USDT transfers API
Pre-requisites: NodeJS 20.x or newer, Docker.
@subsquid/evm-processor- for retrieving Ethereum data- the triad of
@subsquid/typeorm-store,@subsquid/typeorm-codegenand@subsquid/typeorm-migration- for saving data to PostgreSQL
@subsquid/evm-typegen- for decoding Ethereum data and useful constants such as event topic0 values@subsquid/evm-abiand@subsquid/evm-codec- runtime dependencies imported by code generated by@subsquid/evm-typegen@subsquid/graphql-server/ OpenReader
1
Create a new folder and initialise a new project
- create
package.json - add
.gitignore.gitignore
2
Install the packages
3
Add a minimal `tsconfig.json`
tsconfig.json
4
Define the schema for both the database and the core GraphQL API
Define the schema for both the database and the core GraphQL API in
schema.graphql:schema.graphql
5
Generate TypeORM classes based on the schema
src/model/index.ts.6
Prepare the database
- create
.envanddocker-compose.yamlfiles.envdocker-compose.yaml - start the database container
- compile the TypeORM classes
- generate the migration file
- apply the migration with
7
Generate utility classes for decoding USDT contract data
Generate utility classes for decoding USDT contract data based on its ABI.
-
Create an
./abifolder: - Find the ABI at the “Contract” tab of the contract page on Etherscan. Scroll down a bit:
-
Copy the ABI, then paste to a new file at
./abi/usdt.json. -
Run the utility classes generator:
src/abi/usdt/, with an index.ts entry point. Typegen v5 removes a stale src/abi/usdt.ts file from the older single-file layout.8
Tie all the generated code together with `src/main.ts`
Tie all the generated code together with a
src/main.ts executable with the following code blocks:- Imports
EvmBatchProcessorobject definitionTypeormDatabaseobject definition- A call to
processor.run()with an inline definition of the batch handlerNote how supplying aTypeormDatabaseto the function causedctx.storeto be a PostgreSQL-compatibleStoreobject.
9
Compile the project and start the processor process
10
Start the GraphQL server
In a separate terminal, configure the GraphQL port and start the GraphQL server:
.env