I am trying to connect to my testrpc instance from a my web3 application but I can't seem to connect. The below code should return an array of all the accounts in the testrpc chain.


Web3 = require('web3')
web3 = new Web3(new Web3.providers.HttpProvider("http://localhost:8545"));

It returns the below and inside the object intelliJ the currentprovider object is as follows. enter image description here

It just seems to print the object I think:

Accounts {
   Eth {
     currentProvider: [Getter/Setter],
     _requestManager: RequestManager { provider: [Object], providers: [Object], subscriptions: {} },
     givenProvider: null,
      { WebsocketProvider: [Function: WebsocketProvider],
        HttpProvider: [Function: HttpProvider],
        IpcProvider: [Function: IpcProvider] },
     _provider: HttpProvider { host: 'http://localhost:8545', timeout: 0, connected: false },
     setProvider: [Function],
     BatchRequest: [Function: bound Batch],
      { [Function: ex]
        formatters: [Object],
        utils: [Object],
        Method: [Function: Method] },
     clearSubscriptions: [Function],
     getProtocolVersion: { [Function: send] request: [Function: bound ], call: 'eth_protocolVersion' },
     getCoinbase: { [Function: send] request: [Function: bound ], call: 'eth_coinbase' },
     isMining: { [Function: send] request: [Function: bound ], call: 'eth_mining' },
     getHashrate: { [Function: send] request: [Function: bound ], call: 'eth_hashrate' },
     isSyncing: { [Function: send] request: [Function: bound ], call: 'eth_syncing' },
     getGasPrice: { [Function: send] request: [Function: bound ], call: 'eth_gasPrice' },
     getAccounts: { [Function: send] request: [Function: bound ], call: 'eth_accounts' },
     getBlockNumber: { [Function: send] request: [Function: bound ], call: 'eth_blockNumber' },
     getBalance: { [Function: send] request: [Function: bound ], call: 'eth_getBalance' },
     getStorageAt: { [Function: send] request: [Function: bound ], call: 'eth_getStorageAt' },
     getCode: { [Function: send] request: [Function: bound ], call: 'eth_getCode' },
     getBlock: { [Function: send] request: [Function: bound ], call: [Function: blockCall] },
     getUncle: { [Function: send] request: [Function: bound ], call: [Function: uncleCall] },
     getCompilers: { [Function: send] request: [Function: bound ], call: 'eth_getCompilers' },
      { [Function: send]
        request: [Function: bound ],
        call: [Function: getBlockTransactionCountCall] },
      { [Function: send]
        request: [Function: bound ],
        call: [Function: uncleCountCall] },
      { [Function: send]
        request: [Function: bound ],
        call: 'eth_getTransactionByHash' },
      { [Function: send]
        request: [Function: bound ],
        call: [Function: transactionFromBlockCall] },
      { [Function: send]
        request: [Function: bound ],
        call: 'eth_getTransactionReceipt' },
     getTransactionCount: { [Function: send] request: [Function: bound ], call: 'eth_getTransactionCount' },
     call: { [Function: send] request: [Function: bound ], call: 'eth_call' },
     estimateGas: { [Function: send] request: [Function: bound ], call: 'eth_estimateGas' },
     sendSignedTransaction: { [Function: send] request: [Function: bound ], call: 'eth_sendRawTransaction' },
     signTransaction: { [Function: send] request: [Function: bound ], call: 'eth_signTransaction' },
     sendTransaction: { [Function: send] request: [Function: bound ], call: 'eth_sendTransaction' },
     sign: { [Function: send] request: [Function: bound ], call: 'eth_sign' },
     compile: { solidity: [Object], lll: [Object], serpent: [Object] },
     submitWork: { [Function: send] request: [Function: bound ], call: 'eth_submitWork' },
     getWork: { [Function: send] request: [Function: bound ], call: 'eth_getWork' },
     getPastLogs: { [Function: send] request: [Function: bound ], call: 'eth_getLogs' },
     subscribe: { [Function] call: undefined },
      Net {
        currentProvider: [Getter/Setter],
        _requestManager: [Object],
        givenProvider: null,
        providers: [Object],
        _provider: [Object],
        setProvider: [Function],
        BatchRequest: [Function: bound Batch],
        extend: [Object],
        getId: [Object],
        isListening: [Object],
        getPeerCount: [Object],
        getNetworkType: [Function: bound getNetworkType] },
     accounts: [Circular],
      Personal {
        currentProvider: [Getter/Setter],
        _requestManager: [Object],
        givenProvider: null,
        providers: [Object],
        _provider: [Object],
        setProvider: [Function],
        BatchRequest: [Function: bound Batch],
        extend: [Object],
        getAccounts: [Object],
        newAccount: [Object],
        unlockAccount: [Object],
        sendTransaction: [Object],
        lockAccount: [Object],
        importRawKey: [Object],
        sign: [Object],
        ecRecover: [Object],
        net: [Object] },
     Contract: [Function: Contract],
      { [Function: Iban]
        toAddress: [Function],
        toIban: [Function],
        fromAddress: [Function],
        fromBban: [Function],
        createIndirect: [Function],
        isValid: [Function] },
     abi: ABICoder { _types: [Array] } },
   Wallet {
     length: 0,
     _accounts: [Circular],
     defaultKeyName: 'web3js_wallet' } }

The testRPC server starts successfully too: enter image description here

  • 1
    Did you try if other commands do work?
    – Ismael
    Jul 23, 2017 at 17:21

4 Answers 4


If you are using the new web3.js 1.0.0-beta, then try this (all the syntax has changed, sigh). Tested with testrpc -d.

> var Web3 = require('web3');
> var web3 = new Web3('http://localhost:8545');
> web3.version;
> web3.eth.getAccounts().then(console.log);
Promise { ... }
> [ '0x90F8bf6A479f320ead074411a4B0e7944Ea8c9C1',
  '0x1dF62f291b2E969fB0849d99D9Ce41e2F137006e' ]

Absolutely everything is asynchronous now, hence the messing about with promises with the like of the .then method. I've spent the last day grappling with this - it's very strange at first, but is improving with familiarity.

If you want the accounts in a variable, you can do it like this, but take care not to use the variable until the promise is resolved.

> var foo;
> web3.eth.getAccounts().then(accts => {foo = accts});
> foo
[ '0x90F8bf6A479f320ead074411a4B0e7944Ea8c9C1',
  '0x1dF62f291b2E969fB0849d99D9Ce41e2F137006e' ]
  • when that was changed?
    – noisy
    Jul 28, 2017 at 8:19
  • I don't know exactly - I think v.1.0.0 became the default npm install within the last couple of weeks. You can install the old stable version with npm install [email protected], but it looks like the future lies with this, so I reckon it's worth getting to grips with. Jul 28, 2017 at 10:30
  • Yay, this saved me! Been trying to figure this out for a while now. They really need to update their docs if the syncronous functions are going to no longer work. github.com/ethereum/wiki/wiki/JavaScript-API
    – raidfive
    Aug 15, 2017 at 4:00
  • For regular JS: web3.eth.getAccounts().then(function(accts) { console.log(accts); }) Mar 29, 2018 at 1:33
  • This also works and is briefer, which is handy when working at the console: web3.eth.getAccounts().then(console.log). Mar 31, 2018 at 18:00

I tested your code and it seems to work. I also used testrpc.


var Web3 = require('web3')
var web3 = new Web3(new Web3.providers.HttpProvider("http://localhost:8545"));


The accounts are correctly logged with the output ok. Have you tried to run the command node yourscript.js?


There seems to be a bug from the latest release of web3. npm install grabs 1.0.0-beta, which is not the stable release (0.20.0).

Reinstall with

npm uninstall web3

npm install [email protected] --save

Then try again. It should work.


Did you tried to check with truffle console?

Also check if anything is being logged in testrpc console after execution.

I would suggest restart your testrpc as nothing seems wrong your code and it is working perfectly for me also.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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