1

I want to deploy a contract to my private chain by using web3.js, but my contract deployment has been reverted by the EVM.

This is error message

index.js:1437 Error: Transaction has been reverted by the EVM:
{
  "blockHash": "0x0b0b146c15c1c0df01159c7eadfcf8f77d3d4203f2ae077a14b1bfb2aeab9454",
  "blockNumber": 4199,
  "contractAddress": "0xa215e555de244e5045b0054908dd26a85286b019",
  "cumulativeGasUsed": "0x7a120",
  "from": "0x75FA42D8518e18A60b282dff36E4c86A04b3eefB",
  "gasUsed": "0x7a120",
  "logs": [],
  "logsBloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
  "status": "0x0",
  "to": null,
  "transactionHash": "0xf078bd2a273a87b445a290340e8197f7d5e19f69513355350558d5be613721a5",
  "transactionIndex": 0
}
    at TransactionReceiptValidator.validate (web3-core-method.umd.js:168)
    at web3-core-method.umd.js:59

This is my contract.

pragma solidity ^0.5.0;
pragma experimental ABIEncoderV2;

contract Item {

    address constant temporaryPurchaser = address(0);
    uint256 internal itemId = 0; 

    mapping(uint256 => Item) public ItemInfo;

    struct Item { uint256 id; string itemName; uint256 price; address seller; bool selling; address purchaser;}

    constructor(string memory _itemName, uint256 _price) public {
        ItemInfo[0] = Item(itemId, _itemName, _price, msg.sender, true, temporaryPurchaser);
    }

    function getItem() public view returns (Item memory) {
        return ItemInfo[0];
    } 

}

This is my function. I used sendTransaction function, because I am using private chain.

    const bytecode = "0x60806040526000805534801561001457600080fd5b5060405162000a6e38038062000a6e833981018060405261003891908101906102a0565b6040518060c0016040528060005481526020018381526020018281526020013373ffffffffffffffffffffffffffffffffffffffff168152602001600115158152602001600073ffffffffffffffffffffffffffffffffffffffff16815250600160008081526020019081526020016000206000820151816000015560208201518160010190805190602001906100d0929190610193565b506040820151816002015560608201518160030160006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555060808201518160030160146101000a81548160ff02191690831515021790555060a08201518160040160006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff160217905550905050505061038a565b828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f106101d457805160ff1916838001178555610202565b82800160010185558215610202579182015b828111156102015782518255916020019190600101906101e6565b5b50905061020f9190610213565b5090565b61023591905b80821115610231576000816000905550600101610219565b5090565b90565b600082601f83011261024957600080fd5b815161025c61025782610321565b6102f4565b9150808252602083016020830185838301111561027857600080fd5b610283838284610357565b50505092915050565b6000610298825161034d565b905092915050565b600080604083850312156102b357600080fd5b600083015167ffffffffffffffff8111156102cd57600080fd5b6102d985828601610238565b92505060206102ea8582860161028c565b9150509250929050565b6000604051905081810181811067ffffffffffffffff8211171561031757600080fd5b8060405250919050565b600067ffffffffffffffff82111561033857600080fd5b601f19601f8301169050602081019050919050565b6000819050919050565b60005b8381101561037557808201518184015260208101905061035a565b83811115610384576000848401525b50505050565b6106d4806200039a6000396000f3fe608060405234801561001057600080fd5b50600436106100365760003560e01c806397c112d51461003b578063c412eaba14610070575b600080fd5b610055600480360361005091908101906103cf565b61008e565b6040516100679695949392919061056f565b60405180910390f35b6100786101af565b604051610085919061054d565b60405180910390f35b6001602052806000526040600020600091509050806000015490806001018054600181600116156101000203166002900480601f0160208091040260200160405190810160405280929190818152602001828054600181600116156101000203166002900480156101405780601f1061011557610100808354040283529160200191610140565b820191906000526020600020905b81548152906001019060200180831161012357829003601f168201915b5050505050908060020154908060030160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff16908060030160149054906101000a900460ff16908060040160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff16905086565b6101b7610357565b600160008081526020019081526020016000206040518060c001604052908160008201548152602001600182018054600181600116156101000203166002900480601f0160208091040260200160405190810160405280929190818152602001828054600181600116156101000203166002900480156102785780601f1061024d57610100808354040283529160200191610278565b820191906000526020600020905b81548152906001019060200180831161025b57829003601f168201915b50505050508152602001600282015481526020016003820160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020016003820160149054906101000a900460ff161515151581526020016004820160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681525050905090565b6040518060c00160405280600081526020016060815260200160008152602001600073ffffffffffffffffffffffffffffffffffffffff168152602001600015158152602001600073ffffffffffffffffffffffffffffffffffffffff1681525090565b60006103c7823561064c565b905092915050565b6000602082840312156103e157600080fd5b60006103ef848285016103bb565b91505092915050565b61040181610604565b82525050565b61041081610604565b82525050565b61041f81610616565b82525050565b61042e81610616565b82525050565b600061043f826105d7565b61044981856105e2565b9350610459818560208601610656565b61046281610689565b840191505092915050565b6000610478826105d7565b61048281856105f3565b9350610492818560208601610656565b61049b81610689565b840191505092915050565b600060c0830160008301516104be600086018261052f565b50602083015184820360208601526104d68282610434565b91505060408301516104eb604086018261052f565b5060608301516104fe60608601826103f8565b5060808301516105116080860182610416565b5060a083015161052460a08601826103f8565b508091505092915050565b61053881610642565b82525050565b61054781610642565b82525050565b6000602082019050818103600083015261056781846104a6565b905092915050565b600060c082019050610584600083018961053e565b8181036020830152610596818861046d565b90506105a5604083018761053e565b6105b26060830186610407565b6105bf6080830185610425565b6105cc60a0830184610407565b979650505050505050565b600081519050919050565b600082825260208201905092915050565b600082825260208201905092915050565b600061060f82610622565b9050919050565b60008115159050919050565b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b6000819050919050565b6000819050919050565b60005b83811015610674578082015181840152602081019050610659565b83811115610683576000848401525b50505050565b6000601f19601f830116905091905056fea265627a7a72305820b087a3785cc032eb6bda2363f4bc1cb118ffd45b1e8881c1f0bea31868b7a6f16c6578706572696d656e74616cf50037"
    var itemContract = new this.props.web3.eth.Contract([{"constant":true,"inputs":[{"name":"","type":"uint256"}],"name":"ItemInfo","outputs":[{"name":"id","type":"uint256"},{"name":"itemName","type":"string"},{"name":"price","type":"uint256"},{"name":"seller","type":"address"},{"name":"selling","type":"bool"},{"name":"purchaser","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"getItem","outputs":[{"components":[{"name":"id","type":"uint256"},{"name":"itemName","type":"string"},{"name":"price","type":"uint256"},{"name":"seller","type":"address"},{"name":"selling","type":"bool"},{"name":"purchaser","type":"address"}],"name":"","type":"tuple"}],"payable":false,"stateMutability":"view","type":"function"},{"inputs":[{"name":"_itemName","type":"string"},{"name":"_price","type":"uint256"}],"payable":false,"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":false,"name":"id","type":"uint256"},{"indexed":false,"name":"itemName","type":"string"},{"indexed":false,"name":"price","type":"uint256"},{"indexed":false,"name":"seller","type":"address"},{"indexed":false,"name":"selling","type":"bool"},{"indexed":false,"name":"purchaser","type":"address"}],"name":"PostItem","type":"event"}]);

    const hexdata = itemContract.deploy({
      data: bytecode,
      arguments:['Item1', 1]
    }).encodeABI()

    const nonceHex = await this.props.web3.utils.toHex(this.props.nonce);
    const gasPriceHex = await this.props.web3.utils.toHex(0);
    const gasLimitHex = this.props.web3.utils.toHex(500000);

    var details = await {
      nonce : nonceHex,
      gasPrice : gasPriceHex,
      gasLimit: gasLimitHex,
      from : decryptEtherAccount.address,
      data : "0x"+hexdata,
    };

    const transaction = await new EthereumTx(details, { common: customCommon },);

    await transaction.sign(privatekey)
    console.log(transaction)

    var rawdata = await '0x' + transaction.serialize().toString('hex');
    console.log(rawdata)

    await this.props.web3.eth.sendSignedTransaction(rawdata)
    .on('transactionHash', function(hash){
      console.log(['transferToStaging Trx Hash:' + hash]);
    })
    .on('receipt', function(receipt){
      console.log(['transferToStaging Receipt:', receipt]);
    })
    .on('error', console.error);

Could you give me any advise, please?

  • 1
    You are using solidity 0.5 which by default require new opcodes. Does your private chain have constantinople opcodes enabled? – Ismael Sep 27 '19 at 14:17
  • @Ismael How can I enable it ? I could not find any meaningful info. – gnxvw Sep 27 '19 at 21:42
  • Here is an question that explain how to upgrade an existing blockchain to support constantinople/petersburg opcodes ethereum.stackexchange.com/questions/67794/…. – Ismael Sep 27 '19 at 23:15
  • @Ismael I added "constantinopleBlock": 5, "petersburgBlock": 5 to json file, but I am still getting same error. – gnxvw Sep 28 '19 at 0:20
  • You need to restart your blockchain. Look at geth removedb command documentation. Be careful because that command will delete all previous transactions and blocks – Ismael Sep 28 '19 at 2:36

Browse other questions tagged or ask your own question.