Ganache-cli: `web3.eth.accounts` not supported?

Created on 23 Jan 2017  Â·  5Comments  Â·  Source: trufflesuite/ganache-cli

According to doc eth_accounts should be implemented but I when attempting to do

var accounts = web3.eth.accounts;

I get the error

Error: Synchronous requests are not supported.

The same error persists when attempting a callback:

web3.eth.accounts(function(err, res) {
  console.log('err: ' + err + ', res: ' + res);
});

This TestRPC is a great idea but IMO only makes sense if I can transparently exchange it for the full-blown RPC calls.
I am running the latest testrpc on Windows 7.1.

Most helpful comment

I was having the same problems trying to display the eth accounts in the console. This is what ended up working for me:

web3.eth.getAccounts().then(console.log)

All 5 comments

You should never use synchronous xhr requests in JavaScript. In this case,
you should use web3.eth.getAccounts to get the information you need.

Web3 contains asynchronous equivalents for every synchronous function.
Please consult the Web3 documentation for more info.

On Jan 23, 2017 5:14 AM, "Sebastian C. Bürgel" notifications@github.com
wrote:

According to doc https://github.com/ethereumjs/testrpc#implemented-methods
eth_accounts should be implemented but I when attempting to do

var accounts = web3.eth.accounts;

I get the error

Error: Synchronous requests are not supported.

The same error persists when attempting a callback:

web3.eth.accounts(function(err, res) {
console.log('err: ' + err + ', res: ' + res);
});

This TestRPC is a great idea but IMO only makes sense if I can
transparently exchange it for the full-blown RPC calls.
I am running the latest testrpc on Windows 7.1.

—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
https://github.com/ethereumjs/testrpc/issues/246, or mute the thread
https://github.com/notifications/unsubscribe-auth/AAFp1V_JJlb74agS7_3UlTB_Hb_nt5jnks5rVKfEgaJpZM4LrBow
.

That is good advise @tcoulter - yet for quick hacking (mostly what I'd use this for) it would be good to have these quick-and-dirty synchronous requests. For the clean deploy I'd anyway use my full node.

I was having the same problems trying to display the eth accounts in the console. This is what ended up working for me:

web3.eth.getAccounts().then(console.log)

Something like this could work.
var accounts = await web3.eth.getAccounts((error,response) => { if (!error) return response })

This has changed in Web3 1.0.0.

They make heavy use of synchronous calls for things that are not subscriptions, so I think this should be reopened.

Ping @tcoulter

Was this page helpful?
0 / 5 - 0 ratings