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;

        args: ""
        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) => {
    }).catch(function(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.

1 Answer 1


Get rid of this:

newContract.options.data = bytecode;

And change this:

newContract.deploy({args: ""})

To this:

newContract.deploy({data: bytecode, arguments: []})
  • Now it works but it takes ages for Web3 to print the new address, even if the transaction has already been confirmed. Any clues?
    – DamiToma
    Commented Jun 12, 2019 at 8:30
  • @DamiToma: So how do you know that the transaction has been confirmed? (the transactionHash event doesn't indicate this fact). Commented Jun 12, 2019 at 8:33
  • Using web3.eth.getTransactionReceipt(hash) I can see its status is true, which means it was successful. @goodvibration
    – DamiToma
    Commented Jun 12, 2019 at 9:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.