Ethereum Node Connection: TypeError: Cannot read property 'version' of undefined

0 votes

I have an ethereum node running in my system:

--rpc --rpcaddr "127.0.0.1" --rpcport "8000" --rpccorsdomain "*" --datadir "/home/Sample/Ethereum/Data/node1" --port "30303" --maxpeers 2 --ipcapi "admin,db,eth,debug,miner,net,shh,txpool,personal,web3,solc" --rpcapi "db,eth,net,web3,personal" --networkid 1900 --nat "any" --unlock "0" --nodiscover console init ~/Ethereum/Data/node1/customgenesis.json

I am trying to connect to this node from nodejs using the following code:

var Web3 = require('web3');
var web3 =Web3(new Web3.providers.HttpProvider('http://127.0.0.1:8000'));
console.log(web3.version.api)

but, I am getting this error

TypeError: Cannot read property 'version' of undefined

Can someone help me solve this issue?

Oct 24, 2018 in Blockchain by slayer
• 29,050 points
153 views

1 answer to this question.

0 votes

In the code that you are using to connect to the node, you are missing the new keyword. Your code should be:

var Web3 = require('web3');
var web3 =new Web3(new Web3.providers.HttpProvider('http://127.0.0.1:8000'));
console.log(web3.version.api)

This should work..

answered Oct 24, 2018 by Omkar
• 67,290 points

Related Questions In Blockchain

0 votes
0 answers
0 votes
1 answer

How can i read headers of blockchain in multichain?

You could use a recent feature known ...READ MORE

answered Mar 26, 2018 in Blockchain by Perry
• 17,010 points
34 views
0 votes
1 answer

Connection failed to Ethereum Ropsten Testnet network.

 It looks like your node isn't syncing ...READ MORE

answered Mar 27, 2018 in Blockchain by Christine
• 15,790 points
269 views
0 votes
1 answer

Truffle tests not running after truffle init

This was a bug. They've fixed it. ...READ MORE

answered Sep 11, 2018 in Blockchain by Christine
• 15,790 points
126 views
0 votes
1 answer
0 votes
1 answer

Protocols used in a distributed/dlt system for the nodes to establish communication

yes all are over TCP/IP connections secured by TLS encryption in hashgraph architecture-hashgraph, ...READ MORE

answered Aug 6, 2018 in Blockchain by ariaholic
• 7,320 points
63 views
0 votes
1 answer

Cannot read property 'getBlock' of undefined

getBlock is used by web3 and to use it, ...READ MORE

answered Jan 29 in Blockchain by Omkar
• 67,290 points
41 views
0 votes
1 answer

Blockchain: Installing an earlier version of ethereum using apt-get on

geth does not make the previous version available ...READ MORE

answered Oct 10, 2018 in Blockchain by Omkar
• 67,290 points
50 views