0
var Web3 = require('web3');
var web3 = new Web3(new Web3.providers.HttpProvider('https://ropsten.infura.io/v3/5db0a2fb8a8948fdbe57bb19eecb5674'));

web3.eth.getBalance('0x742d35Cc6634C0532925a3b844Bc454e4438f44e').then((res)=>console.log(web3.utils.fromWei(res,'ether')))

and the following is the error I'm getting after running the above code.

 web3.eth.getBalance(...).then is not a function
    at Object.<anonymous> (C:\gitty\app.js:15:6)
    at Module._compile (module.js:653:30)
    at Object.Module._extensions..js (module.js:664:10)
    at Module.load (module.js:566:32)
    at tryModuleLoad (module.js:506:12)
    at Function.Module._load (module.js:498:3)
    at Function.Module.runMain (module.js:694:10)
    at startup (bootstrap_node.js:204:16)
    at bootstrap_node.js:625:3
2

You need to use callback for getBalance function. kindly read Document .

 web3.eth.getBalance('0x742d35Cc6634C0532925a3b844Bc454e4438f44e',function(error,result){

    if(error){
       console.log(error)
    }
    else{
       console.log(result)
    }
 })

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.