0

I have listed the versions of web3 versions installed in my system

 npm ls web3
        inbox@1.0.0 /home/mdvenkatesh/Desktop/etherium solidity programes/inbox
        +-- truffle-hdwallet-provider@0.0.6
        | `-- web3@0.18.4 
        `-- web3@1.0.0-beta.26 

In my code i am using async await. i want to compile my code and run

But i am getting error

accounts = await web3.eth.getAccounts();
           ^^^^^

SyntaxError: await is only valid in async function

1) How to use version 1 without uninstalling the previous version of web3

2)In My previous projects i am using promise's if i uninstall the old version will it effect my previous code while compiling

3) I tried to remove using npm but showing me error

npm remove web3@0.18.4
npm WARN truffle-hdwallet-provider@0.0.6 requires a peer of truffle@4.x but none is installed. You must install peer dependencies yourself.
npm WARN inbox@1.0.0 No description
npm WARN inbox@1.0.0 No repository field.
2

The problem is not related to web3js at all. You need to mark function(lets name the function ‘check’) as ‘async’ before you call functions with await inside of function ‘check’. Take a look the documentation https://javascript.info/async-await

  • Thanks I taught it is web3 error without checking the error – md venkatesh Oct 24 '18 at 7:09

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.