1

I am trying to deploy a contract with web3js. The contract will be deployed but I never get to see the address, which should be returned from the promise. Instead I always get an error returned:

Error: Failed to check for transaction receipt:

Down below my code. For debugging I introduced the event emitters .on:

contract.deploy({
    data: contractBin,
    arguments: [...]
}).send({
    from: ownerAddress,
    gas: 4000000,
    gasPrice: '30000000000000'
}).on('error', (error) => {
   console.log(`Error deploying contract ${error}`);
}).on('transactionHash', (transactionHash) => {
   console.log(`Successfully submitted contract creation. Transaction hash: ${transactionHash}`); 
}).on('receipt', (receipt) => {
   console.log(`Receipt after mining with contract address: ${receipt.contractAddress}`); 
   console.log(`Receipt after mining with events: ${JSON.stringify(receipt.events, null, 2)}`); 
}).on('confirmation', (confirmationNumber, receipt) => { 
    console.log(`Confirmation no. ${confirmationNumber} and receipt for contract deployment: `, receipt); 
}).then((instance) => {
    console.log(instance);
    let address = instance.options.address;
}).catch((error) => {
    console.log(error);
});

Everytime I deploy a contract the transaction gets send:

Successfully submitted contract creation. Transaction hash: 0xb87ee45a3249f2079635d987a51cad31adf5eb52f6afd987d07e84ae0d972d92

but in the next step the error of a failed check for transaction receipt appears. The contract gets even deployed as I can see from my geth node:

INFO [03-09|16:51:12] Submitted contract creation fullhash=0xb87ee45a3249f2079635d987a51cad31adf5eb52f6afd987d07e84ae0d972d92 contract=0xFEb009a6eB95bc46DEb3F35E0004D36b4b6BC6F9

And I can get the contract address from the transaction receipt:

web3.eth.getTransactionReceipt("0xb87ee45a3249f2079635d987a51cad31adf5eb52f6afd987d07e84ae0d972d92").then(console.log); yields:

contractAddress : "0xFEb009a6eB95bc46DEb3F35E0004D36b4b6BC6F9"

What am I doing wrong while deploying a contract?

  • Which client are you using? ie geth, parity, ganache, etc. There's a bug agains web3js related to failing to get the receipt github.com/ethereum/web3.js/issues/1255, you may want to check if it also applies to your situation. – Ismael Mar 11 '18 at 23:10
  • I was using Geth 18.2, but since 18.3 it seems to resolved. – Knowledge Mar 12 '18 at 8:23
1

For anyone interested, this issue is tracked on GitHub. If you want to make web3^1.0 fire the receipt PromiEvent in development mode, you have to add the following options when constructing your web3 instance:

const options = {
  transactionConfirmationBlocks: 1
};
const web3 = new Web(provider, null, options);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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