TransferEVM event topics. This guide can be adapted for Shiden network and other type of tokens as well.
squid-astar-examplerepository on GitHub.
schema.graphqlfile defines them like shis:
@entity- signals that this type will be translated into an ORM model that is going to be persisted in the database
@derivedFrom- signals the field will not be persisted on the database, it will rather be derived
from: Owner) - establishes a relation between two entities
evm-typegentool to generate TypeScript interfaces and decoding functions for EVM logs.
abiparameter points at the JSON file previously created, and the
outputparameter is the name of the file that will be generated by the command itself.
erc721.ts, under the
src/abisubfolder, that defines data interfaces to represent output of the EVM events defined in the ABI, as well as a mapping of the functions necessary to decode these events (see the
eventsdictionary in the aforementione file).
Transferevent has three arguments, named:
tokenId. Their types are, respectively,
uint256. As such, the actual definition of the
Transferevent looks like this:
Transfer(address, address, uint256).
SubstrateProcessoror, in this specific case
SubstrateEvmProcessor. The processor connects to the Subsquid archive to get chain data. It will index from the configured starting block, until the configured end block, or until new data is added to the chain.
src/contracts.tsfile. Here's a summary of what is in it:
processTransferEVM log handler, implementing logic to track token transfers
CHAIN_NODEconstant to the endpoint URL of Astar network (e.g.
totalSupplyvalues used in the
createContractEntityfunction to their correct values (see link in the previous point)
Transfer, they would also have to implement a different handler function from
processTransfer, especially the line where the event
Contextof the correct type (
EvmLogHandlerContext, in this case). The context contains the triggering event and the interface to store data, and is used to extract and process data and save it to the database.
src/processor.tsfile is where the template project instantiates the
SubstrateEvmProcessorclass, configures it for execution, and attaches the handler functions(s).
moonrivernetwork, there are a couple of things to change:
nameargument passed to
SubstrateEvmProcessorconstructor (not necessary, but good practice)
archiveparameter of the
setDataSourcefunction to fetch the Archive URL for Astar.
docker-compose.ymlfile that comes with the template to launch a PostgreSQL container. To do so, run the following command in your terminal:
-dparameter is optional, it launches the container in
daemonmode so the terminal will not be blocked and no further output will be visible.
squid-evm-template_db_1, is running
Transferevent for ERC-721 tokens, but the same process can be applied to ERC-20 tokens as well. It is sufficient to import a new ABI interface, make the necessary changes to the
schema.graphql, launch the
evm-typegentools, and finally adjust the helper and handler functions in