The multi-chains SubQuery project for NFT2.0 protocol. This includes indexer for all protocol on-chain events, including but not limited to:
- Factory events: create data-registries, collections, derived-accounts
- Data-registry events: write, derive.
- Collection events: mint, burn, transfer.
- Derived-account events: claim royalty.
- Addons events: addons created.
- Install dependencies
$ yarn
- Create .env file of special chain from template. Ex for avax:
$ cp .env.example .env.avax
- Populate contract address, block number, etc to
.env.avax
file
- Generate file yaml and all manifest for a chain:
$ CHAIN=<chain> yarn codegen -f project-multichain.ts && mv project-multichain.yaml project-<chain>.yaml
CHAIN env var can be one of supported chains, including: dera-testnet, avax, bnb, avax-testnet, bnb-testnet
Eg., command for
avax
:
$ CHAIN="avax" yarn codegen -f project-multichain.ts && mv project-multichain.yaml project-avax.yaml
This command will also generate types manifest in /src/types folder
- Compile code
$ yarn build -f subquery-multichain.yaml
This command will compile TS code and store artifacts to /dist folder, every update logic, including configuration in project-multichain.ts would require to reexecute this command
- Spin up infrastructure stack, which includes PostgreSQL, Subquery node, GraphQL engine by using docker compose
$ yarn start:docker
- Access GraphQL playground local to query
- Execute UT
$ yarn test
query {
collections(
first: 5
orderBy: [BLOCK_HEIGHT_DESC]
filter: { chainId: { equalTo: 20240801 } }
) {
nodes {
chainId
id
blockHeight
address
}
}
}
The result should look something like this:
{
"data": {
"collections": {
"nodes": [
{
"chainId": 20240801,
"id": "0xc477ef1211e3c20f9069b1d159a88ae2a8024978",
"blockHeight": "1460",
"address": "0xc477ef1211e3c20f9069b1d159a88ae2a8024978"
},
{
"chainId": 20240801,
"id": "0x97a50967fd59b2aab8841cff7304f77f74e22dcf",
"blockHeight": "1459",
"address": "0x97a50967fd59b2aab8841cff7304f77f74e22dcf"
},
{
"chainId": 20240801,
"id": "0x17e5896d4fdb55c79481cb96e07b01dfda0f1382",
"blockHeight": "212",
"address": "0x17e5896d4fdb55c79481cb96e07b01dfda0f1382"
},
{
"chainId": 20240801,
"id": "0x7136c629e76c0dcad52c48bfa41ad35c46aeecf4",
"blockHeight": "187",
"address": "0x7136c629e76c0dcad52c48bfa41ad35c46aeecf4"
}
]
}
}
}
- Via cURL (after publishing project to Managed Service)
$ curl -g -X POST -H "Content-type: application/json" \
-d '{"query": "query{collections(first:5) {nodes {chainId id blockHeight address}}}"}' \
<subquery-query-url>
-
Prerequisites: step Build must be done before doing publishment.
-
Publish project manifest to IPFS
Mainnets
$ SUBQL_ACCESS_TOKEN="<access-token>" subql publish -f subquery-multichain.yaml
Testnets
$ SUBQL_ACCESS_TOKEN="<access-token>" subql publish -f subquery-multichain-testnet.yaml
The IPFS CID will be saved in .project-cid file in root folder
- Deployment can be done either via Console or SubQL CLI
$ SUBQL_ACCESS_TOKEN="<access-token>" subql deployment:deploy -d \
--org "<your-org>" \
--projectName "<project-name>" \
--endpoint "<rpc-endpoint>" \
--ipfsCID "<ipfs-cid>"
- Down Docker compose
$ docker-compose down
- Cleanup PostgreSQL data
$ sudo rm -rf ./.data/
- Cleanup compiled source
$ sudo rm -rf ./dist/
$ sudo rm -rf ./src/types/
- Delete deployment on Managed service
$ SUBQL_ACCESS_TOKEN="<access-token>" subql deployment:delete -d \
--org "<your-org>" \
--project_name "<project-name>" \
--deploymentID "<deployment-id>"
- Subquery-node unhealthy upon docker-compose start, it might occur due to RPC endpoint rate limit, which leads to failure on sync up latest chain status, the solution for this issue is simply waiting for RPC connection success, by monitoring subquery-node logs
$ docker logs -f <subquery-node-container>
Copyright belongs to DERA chain, 2023-2024.