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

    geth --datadir bkc_data --networkid 89992018 --bootnodes enode://9b46f0691dd12ae427adde13988a56e4691ddcba52f7d6f32d4a4129c709196d1ade96985a9522aa73cac957b666b1f41d69ebceae350643ae83217196e6240d@128.230.208.73:30301 --rpc --rpcaddr "127.0.0.1" --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:

    admin.addPeer("enode://62bceb7302bf4368858a15c408ab8d57a263cb590fb4a6ccb588a1ecad42266772370c5d6b3cdaa1a1284c80f6f3fe959ba1453761482fbcc9920a4c2c7099ab@128.230.208.73:30303")
    
  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("http://127.0.0.1:8545"));
    
    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).

2

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) ) – Vishal Kudale Jul 30 '18 at 20:23
  • Could you please confirm once that my (1) geth Command & (2)Http-provider statements are totally correct or not ? Thank You. – Vishal Kudale Jul 30 '18 at 20:25
  • 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. – Vishal Kudale Jul 30 '18 at 20:38

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.