I'm trying to test basic web3 with node. I have testrpc running and I have the following in a javascript file:
var Web3 = require('web3');
var web3 = new Web3(new Web3.providers.HttpProvider("http://localhost:8545"));
console.log(web3.eth.accounts[0]);
When I run node filename.js
it returns undefined. Why is that?
When I change web3.eth.accounts[0]
to web3.eth.accounts
I get this :
Accounts {
currentProvider: [Getter/Setter],
_requestManager:
RequestManager {
provider: HttpProvider { host: 'http://localhost:8545', timeout: 0, connected: false },
providers:
{ WebsocketProvider: [Function: WebsocketProvider],
HttpProvider: [Function: HttpProvider],
IpcProvider: [Function: IpcProvider] },
subscriptions: {} },
givenProvider: null,
providers:
{ WebsocketProvider: [Function: WebsocketProvider],
HttpProvider: [Function: HttpProvider],
IpcProvider: [Function: IpcProvider] },
_provider: HttpProvider { host: 'http://localhost:8545', timeout: 0, connected: false },
setProvider: [Function],
_ethereumCall:
{ getId:
{ [Function: send]
method: [Object],
request: [Function: bound ],
call: 'net_version' },
getGasPrice:
{ [Function: send]
method: [Object],
request: [Function: bound ],
call: 'eth_gasPrice' },
getTransactionCount:
{ [Function: send]
method: [Object],
request: [Function: bound ],
call: 'eth_getTransactionCount' } },
wallet:
Wallet {
_accounts: [Circular],
length: 0,
defaultKeyName: 'web3js_wallet' } }