简体   繁体   English

sendSignedTransaction:Quorum 上的发件人无效错误

[英]sendSignedTransaction: Invalid sender error on Quorum

I am trying to call a method on a Smart Contract on a node app using an account that I create from a private key using web3 on a private quorum blockchain.我正在尝试使用我在私有仲裁区块链上使用 web3 从私钥创建的帐户在节点应用程序上调用智能合约上的方法。 I am using the code below, but I keep getting the error "Error: Returned error: invalid sender" .我正在使用下面的代码,但我不断收到错误"Error: Returned error: invalid sender" Here's the code:这是代码:

const Web3 = require("web3")
const web3 = new Web3(RPC_NODE);

var contract = new web3.eth.Contract(CONTRACT_ABI, CONTRACT_ADRESS);
var myMethod = contract.methods.myMethod(param1, param2);
var encodedABI = myMethod.encodeABI()

const account = web3.eth.accounts.privateKeyToAccount(PRIVATE_KEY);

var tx = {
  from: account.address,
  to: CONTRACT_ADRESS,
  gas: 2000000,
  data: encodedABI
};

console.log("Account Address:", account.address);

account.signTransaction(tx).then(signed => {
  var tran = web3.eth.sendSignedTransaction(signed.rawTransaction);
  console.log("Raw Signed Transaction:", signed.rawTransaction);
});

The error makes sense, since if I have a look at the logs, this is what I get:该错误是有道理的,因为如果我查看日志,这就是我得到的:

Account Address: 0xBd55e32CB2559b06511D03E9B37a1c3bfF0f35Cd账户地址: 0xBd55e32CB2559b06511D03E9B37a1c3bfF0f35Cd

Raw Signed Transaction: ''原始签名交易: ''

And if I decode the raw signed transaction I see:如果我解码原始签名交易,我会看到:

{
  "nonce": 4,
  "gasPrice": null,
  "gasLimit": 2000000,
  "to": "0x73341607498eb0648db01ed55c378c3ea227bf69",
  "value": 0,
  "data": "7d8febab00000000000000000000000000000000000000000000000000000000000000401e4008f33fa1479a536072f9b06e978689c47527593b9a29853e2c708ab75293000000000000000000000000000000000000000000000000000000000000002463343866323863322d353932622d343930622d616663322d62323262366164303035653900000000000000000000000000000000000000000000000000000000",
  "from": "0xbd55e32cb2559b06511d03e9b37a1c3bff0f35cd",
  "r": "d423912021ff81d53c63da08374f9543df1fca3b1d76f085148310d51afb64f1",
  "v": "77",
  "s": "0a212017b256986ca24f151bd920817ae106624b54c04ea702ffd03ab288205c"
}

As you can see, the "from" field from the signed raw transaction does not match the address of the account I created by using the private key.如您所见,签名原始交易中的“from”字段与我使用私钥创建的帐户地址不匹配。 Can somebody explain this behaviour?有人可以解释这种行为吗?

Last time I came across a similar issue, I struggled with the format of the privateKey.上次我遇到类似的问题时,我对 privateKey 的格式感到困惑。

Depending on which version of web3 you use, this formatting might have an impact on the account created via privateKeyToAccount .根据您使用的 web3 版本,此格式可能会对通过privateKeyToAccount创建的帐户产生影响。

I guess you are missing a 0x prefix.我猜您缺少0x前缀。 Make sure your PRIVATE_KEY is prepended with a "0x" and give it another try.确保您的PRIVATE_KEY前面带有"0x" ,然后再试一次。

我通过向tx对象添加正确的chainId来解决它

You can solve this by adding the chainId, like this one var tx = new Tx(rawTx, {'chain':'ropsten'});你可以通过添加chainId来解决这个问题,就像这样一个var tx = new Tx(rawTx, {'chain':'ropsten'});

For your code you can do this =对于您的代码,您可以这样做 =

account.signTransaction(tx, {'chain':'ropsten'}).then(signed => {
  var tran = web3.eth.sendSignedTransaction(signed.rawTransaction);
  console.log("Raw Signed Transaction:", signed.rawTransaction);
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM