0

0 down vote favorite I am using express and web3 while i get the blockNumber it returns { [Function: get] request: [Function: bound ] }

my code is

var express = require('express');
 var app = express();

const Web3 = require('web3');
var web3 = new Web3();

web3.setProvider(new web3.providers.HttpProvider('http://localhost:8545'))

app.get('/', function(req, res) {

let Block =  web3.eth.getBlockNumber

console.log(Block);
res.send("It is me");
});

But i need the block number

Sammu Sundar
  • 219
  • 5
  • 14

1 Answers1

2

Perhaps off-topic, as this is really a JS question...

it returns { [Function: get] request: [Function: bound ] }

That's because the call is asynchronous, so it's returning a Javascript Promise.

See the Web3 documentation for an example of how to make the call correctly:

web3.eth.getBlockNumber()
.then(console.log);
> 2744
Richard Horrocks
  • 37,835
  • 13
  • 87
  • 144
  • In the code at question, there is not even a call. Just let Block = web3.eth.getBlockNumber, which obviously returns an object containing a function. – goodvibration Dec 06 '18 at 10:01
  • @goodvibration - Good point - I missed that there were no parentheses. Either way, he's going to need to understand how promises work for any of the web3 async stuff :-) – Richard Horrocks Dec 06 '18 at 10:07