我正在运行一个Hyperledger私人连锁店,并从一个快递服务器进行sendSignedTransaction调用。
try {
let tx = {
from: fromAccount,
to: this.contract.options.address,
gas: 2000000,
gasPrice: "0",
value: 0,
data: await this.contract.methods
.method().encodeABI()
};
console.log(tx);
console.log("signing transaction");
let signedTx = await this.web3.eth.accounts.signTransaction(tx, privateKey);
console.log("transaction signed");
let result = await this.web3.eth.sendSignedTransaction(signedTx.rawTransaction)
console.log(result);
}
catch (e) {
console.log(e);
}事务正在恢复并被捕获,但我不知道如何获得恢复原因。我尝试过设置contract.handleRevert和其他搜索引擎解决方案,但所有其他解决方案都假设您从前端使用sendTransaction、call或send。根据web3.js文档,handleRevert不适用于sendSignedTransaction (https://web3js.readthedocs.io/en/v1.2.11/web3-eth.html#handlerevert),错误作为一个长字符串返回:
Error: Transaction has been reverted by the EVM:
{
"blockHash": "0xcb93d98a8d6f7c329dfd0cdb7d2fc421147ae077765e63263c794eb43aaa6263",
"blockNumber": 560179,
"contractAddress": null,
"cumulativeGasUsed": 35348,
"from": fromAddress,
"gasUsed": 35348,
"logs": [],
"logsBloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
"status": false,
"to": contractAddress,
"transactionHash": "0xfbd9b755aa71d823640c0f719d358ef9c7d81362a901ec2901fba5f188a4a310",
"transactionIndex": 0,
"revertReason": "0x08c379a0000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000204552433737373a2073656e6420746f20746865207a65726f2061646472657373"
}
at Object.TransactionError (/home/blockchain-dev/Documents/blockchain-app/server/node_modules/web3-core-helpers/src/errors.js:96:21)
at Object.TransactionRevertedWithoutReasonError (/home/blockchain-dev/Documents/blockchain-app/server/node_modules/web3-core-helpers/src/errors.js:108:21)
at /home/blockchain-dev/Documents/blockchain-app/server/node_modules/web3-core-method/src/index.js:482:48
at processTicksAndRejections (internal/process/task_queues.js:93:5) {
receipt: {
blockHash: '0xcb93d98a8d6f7c329dfd0cdb7d2fc421147ae077765e63263c794eb43aaa6263',
blockNumber: 560179,
contractAddress: null,
cumulativeGasUsed: 35348,
from: fromAccount,
gasUsed: 35348,
logs: [],
logsBloom: '0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000',
status: false,
to: contractAddress,
transactionHash: '0xfbd9b755aa71d823640c0f719d358ef9c7d81362a901ec2901fba5f188a4a310',
transactionIndex: 0,
revertReason: '0x08c379a0000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000204552433737373a2073656e6420746f20746865207a65726f2061646472657373'
}
}我还尝试在revertReason十六进制代码上运行十六进制以实现ascii转换器,该值不可读。
我希望能够得到sendSignedTransaction调用的恢复原因。
发布于 2021-05-19 22:08:05
您可以使用revertReason来解码web3.utils.hexToAscii()。
const reason = web3.utils.hexToAscii('0x08c379a0000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000204552433737373a2073656e6420746f20746865207a65726f2061646472657373');返回
Ãy ERC777: send to the zero address注意:前两个字符看起来像UTF,但是hexToUtf8()无法解码字符串(其余的字符串实际上是ASCII,而不是UTF)。
发布于 2022-01-17 21:39:20
这是一项工作,因为revertReason似乎还没有使用sendSignedTransaction (至少从我使用炼金术的节点服务的经验来看)。
try {
let tx = {
from: fromAccount,
to: this.contract.options.address,
gas: 2000000,
gasPrice: "0",
value: 0,
data: await this.contract.methods
.method().encodeABI()
};
console.log(tx);
console.log("signing transaction");
let signedTx = await this.web3.eth.accounts.signTransaction(tx, privateKey);
console.log("transaction signed");
let result = await this.web3.eth.sendSignedTransaction(signedTx.rawTransaction)
console.log(result);
}
catch (e) {
this.contract.methods.method()
.call({'from': fromAccount}).then(() => {
throw Error ('reverted tx')})
.catch(revertReason => console.log({revertReason})
}https://stackoverflow.com/questions/67609884
复制相似问题