Indexing USDT on Tron
Tron support in SQD is now in public beta. Please report any bugs or suggestions to Squid Devs.
Download the project
Begin by retrieving the template and installing the dependencies:TronBatchProcessor configuration
Squid processor is a term with two meanings:- The process responsible for retrieving and transforming the data.
- The main object implementing that process.
TronBatchProcessor is the class that should be used for processor objects. Our first step is to create the processor and configure it to fetch USDT transfers data:
src/main.ts
TronBatchProcessor reference.
The next step is to configure data decoding and transformation.
Processing the data
The other part of the squid processor configuration is the callback function used to process batches of filtered data, the batch handler. It is typically defined within aprocessor.run() call, like this:
processoris the object described in the previous sectiondatabaseis aDatabaseimplementation specific to the target data sink. We want to store the data in a PostgreSQL database and present with a GraphQL API, so we provide aTypeormDatabaseobject here.ctxis the batch context object that exposes a batch of data (atctx.blocks) and any data persistence facilities derived fromdb(atctx.store). See Block data for Tron for details on how the data batches are presented.
src/main.ts
USDT_ADDRESS and have a TRANSFER_TOPIC as the first topic, decodes the log and saves a Transfer record with the obtained data to the database. See Prepare the store for more details on how the database interface works.
Notice that we used the SQD EVM codec and
squid-evm-typegen-generated module to decode events. Since Tron events are fully EVM-compatible, this is the recommended way.This tooling requires that the hex values are prefixed with 0x, as shown above.
