web3.js icon indicating copy to clipboard operation
web3.js copied to clipboard

myContract.methods.myMethod().send() does not fire receipt and confirmation

Open jona-wilmsmann opened this issue 7 years ago • 42 comments

myContract.methods.myMethod().send() does not fire the receipt and confirmation events for me. The transactionHash event is fired, as well as the error event if there is an error. In fact, the "transaction was not mined within 50 blocks" error is fired as well, when in reality the transaction has already been confirmed.

I am using a WebsocketProvider, however I have the same issue with a HttpProvider as well. I have also tried switching to another node, without success. This is the example code I'm using:

myContract.methods.myMethod(myValue).send({
    from: myAddress,
    gas: 2500000
})
    .on("transactionHash", function () {
        console.log("Hash")
    })
    .on("receipt", function () {
        console.log("Receipt");
    })
    .on("confirmation", function () {
        console.log("Confirmed");
    })
    .on("error", async function () {
        console.log("Error");
    });

I am using version 1.0.0-beta.36

Edit: Using this code to send the transaction, the events are fired correctly:

web3.eth.sendTransaction({
    from: myAddress,
    to: myContractAddress,
    gas: 2500000,
    data: myContract.methods.myMethod(myData).encodeABI()
})

jona-wilmsmann avatar Dec 08 '18 00:12 jona-wilmsmann

I also have this exact issue right now

ngyam avatar Dec 10 '18 13:12 ngyam

Update: upgrading my web3 version to the recent 1.0.0-beta.37 solved it

ngyam avatar Dec 10 '18 15:12 ngyam

Hey this has now been fixed on version 1.0.0-beta.37 if you can upgrade and let us know its solved that would be great!

joshstevens19 avatar Dec 11 '18 23:12 joshstevens19

Hey everyone !

I'm coming back on this issue because ia mfacing the same problem.

I am using web3 on version 1.0.0-beta.37 with Metamask to connect on a private Clique-POA node. When submitting a transaction MM ui confirms that it has been mined but web3 does not seem to catch the receipt.

On the other hand if I test my code on a test net like Ropsten it works just fine.

tchataigner avatar Jan 22 '19 21:01 tchataigner

This is because there are missing confirmations for returning a confirmed transaction. With the new Web3.js version (1.0.0-beta.38) which I will release in the next days is it possible to configure the transaction confirmation workflow and I think this will solve your problem. @tchataigner

nivida avatar Jan 25 '19 10:01 nivida

Is this still an ongoing issue for folks?

We were using 1.0.0-beta.36 and it would take an additional 10-15 seconds for the 'receipt' event to fire after the block was already confirmed. We just attempted to update to 1.0.0-beta.48 and now the 'receipt' event does not fire for multiple minutes, while the 'confirmation' event fires almost immediately inline with the block showing confirmed.

I guess we can move away from use the 'confirmation' event in lieu of using the 'receipt' event instead, but this is pretty kludgy.

Do we know what the source of the issue is? Should I be trying various beta versions between 36-48 to see if one of them is better?

lonlundgren avatar Mar 13 '19 21:03 lonlundgren

Additionally, the receipt that comes out of the 'confirmation' event is not ABI decoded like the receipt that comes out of the 'receipt' event. Does this need its own issue?

lonlundgren avatar Mar 13 '19 22:03 lonlundgren

I have the same issue even in 1.0.0-beta.48, only works in sendTransaction and encodeABI.

taoxinyi avatar Mar 17 '19 16:03 taoxinyi

1.0.0-beta.46 working fine with confirmations, but 1.0.0-beta.47(48, 50) - has an issue

kostysh avatar Mar 22 '19 19:03 kostysh

I had the same issue with 1.0.0-beta.37. Turns out that the contract's ABI was outdated and the web3 was failing silently on event parsing. This explains why the sendTransaction works correctly - it doesn't parsing the events. Updating the ABI fixed this issue. Not sure about newer versions..

leonprou avatar Apr 03 '19 12:04 leonprou

does not fire receipt in beta51,52

coolcode avatar Apr 08 '19 05:04 coolcode

Yeah, I concur. Event still not fired in beta 52 (the transaction is on Ropsten testnet).

luzzif avatar Apr 08 '19 08:04 luzzif

Hi, I am facing the same issue with [email protected]; Only the event once('transactionHash' triggers, .once('receipt' doesn't trigger .then(function(receipt) doesn't trigger either .on('error' triggers and prints an error and transaction object that has status: true Error: Transaction has been reverted by the EVM:

{
  "blockHash": "0x7f1967d80e8006bb867e0cf23d2d61afa7a50234ec30fad8cc476bd06ad2d192",
  "blockNumber": 5370174,
  "contractAddress": null,
  "cumulativeGasUsed": 7400752,
  "from": "0x33c391c8ef59bf79b99d8a73d4a8715cd638dd6a",
  "gasUsed": 40698,
  "logs": [],
  "logsBloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
  "status": true,
  "to": "0xcd842ec9601e9056ddf82f587798d71ca0c75acf",
  "transactionHash": "0x1921c53ea9ae3e7ea2a72f73367291abd883bfb54f572f546df850fffd3098cd",
  "transactionIndex": 78
}

but the transaction is shown successfully completed on Etherscan Ropsten.

farazbhinder avatar Apr 09 '19 08:04 farazbhinder

Closed because of the ongoing clean up of the issue list. Feel free to ask this in our gitter channel or on stackoverflow.

nivida avatar Apr 16 '19 09:04 nivida

Not sure why this would get closed without a clarification or linked issue.

If this is because of the transactionConfirmationBlocks property, you could at least call that out. There is still a regression here, at least when I last tested with beta-36: if you set this property on the web3js object it will not be properly set on new contract objects (new contract objects will always have a 24 block conf period, regardless of property setting). It will however set the property properly on existing contract objects.

lonlundgren avatar Apr 16 '19 18:04 lonlundgren

I'm hitting this same issue, is this behavior documented anywhere?

dmihal avatar May 16 '19 10:05 dmihal

@nivida Maybe this issue has to be reopened because even in the last release confirmations are not firing.

kostysh avatar May 16 '19 11:05 kostysh

Two things you have to care for a working solution:

  • configure the transaction confirmation workflow
  • Just use the Promise, callback or the EventEmitter of the returned PromiEvent and don’t combine them.

nivida avatar May 16 '19 11:05 nivida

@nivida wait... does it mean I remove .catch from the following code it should become working?

myContract.methods
        .someMethod()
        .send({
            from: ...
        })
        .on('error', console.log)
        .on('transactionHash', console.log)
        .on('confirmation', console.log)
        .catch(console.log);

kostysh avatar May 16 '19 11:05 kostysh

@nivida Please clarify how the transaction confirmation workflow should be configured correctly.

  • I am using web3 v.1.0.0-beta.55
  • Initialized with:
const myWeb3 = new Web3(window.web3.currentProvider, null, {
    transactionConfirmationBlocks: 10
});
  • I am calling a method this way (using PromiEvent only):
myContract.methods
    .someMethod()
    .send({  from: 0x... })
    .on('error', console.log)
    .on('transactionHash', console.log)
    .on('confirmation', console.log);
  • I am getting a transactionHash only, but confirmations never comes UPD: receipt does not comes too

What I am doing wrong?

kostysh avatar May 17 '19 11:05 kostysh