Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Transaction receipt callback is not called on Metamask 4.12 #5425

Closed
AleG94 opened this issue Oct 4, 2018 · 30 comments
Closed

Transaction receipt callback is not called on Metamask 4.12 #5425

AleG94 opened this issue Oct 4, 2018 · 30 comments
Assignees
Labels

Comments

@AleG94
Copy link

AleG94 commented Oct 4, 2018

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

@obernardovieira
Copy link

Important to note that the truffle community and the web3.js community has been reporting this kind of errors recently.

@danfinlay
Copy link
Contributor

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.

@obernardovieira
Copy link

@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.

@AleG94
Copy link
Author

AleG94 commented Oct 4, 2018

@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.

@danfinlay
Copy link
Contributor

danfinlay commented Oct 4, 2018

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.

@danfinlay
Copy link
Contributor

Alright, we’ve published a rollback to 4.11.1, called 4.13.0. We would still really appreciate reproduction steps.

@AleG94
Copy link
Author

AleG94 commented Oct 5, 2018

@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.

@danfinlay danfinlay added the 4.12 label Oct 5, 2018
@danfinlay
Copy link
Contributor

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.

@danfinlay
Copy link
Contributor

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.

@AleG94
Copy link
Author

AleG94 commented Oct 5, 2018

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.

danfinlay added a commit that referenced this issue Oct 7, 2018
While MetaMask never officially supported subscriptions, we added a
subscription subprovider to our provider-engine, which people began
building on.

We have since moved to json-rpc-engine, which lacks this subprovider. We
thought this would be fine, since we never officially supported it, but
apparently even Drizzle was building its UI framework on this API
expectation, so we decided breaking was unacceptable.

Rather than completely engineer a new subscription subprovider for
json-rpc-engine, or add websocket support (yet), I came up with a very
simple way of integrating our old support into the new inpage-provider.

Should have the added benefit of automatic memory management,
potentially solving memory leaks related to the old subscription
support.

Likely fixes #5425, pushing as a PR so we can provide the build to those
affected devs and see if this fixes their issue.
@ghost ghost assigned danfinlay Oct 7, 2018
@ghost ghost added the in progress label Oct 7, 2018
@danfinlay
Copy link
Contributor

danfinlay commented Oct 7, 2018

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.

@AleG94
Copy link
Author

AleG94 commented Oct 8, 2018

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.

@danfinlay
Copy link
Contributor

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

@tmashuang
Copy link
Contributor

We have been working implementing the web3 1.0 subscription method once again. Let us know if this build is breaking your dapps.
#5458 (comment)

@AleG94
Copy link
Author

AleG94 commented Oct 8, 2018

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".

@tmashuang
Copy link
Contributor

tmashuang commented Oct 8, 2018

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

@danfinlay
Copy link
Contributor

danfinlay commented Oct 9, 2018

@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 support@metamask.io

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

@AleG94
Copy link
Author

AleG94 commented Oct 9, 2018

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.

@DaneWiid1
Copy link

DaneWiid1 commented Oct 9, 2018

@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 ?

@tmashuang
Copy link
Contributor

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

@ghost ghost removed the in progress label Oct 9, 2018
@danfinlay
Copy link
Contributor

Thanks for your patience. We have a new build that we hope has fixed this issue here: #5475 (comment)

@AleG94
Copy link
Author

AleG94 commented Oct 10, 2018

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.

@danfinlay
Copy link
Contributor

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?

@AleG94
Copy link
Author

AleG94 commented Oct 10, 2018

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.

@allegramarie
Copy link

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?

@bdresser
Copy link
Contributor

bdresser commented Nov 12, 2018

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

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

@allegramarie
Copy link

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

@tmashuang
Copy link
Contributor

@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)
  }
})

@allegramarie
Copy link

allegramarie commented Nov 13, 2018

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)
	}
}

@bdresser bdresser reopened this Apr 8, 2019
@bdresser bdresser closed this as completed Apr 8, 2019
@alexiicon
Copy link

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants