0
var gogo =web3.eth.getBalance("0xXXXXXXXXXXXXXX")
.then(console.log);

console.log(gogo);

if (gogo > 123) {
    console.log('enough.');
}

how to run if in this case? Thanks for helping me.

1 Answer 1

1

You need to use the result in your callback function, after it's returned. Hopefully this helps:

// Code here runs first.
web3.eth.getBalance("0xXXXXXXXXXXXXXX")
.then(function (gogo) {
  // Code in here runs third, after the call to `getBalance` returns.
  if (gogo > 123) {
    console.log('enough.');
  }
});

// Code here runs second.
console.log('Here!');
2
  • How can i know the sort of these unit? Functions alaways are Later because return?
    – 戴廷逸
    Commented Nov 8, 2018 at 4:06
  • This is just how asynchronous JavaScript works.
    – user19510
    Commented Nov 8, 2018 at 4:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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