MetaMask / web3-provider-engine

A JavaScript library for composing Ethereum provider objects using middleware modules
MIT License
597 stars 328 forks source link

Supporting synchronous dapps, "Web3ProviderEngine does not support synchronous requests." #259

Closed mandelmonkey closed 5 years ago

mandelmonkey commented 6 years ago

Apologies this is not really an issue but I developed a dapp browser using this repo however when loading some notable dapps (that work with the metamask chrome extension) in my dapp browser I get the error Web3ProviderEngine does not support synchronous requests

I see the dapp is calling synchronous methods and seems like they should be calling async however the dapps works in the metamask chrome extension.

So my question is, is this in issue with the dapp? i.e. they should upgrade to asynchronous request or is it good practice to support both in a dapp browser? Why does metamask chrome extension work with sync but not this repo?

thanks!

jamespic commented 6 years ago

MetaMask adds a wrapper around this library, and one of the things in that wrapper is an implementation of the synchronous send method.

Well-written dapps will not use this method (not least, because they'll fail unit tests using Ganache), but unfortunately not all dapps are well-written. If you want a "MetaMask-compatible" provider, you'll need to provide a send method - the version in MetaMask is a good starting point.

mandelmonkey commented 6 years ago

ok thanks for the reply, I guess it also needs a wrapper for a sync getaccounts method?

jamespic commented 6 years ago

Yes and no: send is the name of a Javascript method, that's used to make JSONRPC calls synchronously. MetaMask's send methods includes implementations of eth_accounts, eth_coinbase, eth_uninstallFilter and net_version (I think because these are ones it's difficult to prevent Web3 calling synchronously). Your send implementation will likely need to implement the same methods for MetaMask compatibility.

kumavis commented 5 years ago

hi @mandelmonkey, i really enjoyed playing with Takara and left a little something in mikura-jima

@jamespic's feedback is correct