Below is my code snippet. I wish to wait for the transaction hash value so that I can return my Javascript function with the hash value.

But I get the error "SyntaxError: await is only valid in async functions and async generators" in Firefox console. I'm using web3js 1.0 at https://cdn.jsdelivr.net/gh/ethereum/[email protected]/dist/web3.min.js'

web3.eth.accounts.signTransaction(tx, privateKey).then(signed => {
  const tran = await web3.eth
    .on('confirmation', (confirmationNumber, receipt) => {
      console.log('=> confirmation: ' + confirmationNumber);
    .on('transactionHash', hash => {
      console.log('=> hash');
      //console.log("HASH: ", hash);
      transHash = hash;
    .on('receipt', receipt => {
      console.log('=> reciept');
    .on('error', console.error);
  • you need to wrap that in a promise
    – Majd TL
    Oct 16, 2019 at 15:01

2 Answers 2


Change this:

signed => {

To this:

function(signed) {

And then to this:

async function(signed) {

The middle phase is just an intermediate step in order clarify the syntax for you.


You could also do this:

async (signed) => {

if you want to use shorthand notation.

Not the answer you're looking for? Browse other questions tagged or ask your own question.