【问题标题】:Web3 Error: Transaction has been reverted by the EVM:Web3 错误:EVM 已恢复事务:
【发布时间】: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


【解决方案1】:

这意味着智能合约为您的交易执行了revert(),通常是通过失败 require() 行。其他原因包括尝试对不接受付款的智能合约进行应付交易。

如果没有智能合约源代码,就无法判断是什么导致了还原。

【讨论】:

    猜你喜欢
    • 2020-12-14
    • 1970-01-01
    • 2022-01-06
    • 2022-08-15
    • 1970-01-01
    • 2021-08-19
    • 2017-11-21
    • 2011-04-23
    • 2022-08-31
    相关资源
    最近更新 更多