2

I'm using web3js version 0.20.6.

When I try the getBalance function it returns a string and it works. But the documentation here says it should return a promise. But the documentation here says it returns a string. Is this a change between the versions?

In the world of async calls using promise, the chain of method calls needs to get converted into promise based then and catch. Is it okay to have so many layers of promise going from parent to child to its child method?

4

Yes, getBalance returns a promise. The spec you're referencing is old but appropriate for the version of web3js you're using. You might accidentally be using web3js 1.0.0. I'd try this:

web3.eth.getBalance()
.then(function (balance) {
    console.log(balance);
}).catch(function(e) {
    console.log(e);
});
  • Is the best practice to have all of the method calls above this to return promise too? – Sundar Jul 19 '18 at 4:16

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.