簡體   English   中英

錯誤:通過 ropsten infura 測試網發送交易時,EVM 已恢復交易

[英]Error: Transaction has been reverted by the EVM while sending transaction via ropsten infura testnet

我有一個智能合約,它是通過 ropsten 測試網上的 remix IDE 部署的:

// 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 _client,
        address payable _provider,
        string memory _fileHash
    ) public payable {
        orderCount++;
        //fetch the offer
        // Order memory _order = Order(_id, _orderPrice, _owner, true);
        orders[orderCount] = Order(_id, _orderPrice, _client, _provider, 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, _fileHash, _contract, _client, _account) {
    var data = await _contract.methods.setOffer(_offerprice, _fileHash, _client, _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'),
        to: '0x8285ed4dbfba6faa5bd9da628579239168dd2e06',
        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 交易在此處輸入圖片說明

“0x2692DEA243c0341A48ba9017e84d5BC4Ab1D2E0d”和chainId:3。然后我設定值“0”我已經從刪除。

它的正常工作了。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM