This subgraph indexes ERC20 token transfers and approvals on the Sonic blockchain, tracking:
- Token metadata
- Account balances
- Token approvals
- Market data
- Portfolio tracking
- Token popularity metrics
- Node.js (v16 or later)
- PNPM or NPM
- Graph CLI (
pnpm install -g @graphprotocol/graph-cli
)
# Install dependencies
pnpm install
# Generate AssemblyScript types from subgraph schema and ABIs
graph codegen
# Build the subgraph
graph build
For custom chains like Sonic, running your own Graph Node is often the most direct approach:
-
Set up a Graph Node connected to a Sonic RPC:
graph-node: environment: - ethereum=mainnet:https://eth-mainnet.alchemyapi.io/v2/your-api-key - sonic:146:https://rpc.soniclabs.com
-
Deploy to your Graph Node:
graph create --node http://localhost:8020/ sonic-erc20-subgraph graph deploy --node http://localhost:8020/ --ipfs http://localhost:5001 sonic-erc20-subgraph
While The Graph's hosted service doesn't directly support Sonic yet, you can request support:
- Submit a request to The Graph team to add Sonic chain support
- Once supported, deploy using:
graph auth --product hosted-service <YOUR_DEPLOY_KEY> graph deploy --product hosted-service <YOUR_GITHUB_USER>/<SUBGRAPH_NAME>
Alchemy Subgraphs supports Sonic chain with network name sonic-mainnet
:
- Create a new subgraph in the Alchemy Dashboard
- Deploy using:
graph deploy your-subgraph-name \ --version-label v0.1.0 \ --node https://subgraphs.alchemy.com/api/subgraphs/deploy \ --deploy-key <YOUR_DEPLOY_KEY> \ --ipfs https://ipfs.satsuma.xyz
Important: Make sure to use network: sonic-mainnet
in your subgraph.yaml file
The schema includes the following entities:
Token
: ERC20 token with metadata, popularity metricsAccount
: User/wallet addressesTokenBalance
: Links tokens to accounts with balanceApproval
: Token spending permissionsPortfolio
: User's token collection per chainMarketData
: Price and market informationProject
: Additional metadata for display
Example GraphQL queries:
# Get top tokens by holder count
{
tokens(first: 10, orderBy: holderCount, orderDirection: desc) {
id
name
symbol
holderCount
transactionCount
transferVolume
}
}
# Get token balances for a specific account
{
account(id: "0x...") {
tokenBalances {
token {
name
symbol
}
quantity
}
}
}
- Adjust start block in
subgraph.yaml
for different indexing starting points - Modify event handlers in
src/mappings/erc20.ts
to capture additional data
This subgraph is specifically configured for the Sonic blockchain (chain ID 146). The RPC endpoints in the mapping code are configured to access the Sonic network.
This project is open source and available under the MIT License.