sendSignedTransaction:Quorum 上的无效发件人错误
sendSignedTransaction: Invalid sender error on Quorum
我正在尝试使用我在私有仲裁区块链上使用 web3 从私钥创建的帐户调用节点应用程序上智能合约的方法。我正在使用下面的代码,但我不断收到错误 "Error: Returned error: invalid sender"。这是代码:
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);
});
这个错误是有道理的,因为如果我查看日志,我会得到以下结果:
Account Address: 0xBd55e32CB2559b06511D03E9B37a1c3bfF0f35Cd
Raw Signed Transaction: '0xf901050480831e84809473341607498eb0648db01ed55c378c3ea227bf6980b8a47d8febab00000000000000000000000000000000000000000000000000000000000000401e4008f33fa1479a536072f9b06e978689c47527593b9a29853e2c708ab75293000000000000000000000000000000000000000000000000000000000000002463663038646139362d363665332d343034312d393630652d3030393838636433383865320000000000000000000000000000000000000000000000000000000078a0700c0b30a6a58016a9621033fe71974eb0cc8721841353b7aa5e42f96d122a7aa023fa6bf121c3c83de1c03674edf90c5bf9ad55165ac10a43965318cdde65e438'
如果我解码原始签名交易,我会看到:
{
"nonce": 4,
"gasPrice": null,
"gasLimit": 2000000,
"to": "0x73341607498eb0648db01ed55c378c3ea227bf69",
"value": 0,
"data": "7d8febab00000000000000000000000000000000000000000000000000000000000000401e4008f33fa1479a536072f9b06e978689c47527593b9a29853e2c708ab75293000000000000000000000000000000000000000000000000000000000000002463343866323863322d353932622d343930622d616663322d62323262366164303035653900000000000000000000000000000000000000000000000000000000",
"from": "0xbd55e32cb2559b06511d03e9b37a1c3bff0f35cd",
"r": "d423912021ff81d53c63da08374f9543df1fca3b1d76f085148310d51afb64f1",
"v": "77",
"s": "0a212017b256986ca24f151bd920817ae106624b54c04ea702ffd03ab288205c"
}
如您所见,已签名原始交易的“发件人”字段与我使用私钥创建的帐户地址不匹配。有人可以解释这种行为吗?
上次遇到类似问题时,我一直在纠结私钥的格式。
根据您使用的 web3 版本,此格式可能会对通过 privateKeyToAccount
创建的帐户产生影响。
我猜您缺少 0x
前缀。确保你的 PRIVATE_KEY
前面有一个 "0x"
并再试一次。
我通过将正确的 chainId
添加到 tx 对象
来解决它
你可以通过添加chainId来解决这个问题,比如这个var tx = new Tx(rawTx, {'chain':'ropsten'});
对于您的代码,您可以这样做 =
account.signTransaction(tx, {'chain':'ropsten'}).then(signed => {
var tran = web3.eth.sendSignedTransaction(signed.rawTransaction);
console.log("Raw Signed Transaction:", signed.rawTransaction);
});
我正在尝试使用我在私有仲裁区块链上使用 web3 从私钥创建的帐户调用节点应用程序上智能合约的方法。我正在使用下面的代码,但我不断收到错误 "Error: Returned error: invalid sender"。这是代码:
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);
});
这个错误是有道理的,因为如果我查看日志,我会得到以下结果:
Account Address: 0xBd55e32CB2559b06511D03E9B37a1c3bfF0f35Cd
Raw Signed Transaction: '0xf901050480831e84809473341607498eb0648db01ed55c378c3ea227bf6980b8a47d8febab00000000000000000000000000000000000000000000000000000000000000401e4008f33fa1479a536072f9b06e978689c47527593b9a29853e2c708ab75293000000000000000000000000000000000000000000000000000000000000002463663038646139362d363665332d343034312d393630652d3030393838636433383865320000000000000000000000000000000000000000000000000000000078a0700c0b30a6a58016a9621033fe71974eb0cc8721841353b7aa5e42f96d122a7aa023fa6bf121c3c83de1c03674edf90c5bf9ad55165ac10a43965318cdde65e438'
如果我解码原始签名交易,我会看到:
{
"nonce": 4,
"gasPrice": null,
"gasLimit": 2000000,
"to": "0x73341607498eb0648db01ed55c378c3ea227bf69",
"value": 0,
"data": "7d8febab00000000000000000000000000000000000000000000000000000000000000401e4008f33fa1479a536072f9b06e978689c47527593b9a29853e2c708ab75293000000000000000000000000000000000000000000000000000000000000002463343866323863322d353932622d343930622d616663322d62323262366164303035653900000000000000000000000000000000000000000000000000000000",
"from": "0xbd55e32cb2559b06511d03e9b37a1c3bff0f35cd",
"r": "d423912021ff81d53c63da08374f9543df1fca3b1d76f085148310d51afb64f1",
"v": "77",
"s": "0a212017b256986ca24f151bd920817ae106624b54c04ea702ffd03ab288205c"
}
如您所见,已签名原始交易的“发件人”字段与我使用私钥创建的帐户地址不匹配。有人可以解释这种行为吗?
上次遇到类似问题时,我一直在纠结私钥的格式。
根据您使用的 web3 版本,此格式可能会对通过 privateKeyToAccount
创建的帐户产生影响。
我猜您缺少 0x
前缀。确保你的 PRIVATE_KEY
前面有一个 "0x"
并再试一次。
我通过将正确的 chainId
添加到 tx 对象
你可以通过添加chainId来解决这个问题,比如这个var tx = new Tx(rawTx, {'chain':'ropsten'});
对于您的代码,您可以这样做 =
account.signTransaction(tx, {'chain':'ropsten'}).then(signed => {
var tran = web3.eth.sendSignedTransaction(signed.rawTransaction);
console.log("Raw Signed Transaction:", signed.rawTransaction);
});