tezos.token_transfers
index
This index allows indexing token transfers of contracts compatible with FA1.2 or FA2 standards.
dipdup.yaml
spec_version: 3.0
package: demo_tezos_token_transfers
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_transfers
datasources:
- tzkt
handlers:
- callback: on_token_transfer
contract: tzbtc_mainnet
Callback receives TzktTokenTransferData
model that optionally contains the transfer sender, receiver, amount, and token metadata.
from decimal import Decimal
from decimal import InvalidOperation
from demo_tezos_token_transfers.handlers.on_balance_update import on_balance_update
from dipdup.context import HandlerContext
from dipdup.models.tezos import TezosTokenTransferData
async def on_token_transfer(
ctx: HandlerContext,
token_transfer: TezosTokenTransferData,
) -> None:
from_, to = token_transfer.from_address, token_transfer.to_address
if not from_ or not to or from_ == to:
return
try:
amount = Decimal(token_transfer.amount or 0) / (10**8)
except InvalidOperation:
return
if not amount:
return
await on_balance_update(address=from_, balance_update=-amount, timestamp=token_transfer.timestamp)
await on_balance_update(address=to, balance_update=amount, timestamp=token_transfer.timestamp)
Help and tips -> Join our Discord
Ideas or suggestions -> Issue Tracker
GraphQL IDE -> Open Playground