I have ganachi-cli running at localhost:8545.
When I try to use the following code, web3.eth.coinbase is undefined. Is there anything wrong?
$ cat main.js
#!/usr/bin/env node
// vim: set noexpandtab tabstop=2:
const Web3 = require('web3');
const web3 = new Web3(new Web3.providers.HttpProvider("http://localhost:8545"));
console.log(web3.eth.coinbase);
$ ./main.js
undefined
In your geth console, what does it print? It seems like you don't have any account set yet.
@pengyu
If this is web3.js 1.0 then you should use web3.eth.getCoinbase((err, coinbase) => {console.log(coinbase)}) ; If it's 0.20; then it's likely that you don't have the accounts setup yet. check web3.eth.getAccounts(console.dir)
Most helpful comment
@pengyu
If this is web3.js 1.0 then you should use
web3.eth.getCoinbase((err, coinbase) => {console.log(coinbase)}); If it's 0.20; then it's likely that you don't have the accounts setup yet. checkweb3.eth.getAccounts(console.dir)