0

First I connected web3 with Infura. Then reading an ethereum account.

I receive the following error while fetching account balance through node.js console.

> web3.eth.getBalance(address, (err, bal) => { balance = bal })
TypeError: this.provider.sendAsync is not a function
    at RequestManager.sendAsync (/home/kavi/node_modules/web3/lib/web3/requestmanager.js:80:19)
    at Eth.send [as getBalance] (/home/kavi/node_modules/web3/lib/web3/method.js:141:42)

this is the snapshot

  • Please write down a proper question. – DamiToma Jun 30 at 9:07
  • 1
    Web3.js v1 has deprecated sendAsync for send (or vice-versa, so check your web3 version). – goodvibration Jun 30 at 10:26
1

Try with this:

$ node
> const Web3 = require('web3');
> const URL = "https://mainnet.infura.io/v3/ca689c96846043b18d038f8c97174cf6"    
> const web3 = new Web3(new Web3.providers.HttpProvider(URL))
> web3.version.api
'0.20.0'
> const address = "0xa92b75a1349426380edd57b4858674cdb327a30d"
> web3.eth.getBalance(address, (err, wei) => { balance = web3.fromWei(wei, 'ether')})
> balance.toString()
'2089.198909964156321893'

If you use web3 version 1.0 use: web3.utils.fromWei

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.