cmditch / elm-ethereum

dApps in Elm
https://package.elm-lang.org/packages/cmditch/elm-ethereum/1.0.1/
BSD 3-Clause "New" or "Revised" License
146 stars 21 forks source link

Support multiple instances of Web3 objects (for reasons of security/trust) #23

Closed cmditch closed 6 years ago

cmditch commented 7 years ago

See https://gist.github.com/frozeman/fbc7465d0b0e6c1c4c23#gistcomment-1741887 for impetus. I'm curious if this worry is still relevant, I suspect it is, despite services like Infura and MetaMask.

A number of ways to potentially go about this, but should not be priority, until user/dev demand necessitates it:

cmditch commented 7 years ago

This has become relevant.

Relevant content from that link:

NOTE FOR DAPP DEVELOPERS!

From this version on Mist will not ship its own web3.js instance anymore. We only provide for now web3.currentProvider so you can connect to ethereum. In the future, we will provide a special ethereum object with a default provider.

Also this web3.currentProvider will not allow sync calls anymore, as it is already the case in MetaMask (and it's bad practice in general). So make sure to use the async ones e.g. web3.eth.accounts -> web3.eth.getAccounts(function(){...})

To instantiate your (self-included) web3.js lib you can use:

if(typeof web3 !== 'undefined')
    var web3 = new Web3(web3.currentProvider);
else
    web3 = new Web3(new Web3.providers.HttpProvider("http://localhost:8545"));
cmditch commented 6 years ago

This would add too much complexity to the API, choosing to forgo implementation of this for the time being.