web3 - Contract deployment has been reverted by the EVM

by DamiToma   Last Updated June 12, 2019 08:28 AM

I want to deploy a contract but my transaction gets reverted. This only happens with Web3, while it works fine with Remix.
I can assure the ABI and Bytecode are correct because I pasted them from Remix, I also debugged the transaction and it doesn't get rejected because of a faulty require statements. Since the issue occours when using Web3, I wonder whether I'm doing anything wrong with the code, but I followed the docs so it should be fine.

web3.eth.personal.unlockAccount("0x57...8c6b", "myPassword", 10000000).then(function() {
    let abi = [...]; // Pasted from Remix
    let bytecode = "0x..."; // Pasted from Remix
    let sender = "0x577...8c6b";

    let newContract = new web3.eth.Contract(abi);
    newContract.options.data = bytecode;

    newContract.deploy({
        args: ""
    }).send({
        from: sender,
        gas: 3000000, 
        gasPrice: '30000000000000'
    }).on('error', (error) => {
        console.log("Error: ", error);
    }).on('transactionHash', (transactionHash) => {
        console.log("TxHash: ", transactionHash);
    }).on('receipt', (receipt) => {
       console.log("Address: ", receipt.contractAddress)
    }).then((newContractInstance) => {
        console.log(newContractInstance);   
    }).catch(function(error) {
        console.log(error);
    });
});

I also tried ignoring the args parameter in deploy but the result is the same:

Error: Error: Transaction has been reverted by the EVM:
{
  "blockHash": "0x0038dfdb8cfd6504d247c9463ad13a43418c15235c625663be4cffee52fe5d61",
  "blockNumber": 387165,
  "contractAddress": "0xf6c8bA6fe06d7F1266bE90A2618faa9E172c0ee6",
  "cumulativeGasUsed": 3000000,
  "from": "0x577ed03fb404fab176c5ca39543def8fd3308c6b",
  "gasUsed": 3000000,
  "logs": [],
  "logsBloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
  "status": false,
  "to": null,
  "transactionHash": "0x4e6c1ebb28770bd702d37f41b442a05b66beba3653a8f1c237e6e18be42b707c",
  "transactionIndex": 0
}

By debugging the transaction I can see that it fails when 2097504 gas is left, whereas Web3's output says the transaction used them all. What I want to understand is whether I'm doing anything wrong with Web3, because the code should be fine considering I can deploy it via Remix.

N.B: I'm using a private chain.



Answers 1


Get rid of this:

newContract.options.data = bytecode;

And change this:

newContract.deploy({args: ""})

To this:

newContract.deploy({data: bytecode, arguments: []})
goodvibration
goodvibration
June 12, 2019 07:59 AM

Related Questions


Updated October 04, 2018 12:28 PM

Updated September 24, 2018 07:28 AM

Updated September 01, 2017 19:28 PM

Updated October 24, 2017 06:28 AM

Updated February 08, 2018 17:28 PM