【发布时间】:2021-02-13 13:28:50
【问题描述】:
我对使用 Web3 还很陌生。
我正在尝试测试一个购买智能合约(ERC20 硬币)的功能。我已经测试了这段代码以将以太币从一个钱包发送到另一个钱包,它成功了。现在,每当我尝试与智能合约交互(发送签名交易以购买硬币)时,我都会收到此错误:
错误:交易已被 EVM 还原:
这就是它在 etherscan rinkeby 上的显示方式
这是我的代码
var rawTx = {
nonce : nxn,
gasPrice: web3.utils.toHex(web3.utils.toWei('3000', 'gwei')),
gasLimit: '0x5208',
to: '0x40d3b2f06f198d2b789b823cdbecd1db78090d74',
value: web3.utils.toHex(web3.utils.toWei('0.002', "ether")),
data : '0x',
}
var tx = new Tx(rawTx,{chain:'rinkeby', hardfork: 'petersburg'});
tx.sign(privateKey);
var serializedTx = tx.serialize();
await web3.eth.sendSignedTransaction('0x' + serializedTx.toString('hex'))
.on('receipt', console.log);
【问题讨论】:
-
这意味着智能合约为你的交易做了
revert(),通常是通过失败的`require()`行。
标签: javascript node.js blockchain ethereum web3