Metamask-extension: Transaction receipt callback is not called on Metamask 4.12

Created on 4 Oct 2018  路  30Comments  路  Source: MetaMask/metamask-extension

With MetaMask 4.12, the receipt is not returned in both callback and promise versions.

contract.methods.method().send({ from: address }).then(receipt => console.log(receipt))

contract.methods.method().send({ from: address }).on('receipt', function(receipt) { console.log(receipt); })

Both these examples are not working in Metamask 4.12 but working fine in 4.9

P1-asap T00-bug

Most helpful comment

The new build is working fine for me but the MaxListenersExceededWarning: "Possible EventEmitter memory leak detected. 11 data listeners added. Use emitter.setMaxListeners() to increase limit" is still there. It wasn't an issue on 4.11. Thank you.

All 30 comments

Important to note that the _truffle_ community and the _web3.js_ community has been reporting this kind of errors recently.

Could you share what JS library you are using to get these results?

Please note web3 1.0 is in beta, and not yet supported by MetaMask.
Like it, Drizzle (from the Truffle team) depends on websockets/subscriptions, which MetaMask does not yet support.

If you want to use these event-based APIs, you will need to connect to your own websocket-hosting ethereum server, as it is not provided by MetaMask at this time. You can still read from a different server, and propose transactions to the MetaMask API if you want to work around this limitation for now.

Leaving open in case this isn't a websocket issue, but it really looks like one to me. I have not had any issues getting tx receipts with the latest MetaMask builds.

@danfinlay can be a websocket issue. I've read something related too, but those who got problems with metamask 4.12, after downgraded to 4.11.1 and had no issues. Sorry, can't be more specific than that, since I'm not using 4.12 currently and I have no issues.

@danfinlay I am using web3 1.0beta36 and this is the error I'm getting.

MetaMask - RPC Error: Internal JSON-RPC error. {code: -32603, message: "Internal JSON-RPC error."}
ERROR Error: Uncaught (in promise): Error: Failed to subscribe to new newBlockHeaders to confirm the transaction receipts.

But everything has been working flawlessy for the last month and it's still working fine on metamask 4.9 and 4.11 so it should be something you can address. This will break the workflow for many dapps.

This could be a very serious issue, but I'm unable to reproduce. A sample call that any MetaMask user can enter in their console while connected to the main network:

web3.eth.getTransactionReceipt('0xec7bf72ecac93325adad8bfb08f22108a6f4fd270a8275a207fb0c18ec082dbd', console.log)

Returns the correct value for me.

Can you provide reproduction steps or a reproduction app? Until we can reproduce the error, we cannot be sure that a given action will fix the issue.

Alright, we鈥檝e published a rollback to 4.11.1, called 4.13.0. We would still really appreciate reproduction steps.

@danfinlay Thank you so much for your help. Here is a code snippet (Angular 6) to reproduce the issue. I'm using the lastest web3 1.0.0beta.36 but I had the same issue on beta33. Be sure to connect to Ropsten testnet.

this.web3 = new Web3(window.web3.currentProvider);
this.web3.eth.getAccounts().then(accounts => {

   let abi = [{"constant":true,"inputs":[],"name":"rate","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"weiRaised","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"closingTime","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"owner","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"openingTime","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"newOwner","type":"address"}],"name":"transferOwnership","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"token","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"inputs":[{"name":"_rate","type":"uint256"},{"name":"_openingTime","type":"uint256"},{"name":"_closingTime","type":"uint256"}],"payable":false,"stateMutability":"nonpayable","type":"constructor"},{"payable":true,"stateMutability":"payable","type":"fallback"},{"anonymous":false,"inputs":[{"indexed":true,"name":"purchaser","type":"address"},{"indexed":true,"name":"beneficiary","type":"address"},{"indexed":false,"name":"value","type":"uint256"},{"indexed":false,"name":"amount","type":"uint256"}],"name":"TokenPurchase","type":"event"},{"constant":false,"inputs":[{"name":"_beneficiary","type":"address"}],"name":"buyTokens","outputs":[],"payable":true,"stateMutability":"payable","type":"function"},{"constant":false,"inputs":[{"name":"_token","type":"address"}],"name":"setToken","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"hasClosed","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"remainingSupply","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_amount","type":"uint256"}],"name":"burnTokens","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[],"name":"withdrawFunds","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"}];

   let contract = new this.web3.eth.Contract(abi,'0x96c60DDa637487820AF1858b94b5c732F0beFfD3');
   contract.methods.buyTokens(accounts[0]).send({ from: accounts[0], value: this.web3.utils.toWei('0.00005', 'ether')})
   .then(receipt => console.log(receipt));

});

This will not print the receipt on console with MetaMask 4.12 while I can confirm it is working fine again on 4.13. I hope this can help you to track down the issue.

We do not currently support web3 1.0 beta since it depends on the subscriptions API. If you want promises and a similar interface, I recommend either ethjs, truffle-contract, or maybe ethers.js.

I cannot promise that our next release will support web3 1.0 beta, it's surprising that it worked even momentarily.

Closing as a duplicate of #3642.

I confirmed this is because we don't support the subscriptions API, and apparently we did have a rudimentary version of subscription support previously. We need to port that subprovider to json-rpc-engine.

Are you going to port that in the next release or at a later time? So I know if I should migrate to another library or stick with web3 1.0.
I'm seeing many new dapps using web3 1.0 and I believe this change would break their workflow.
Thank you for your patience.

We're hoping to not break this, since so many people are apparently building on our unofficial support, but we also have several critical issues "blocked" by this, so in some ways we're inclined to protect the API schedule we declared over the unofficial one we never supported.

That said, I may have a fix:

Could someone who was affected by this issue pull down one of these builds, and confirm if this fixes it?

metamask-opera-4.14.0.zip
metamask-chrome-4.14.0.zip
metamask-firefox-4.14.0.zip

You can also build from source and comment on that particular approach here.

Metamask 4.14 is not working for me in any browser. It doesn't even recognize my account and the error is:
TypeError: t.setEngine is not a function.

Thanks for trying, sorry there was an issue. Looking into what could cause that now.

We have been working implementing the web3 1.0 subscription method once again. Let us know if this build is breaking your dapps.
https://github.com/MetaMask/metamask-extension/pull/5458#issuecomment-427979200

Thank you for your efforts to fix this. I am really sorry to report that the new build isn't working. For every transaction, Metamask says ALERT: Transaction Error. Exception thrown in contract code.. I have tried with multiple contract functions and nothing. Downgraded to 4.11 and everything is working properly again. Even the old 4.12 didn't have this issue.

Another thing that gets printed in console is MaxListenersExceededWarning: "Possible EventEmitter memory leak detected. 11 data listeners added. Use emitter.setMaxListeners() to increase limit".

I do get that error message too, but seemed to work just fine for me to send. Will track down where the error message is coming from.
https://ropsten.etherscan.io/tx/0xe373bd2b29ce93f65488dcfc81db1b8e07cfaf52c741689707eeccaa5c0f0aa3

@AleG94 thanks so much for your help reproducing this issue. Would you mind sending us your state logs after getting that error, so we could inspect how the transaction was composed? You can send it privately to [email protected]

https://metamask.zendesk.com/hc/en-us/articles/360015289832-How-to-Download-State-Logs-New-UI-

I just sent the state logs. I can confirm that, despite the error, the transaction is being mined succesfully so it's probably just a display error. The receipt callback is also working fine now. The MaxListenersExceededWarning for data listeners is still there though.

@danfinlay when you say you have no short term plans to support Web3 1.0 is this specifically support for the promi events and event watchers ? Will Web3 1.0 still work using callbacks for tx/call results or do you suggest a rollback to 0.20.x ?

For me, it is coming from here,
https://github.com/MetaMask/metamask-extension/blob/develop/app/scripts/controllers/transactions/tx-gas-utils.js#L30-L37

The catch results in TypeError: l.slice is not a function

Thanks for your patience. We have a new build that we hope has fixed this issue here: https://github.com/MetaMask/metamask-extension/pull/5475#issuecomment-428371017

The new build is working fine for me but the MaxListenersExceededWarning: "Possible EventEmitter memory leak detected. 11 data listeners added. Use emitter.setMaxListeners() to increase limit" is still there. It wasn't an issue on 4.11. Thank you.

That's great to hear!

The warning should be very easy to fix: Is that warning in the page console, or which console do you see that in?

The warning is shown in the browser console after I unlock my Metamask account. It's been present since the initial 4.12 (the one with the receipt bug) and it's still here in the lastest build. It's not present in 4.11 and 4.9. Everything seems to work as expected though.

Hi, wanted to confirm I'm having the same issue as above with async/await - transaction success is confirmed in 4.13, but not 4.14. Similar to the above, the transaction goes through in MetaMask and is mined, but I never get a confirmation. I'm actually not getting any kind of error, just an extended wait. Also on web3 1.0.0beta.36.

const result = await token.methods.transferFrom(user, owner, amount, 0).send({ from: user, gas: gas, chainId })

Do I need to refactor to callbacks to move forward?

@allegramarie try v5.0.2 and let us know if you still have trouble

https://github.com/MetaMask/metamask-extension/releases

Thanks! I'm on v5.0.2, no change.

@allegramarie Could I have the whole snippet? My steps to reproduce came up with no issues returning the tx details. This is my simpler repro snippet that can be ran in your project's console, the contract is on Ropsten.

web3.eth.getAccounts().then(async accounts => {
  var abi = [{"constant":false,"inputs":[{"name":"x","type":"uint256"}],"name":"set","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"get","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"}]
  var contract = new web3.eth.Contract(abi, '0xC87f3D029dD512B8042F7c2eeb0ffFD4db4EdFC4')
  try {
    const result = await contract.methods.set(2).send({ from: accounts[0]})
    console.log(result)
  } catch (error) {
    console.log(error)
  }
})

Here's the whole snippet. I ran your repro on Ropsten and didn't have any issues getting a response in the console, but I'm on a private network with this contract.

const buyAsset = async (amount, assetToken) => {
    try {
        const chainId = await web3.eth.net.getId();
        let user = await getUserAccount();
        user = user.toString();
        const token = Token(assetToken);
        let owner = await token.methods.owner().call();
        owner = owner.toString();
        try {
            const result = await token.methods.transferFrom(owner, user, amount, 5).send({ from: user, gas: gas, chainId });
            return result;
        }
        catch (err) {
            console.log('error!')
        }
    }
    catch (err) {
        console.log('error buying an asset', err)
    }
}

Hi, All
This issue i'm now see in Metamask browser on Android. And the worst of all i do not see how to debug it on Android? I' calling send(...) transaction generated and contract method called, but no receipt, no any callback. The same code is working through Chrome on PC. How can i avoid this problem on Android device and Metamask browser?

Was this page helpful?
0 / 5 - 0 ratings