tezos.token_balances
index
This index allows indexing token balances of contracts compatible with FA1.2 or FA2 standards. You can either index transfers and cumulatively calculate balances or use this index type to fetch the latest balance information directly.
dipdup.yaml
spec_version: 3.0
package: demo_tezos_token_balances
contracts:
tzbtc_mainnet:
kind: tezos
address: KT1PWx2mnDueood7fEmfbBDKx1D9BAnnXitn
typename: tzbtc
datasources:
tzkt:
kind: tezos.tzkt
url: https://api.tzkt.io
indexes:
tzbtc_holders_mainnet:
kind: tezos.token_balances
datasources:
- tzkt
handlers:
- callback: on_balance_update
contract: tzbtc_mainnet
Callback receives TzktTokenBalanceData
model that optionally contains the owner, token, and balance values
from decimal import Decimal
from demo_tezos_token_balances import models as models
from dipdup.context import HandlerContext
from dipdup.models.tezos import TezosTokenBalanceData
async def on_balance_update(
ctx: HandlerContext,
token_balance: TezosTokenBalanceData,
) -> None:
holder, _ = await models.Holder.get_or_create(address=token_balance.contract_address)
holder.balance = Decimal(token_balance.balance_value or 0) / (10**8)
await holder.save()
Help and tips -> Join our Discord
Ideas or suggestions -> Issue Tracker
GraphQL IDE -> Open Playground