2

The app below is to send the eth value to the account and refresh the account balance. however the balance doesn't show immediately.

   // send the eth to the contract 
   contract.methods.create(model)
                     .send({from: account,value:value })
                     .on('transactionHash', function(hash){
                               console.log('hash',hash);
                      })

   // refresh the account to see the balance
    web3.eth.getBalance(address, function (error, result) {
      if (error) {
      } else {

        }
    })

I am just wondering is there a event callback on web3 to notify the account balance change?

2

Are you using web3 v1? In v1 you can use .then() from the result of send to chain getBalance after the transaction was mined.

// send the eth to the contract 
contract.methods.create(model)
    .send({from: account,value:value })
    .on('transactionHash', function(hash){
        console.log('hash',hash);
    })
    .then(function () {
        // refresh the account to see the balance
        web3.eth.getBalance(address, function (error, result) {
            if (error) {
            } else {
            }
        })
    })

There's no event for balance changes that I'm aware of, but installing a block filter and checking for balance chanes should work.

-1

I've found a new service for receive ethereum callback transaction via webhook. Crypitor. You just need to add your address and the callback url. They will send you a message with every transaction and also erc20. You can take a look at their api document at Crypitor Documentation You don't need to scan balance anymore. it increase alot of performance for your applicationwebhook receive

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.