0

(I am using a private blockchain running on my computer for testing this)

So I am coding a simple front end app, that waits for a user to deposit some value of ETH into an address, before allowing the user to continue execution of the app.

I am wondering is there anyway to set an event listener on certain address, that gets fired every time a transaction is made to that address.

More importantly is it possible to do this without getting into using Contracts just vanilla wallets?

0

I don't think there's any better way than polling. In web3.js 0.2.x, something like this should work (untested code):

function waitForBalance(account, amount, cb) {
  web3.eth.getBalance(account, function (err, balance) {
    if (balance >= amount) {
      cb();
    } else {
      // Try again in 1 second.
      window.setTimeout(function () {
        waitForBalance(account, amount, cb);
      }, 1000);
    }
  });
}

waitForBalance("0x123abc987...", web3.toWei(1, "ether"), function () {
  alert("1 ether received!");
});
| improve this answer | |
  • This answer is good when sticking to simple wallets. But I realize it was fairly easy to deploy a Contract wallet, with custom event handling. This is the approach I ended up using. However thank you for your answer – Robert Lemiesz Mar 2 '18 at 21:56

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.