0

I have a localhost blockchain node successfully working and my contract deploys OK using truffle. Geth works too. But when I try and access the node via React and the Chrome console when running React I am not getting anything meaningful. Even web3.eth.coinbase does not work.

Example code -

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


var x = web3.eth.coinbase;

And x is undefined.

Here is the connection string -

geth --datadir ~/blockchain/mybc1 --rpc --rpcaddr "localhost" --port 8545 --rpcport 8545 --networkid 1234 console 2> consolemybc1.log

Has anyone any ideas about this?

  • The '--port' specifies the p2p port, which, by default is 30303. It shouldn't be the same as the "--rpcport" . Try removing the "--port 8545" and see what happens? – Linmao Song Apr 3 '18 at 15:45
  • I changed that and the same issue exists. – Trevor Oakley Apr 3 '18 at 16:49
  • Try adding --rpccorsdomain '*' (notice the single quote) ? – Linmao Song Apr 3 '18 at 16:58
  • Done - same issues. I think web3 was changed too? But is there a way to debug the connection? – Trevor Oakley Apr 3 '18 at 17:19
  • Check for web3 itself... is it still undefined... if it is not...you can check web3.version.api – kherwa Apr 3 '18 at 17:22
1

The installation somehow had different versions. The default is 1.0 using npm install web3 which fails.

Here is the correct installation -

npm install web3@0.20.2

Reference - https://www.versioneye.com/nodejs/web3/0.20.2

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.