web3 / web3.js

Collection of comprehensive TypeScript libraries for Interaction with the Ethereum JSON RPC API and utility functions.
https://web3js.org/
Other
19.31k stars 4.95k forks source link

No receipt after contract deploy #2601

Closed ghost closed 5 years ago

ghost commented 5 years ago

Description

After deploying a new contract I never receive a receipt object.

const deploy = { abi: [...], bytecode: '0x...' };

const web3 = new Web3 (window ['ethereum']);
const contract = new web3.eth.Contract (deploy.abi);

window ['ethereum'].enable()
    .then (accounts => {

        contract.deploy({
            data: deploy.bytecode,
            arguments: [...]
        })
        .send ({
            from: accounts [0]
        })
        .on ('error',           console.error)
        .on ('transactionHash', console.log)       /* this is working */
        .on ('receipt',         console.log);      /* this never gets executed */

    })
    .catch (console.error);

Expected behavior

Receiving a contract object containing the address of the new contract in .on ('receipt', ....

Actual behavior

Nothing happens (also no error).

On my node I can look up the contract address manually. The contract gets created.

Versions

ghost commented 5 years ago

In addition: With web3.js: 1.0.0-beta.46 it's working fine and I get a receipt as well. All other versions after this one are not working.

nivida commented 5 years ago

You have to configure your module correctly for the development environment. I've updated and improved the transaction confirmation workflow in this release.

ghost commented 5 years ago

Thank's for the quick reply.

You mean this options object?

const options = {
    defaultAccount: '0x0',
    defaultBlock: 'latest',
    defaultGas: 1,
    defaultGasPrice: 0,
    transactionBlockTimeout: 50,
    transactionConfirmationBlocks: 24,
    transactionPollingTimeout: 480,
    transactionSigner: new CustomTransactionSigner()
}

const web3 = new Web3(window ['ethereum'], options);

Are this values not calculated and set by metamask if you do a transaction? This is what they do for you, right? If not, can I just use this default values then?

princesinha19 commented 5 years ago

Yes @nivida. This issue is same as the issue #2577. Please check the .on('receipt') event. Why it's not generating the receipt. I don't know, but it might be issue of Geth as it is working fine with Ganache. Also, after setting options it gets executed but doesn't produces transaction receipt. We only get methods, options etc in receipt.

@hbrs Check the issue #2577 and set the options correctly.

ghost commented 5 years ago

I changed my code to this below, but still don't get a receipt.

const options = {
    transactionConfirmationBlocks: 1,
    transactionBlockTimeout: 5,
    transactionPollingTimeout: 480
};

const web3 = new Web3 (window ['ethereum'], null, options);
lucashenning commented 5 years ago

+1 After updating to 1.0.0-beta.51 (latest), the .on('receipt', (txReceipt : TransactionReceipt) event is not triggered anymore. I tested this on Ganache, Quorum, and Ropsten. The confirmation and transactionHash events are triggered correctly.

dileepfrog commented 5 years ago

Most likely related, awaiting a call to web3.eth.sendSignedTransaction the Promise never resolves in 1.0.0-beta.51. It did resolve correctly on the receipt in 1.0.0-beta.50

szerintedmi commented 5 years ago

Same here. Here is a failing test to demonstrate the issue with sendTransaction on ganache

szerintedmi commented 5 years ago

not sure if it's related but it seems not to resolve nor reject on VM error either (running on ganache-cli version 6.4.1). This test times out on await receipt which is executing a contract tx which reverts.

ghost commented 5 years ago

update: I tried it today with beta.52 (latest) again and still don't get a receipt.

nivida commented 5 years ago

@hbrs Thanks for answering here!:)

Did you configure the transaction confirmation workflow as documented in our documentation?

What kind of node are you using and which provider?

JonahGroendal commented 5 years ago

I tried with beta 55 and web3.eth.sendTransaction() is still not resolving and no receipt. I'm using Infura websocketprovider

PaulRBerg commented 5 years ago

@nivida @JonahGroendal I can confirm that in beta 55 this issue is fixed when setting the options defined above, but I would kindly want to ask for additional information on the docs:

PaulRBerg commented 5 years ago

Also, another issue I have is with the synchrony between the receipt PromiEvent and the value returned by web3.eth.getTransactionReceipt. Even if the latter returns a non-null value for a given transaction hash, it can take up to 10 seconds and more for the former PromiEvent to be fired.

Is this related or should I open a new issue?

JonahGroendal commented 5 years ago

@PaulRBerg It's working for me now after initializing like this: ''' new Web3( new Web3.providers.WebsocketProvider("wss://kovan.infura.io/ws/v3"), undefined, { transactionConfirmationBlocks: 1 } )'''

guix77 commented 5 years ago

Default value of transactionConfirmationBlocks is 24 by default: https://github.com/ethereum/web3.js/blob/5683436b1dae70fce72a2ff952736e687998fd7f/packages/web3-core/src/AbstractWeb3Module.js#L53

You might want to just wait or lower it. For those on local dev chains you want transactionConfirmationBlocks = 1 because blocks are not created after the one including the TX, so the receipt is never fired.