2

I am wondering how to effectively monitor for some given address for FA 1.2 and FA 2 token balance updates. Given that the entrypoints to the contract are defined, I'd like to write something which reads in each "block" response from the Tezos node, iterates over all executed transactions, and analyzes the entrypoints to track when one of my addresses had a transaction occur.

This would of course only be feasible if all potential token transfers appear as "Transaction" operations in the block response, with the appropriate endpoints.

An example of a token I may want to track is tzBTC, which does call transfer internally - and it does show up in the RPC response.

The other method of doing this would be to look inside the storage of each contract, but that doesn't seem particularly scalable.

3
  • 2
    You can use BCD API for retrieving FA1.2/FA2 transfers for a particular account: https://api.better-call.dev/v1/tokens/{network}/transfers/{account_address} Dec 8, 2020 at 22:16
  • @MichaelZaikin I would like to avoid using a third party. Although, the method BCD has used is likely what I am looking for.
    – enforser
    Dec 8, 2020 at 22:19
  • Why are people so scared of using third party? It's free. It's open source. What's the problem?
    – Groxan
    Dec 10, 2020 at 1:00

1 Answer 1

2

An example of a token I may want to track is tzBTC, which does call transfer internally - and it does show up in the RPC response.

That is the answer, isn't that? :)


So, you need to iterate over transactions in a block and check for those where destination is {tzBTC} and parameters.entrypoint is "transfer". Then you need to analyze the parameters. They look like this:

"parameters": {
  "entrypoint": "transfer",
  "value": {
    "prim": "Pair",
    "args": [
      {
        "string": "tz1Y77S4EcSQwyUWzAwtYGU6NTtKXbH3VQLg"      <--- from
      },
      {
        "prim": "Pair",
        "args": [
          {
            "string": "tz1ZbokEB5tekbPxyWdo28ugn3UUkbQjguK3"  <--- to
          },
          {
            "int": "119380000"                                <--- amount
          }
        ]
      }
    ]
  }
}

As you can see, you can easily extract tokens amount, sender and receiver, and check whether it's you.

However, I highly recommend you use existing solutions, like BCD API, because there are so many pitfalls. Otherwise you will likely shoot yourself in the foot.

1
  • 1
    Right, I think that is my preferred solution, provided I scan all transaction operations, including the transactions which are created by contracts (returned in "internal_operation_results"). Thanks for the response, glad to hear my initial idea doesn't have any obvious flaws. Noted that using the BCD API can remove a lot of complexity. I will certainly compare the results that my solution returns compared to their API :).
    – enforser
    Dec 10, 2020 at 1:57

Your Answer

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

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