1. I have a running blockchain on .
  2. I have created local-node on my system using following commands:

    geth --datadir bkc_data --networkid 89992018 --bootnodes enode://9b46f0691dd12ae427adde13988a56e4691ddcba52f7d6f32d4a4129c709196d1ade96985a9522aa73cac957b666b1f41d69ebceae350643ae83217196e6240d@ --rpc --rpcaddr "" --rpcport "8545" --rpcapi=eth,web3,net,personal,ssh,db,debug --nodiscover console 2>console.log
  3. Inside geth console, I am adding peer using command:

  4. Now in the same directory, I have abc.js which has following code:

    var Web3 = require('web3');
    var web3 = new Web3(new Web3.providers.HttpProvider(""));
    console.log("block number => "+web3.eth.blockNumber);
  5. Now, in terminal, I am running node abc.js from same directory but I am getting block number => undefined

Kindly let me know, where I am making mistake. Any help is appreciated. Thank You.

Note: (Let me know if you need more information).

1 Answer 1


Try instead to make an async call as following:

web3.eth.getBlockNumber(function(error, result){ 
  if (!error)
    console.log("block number => "result)
  • I am getting following error: There is not missing parenthesis. web3.eth.getBlockNumber(callback(error, result){ if(!error) cosole.log(result) }) ^SyntaxError: missing ) after argument list at new Script (vm.js:74:7) at createScript (vm.js:246:10) at Object.runInThisContext (vm.js:298:10) at Module._compile (internal/modules/cjs/loader.js:657:28) at Object.Module._extensions..js (internal/modules/cjs/loader.js:700:10) at Module.load (internal/modules/cjs/loader.js:599:32) ) Jul 30, 2018 at 20:23
  • Could you please confirm once that my (1) geth Command & (2)Http-provider statements are totally correct or not ? Thank You. Jul 30, 2018 at 20:25
  • 1
    Your answer is working. Just need to replace 'callback' with 'function'. Could you please let me know, how can I execute a 'sendTransaction' through simple javascript file(same as above). Thank You. Jul 30, 2018 at 20:38

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.