错误:通过ropsten infura testnet发送交易时,EVM已恢复交易

问题描述

我有一个智能合约,该合约通过remix IDE部署在ropsten测试网上:

// SPDX-License-Identifier: MIT
pragma solidity >=0.4.21 <0.7.0;

contract PrinterMarketplace {
    uint256 public requestCount = 0;
    uint256 public offerCount = 0;
    uint256 public orderCount = 0;

    mapping(uint256 => Request) public requests;
    struct Request {
        uint256 id;
        address payable client;
        string filehash;
    }
    mapping(uint256 => Offer) public offers;
    struct Offer {
        uint256 id;
        uint256 price;
        string filehash;
        address payable client;
        address payable provider;
        bool purchased;
    }
    mapping(uint256 => Order) public orders;
    struct Order {
        uint256 id;
        uint256 price;
        address payable client;
        address payable provider;
        bool purchased;
        string filehash;

    }

    function setRequest(string memory _filehash) public {
        requestCount++;
        requests[requestCount] = Request(requestCount,msg.sender,_filehash);
    }

    function setoffer(uint256 _offerPrice,string memory _filehash,address payable _client,address payable _provider) public {
        offerCount++;
        offers[offerCount] = Offer(
            offerCount,_offerPrice,_filehash,_client,_provider,false
        );
    }

    /*     function get() public view returns (string memory) {
        return filehash;
    } */

    function purchaSEOffer(
        uint256 _id,uint256 _orderPrice,address payable _provider,string memory _filehash
    ) public payable {
        orderCount++;
        //fetch the offer
        // Order memory _order = Order(_id,_orderPrice,_owner,true);
        orders[orderCount] = Order(_id,true,_filehash);
        //pay the seller by sendding them ether
        address(uint160(_provider)).transfer(msg.value);
    }
}

运行我的JavaScript代码时,出现以下错误

Error in setoffer:  { Error: Transaction has been reverted by the EVM:
{
  "blockHash": "0x71561626c29b157c9e01b6cb143868055a570ce99a4fa0d4a1f4a827ec401ee4","blockNumber": 8562752,"contractAddress": null,"cumulativeGasUsed": 1602671,"from": "0x2692dea243c0341a48ba9017e84d5bc4ab1d2e0d","gasUsed": 23267,"logs": [],"logsBloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000","status": false,"to": "0x8285ed4dbfba6faa5bd9da628579239168dd2e06","transactionHash": "0x4fe04293fbce89472bb8508598fc1598794f1ab20788c234eac1d32fbd9cdcf4","transactionIndex": 4
}
    at Object.TransactionError (/home/emre/CARdamOM/Printerapp/node_modules/web3-core-helpers/src/errors.js:93:21)
    at Object.TransactionRevertedWithoutreasonerror (/home/emre/CARdamOM/Printerapp/node_modules/web3-core-helpers/src/errors.js:105:21)
    at /home/emre/CARdamOM/Printerapp/node_modules/web3-core-method/src/index.js:474:48
    at process._tickCallback (internal/process/next_tick.js:68:7)
  receipt:
   { blockHash:
      '0x71561626c29b157c9e01b6cb143868055a570ce99a4fa0d4a1f4a827ec401ee4',blockNumber: 8562752,contractAddress: null,cumulativeGasUsed: 1602671,from: '0x2692dea243c0341a48ba9017e84d5bc4ab1d2e0d',gasUsed: 23267,logs: [],logsBloom:
      '0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000',status: false,to: '0x8285ed4dbfba6faa5bd9da628579239168dd2e06',transactionHash:
      '0x4fe04293fbce89472bb8508598fc1598794f1ab20788c234eac1d32fbd9cdcf4',transactionIndex: 4 } }

我在etherscan上看到了该事务,但是它被标记为失败。

这是我的js代码

var Tx = require('ethereumjs-tx').Transaction;
var privateKey = new Buffer('xxxxxxxxxxxxxxxxxxxxxx','hex')

async function writeOfferToContract(_offerprice,_contract,_account) {
    var data = await _contract.methods.setoffer(_offerprice,_account).encodeABI();
    var nonce = await web3.eth.getTransactionCount(_account);
    nonce = '0x' + nonce.toString(16)

    var rawTx = {
        nonce: nonce,//web3.eth.getTransactionCount(_account) + 1,gasPrice: web3.utils.toHex('10000000000'),gasLimit: web3.utils.toHex('3000000'),from: '0x2692DEA243c0341A48ba9017e84d5BC4Ab1D2E0d',value: web3.utils.toHex(_offerprice),data: data,chainId: 3 //ropsten = 3
    }

    var tx = new Tx(rawTx,{ 'chain': 'ropsten' });
    tx.sign(privateKey);

    var serializedTx = tx.serialize();

    if (_offerprice != 'undefined' && _contract != 'undefined') {
        try {

            const receipt = await web3.eth.sendSignedTransaction('0x' + serializedTx.toString('hex'),function (err,hash) {
                if (!err)
                    console.log('ERROR:',hash); 
            });
            console.log(receipt)
            console.log('OFFER SUCCESSFULLY WRITTEN IN CONTRACT')
        } catch (error) {
            console.log('Error in setoffer: ',error)
        }
    }
    //console.log('offerPrice: ',_contract.methods.getofferPrice()) test
}
module.exports = {
    writeOfferToContract
};

对我来说,一切看起来都不错,在这种情况下,我真的不知道该从哪里继续。 有人可以帮我找到问题。我可能不知道,该错误可能与contractAddress:null有关。

我已经附加了etherscan交易

enter image description here

解决方法

我已从以下地址删除:“ 0x2692DEA243c0341A48ba9017e84d5BC4Ab1D2E0d”和chainId:3。 然后将值设置为“ 0”。

现在可以正常工作了。

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...