3

I am quite confusued on how users should select the account they want to use with dapps. Before version 0.9.0 of mist I could just use web3.eth.accounts[0] and let users select what account they want to use via the identity chooser of mist.

This seems quite hacky to me, but at least it worked.

However since the release of version 0.9.0 this approach is broken. I guess it doesn't work anymore, because mist does not ship with it's own version of web3 anymore?

So what is the proper way to let users choose the account the want to use in general and especially with mist version 0.9.0?

0

Glad to answer this one.

There were breaking changes indeed from 0.9.0 (July 2017) on. Two main things:

  1. Mist does not provide web3.js anymore to the users, so they can choose whichever version or other libraries it might suit them better.

  2. It also does not allow synchronous web3.js calls anymore, on a move trying to encourage these best practices: while using web3.js 0.19, refer to callback functions, and 1.0.0+ you could use Promises.

Here's an excerpt from the release notes:

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"));

Taken from here: https://github.com/ethereum/mist/releases/tag/v0.9.0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.