1

Let’s say that I have:

    1. Token Contract (ERC20 token standard)
    1. Dapp(Contract)

The Dapp account "have" some token. Is there any way to know if the token balance of the Dapp changed?

In another words, I know that smart contract CAN NOT listen to Events I don't want to use a 3rd party server

What are my options?

2
  • 1
    use an event inside the transfer or deposit function
    – Badr Bellaj
    Commented Aug 14, 2017 at 12:55
  • Why do you want the contract to run code in response to a token balance? Tell us more about the context, and what the contract will do in reaction to a balance change.
    – carver
    Commented Aug 14, 2017 at 20:07

1 Answer 1

1

There is no way for your contract to automatically take some action, in response to its token balance changing.

Some reasonable approaches:

  • If your contract needs to limit other actions until its token balance changes, then include a restriction at the beginning of those actions that confirms the balance change
  • Run a server that watches the blockchain for token balance events and calls into your contract on a change.
  • Write a world-callable function that will query the token balance, and update its internal state as appropriate. Whoever has some intrinsic motivation for your contract to be updated can call that function when appropriate.

Which solution is best depends on the details of what you're building.

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.