var test = await web3.eth.getBlockNumber();

I copied this code from the docs but when I call it I get this error:

TypeError: e is not a function

Anyone know what might be causing this?

I'm able to do

userAccountAddress = await web3.eth.accounts[0];

no problem.


2 Answers 2


Most web3.js objects allow a callback as the last parameter, as well as returning promises to chain functions.

The error TypeError: e is not a function means it is missing callback function.

In your case await must work out of box, I'm thinking you're use it wrong, here is an example from documentation getBlockNumber():

> 2744

If you still want use await you must use it right, with async keyword.

(async ()=> { await web3.eth.getBlockNumber(console.log) })()
> 2744

Looks ugly ya? That's javascript my friend.

Tip: If you want the blocknumber you can use web3.eth.blockNumber.

  • 1
    Please make the tip larger, it works great in truffle develop! Commented Aug 19, 2018 at 0:42

In the interactive REPL mode this is not working (await is only valid in async function)

userAccountAddress = await web3.eth.accounts[0];

If you just want to play around in interactive mode you could do:

> let n;
> n = web3.eth.getBlockNumber();
Promise { <pending> }
> n
Promise { 392629 }

Here i did not handle the promise, just waited for it to resolve.

If it should be for actual code you have to write an async function and await inside, just as @Зелёный said.

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.