A comprehensive Substreams module for extracting and analyzing Solana SPL token data, specifically designed for tracking Mint, Burn, Transfer, and InitializeAccount operations. This project provides a complete data pipeline from Solana blockchain to ClickHouse database with pre-built materialized views for analytics.
This Substreams extracts SPL token events from the Solana blockchain and stores them in a ClickHouse database for analysis. It's particularly useful for:
git clone https://github.com/streamingfast/substreams-spl-token.git
cd substreams-spl-token
# Start ClickHouse database
make db-up
This will:
localhost:8123
(HTTP) and localhost:9000
(native)spl2
databasesubstreams build
# Consume a subset of the chain just for demonstration purposes
substreams-sink-sql from-proto clickhouse://default:@localhost:9000/spl2 ./solana-spl-token-v0.1.0.spkg -s 356312000 -t +10000
# Apply views using the db-query command
docker exec -i spl-token-clickhouse clickhouse-client --database spl2 --multiquery < views.sql
# Open ClickHouse client and enter query there (SELECT count() FROM mints)
make db-shell
# Or run example queries
make db-query QUERY="SELECT count() FROM mints"
The pipeline creates the following tables in ClickHouse:
mints
: Token mint operationsburns
: Token burn operationstransfers
: Token transfer operationsinitialized_accounts
: Account initialization eventsinstructions
: Instruction metadata_blocks_
: Block informationmv_all_mints
: Enhanced mint data with account owner informationmv_all_burns
: Enhanced burn data with account owner informationmv_mint_per_month
: Monthly mint aggregationsmv_burn_per_month
: Monthly burn aggregationsmv_supply
: Current total supply calculationEdit the substreams.yaml
file to track a different SPL token:
params:
map_spl_instructions: "spl_token_address=YOUR_TOKEN_ADDRESS|spl_token_decimal=DECIMALS"
solana_common:transactions_by_programid_and_account_without_votes: "program:TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA && account:YOUR_TOKEN_ADDRESS"
See example-queries.md for comprehensive query examples. Here are a few quick ones:
SELECT * FROM spl2.mv_supply;
SELECT
block_time,
to_derive_address,
amount / 1000000000 as tokens_minted
FROM spl2.mv_all_mints
ORDER BY block_number DESC
LIMIT 10;
SELECT
m.month,
m.total / 1000000000 as tokens_minted,
COALESCE(b.total, 0) / 1000000000 as tokens_burned,
(m.total - COALESCE(b.total, 0)) / 1000000000 as net_change
FROM spl2.mv_mint_per_month m
LEFT JOIN spl2.mv_burn_per_month b ON m.month = b.month
ORDER BY m.month DESC;
# Database management
make db-up # Start ClickHouse
make db-down # Stop ClickHouse
make db-setup # Initialize database
make db-shell # Open database shell
make db-reset # Reset database (removes all data)
The substreams-sink-sql
tool is required to stream data from Substreams to ClickHouse.
Option 1: Download Pre-built Binary
# Download from GitHub releases
curl -L https://github.com/streamingfast/substreams-sink-sql/releases/latest/download/substreams-sink-sql-$(uname -s | tr '[:upper:]' '[:lower:]')-$(uname -m).tar.gz | tar -xz
sudo mv substreams-sink-sql /usr/local/bin/
Option 2: Build from Source
git clone https://github.com/streamingfast/substreams-sink-sql.git
cd substreams-sink-sql
go build -o substreams-sink-sql ./cmd/substreams-sink-sql
For detailed installation instructions, see the official documentation.
# View ClickHouse logs
make db-logs
# Check if data is flowing
docker exec -it spl-token-clickhouse clickhouse-client --database spl2 --query "
SELECT
'mints' as table_name,
count() as row_count,
max(block_number) as latest_block
FROM spl2.mints
"
Database Connection Issues:
docker-compose ps
make db-logs
netstat -ln | grep 8123
No Data Flowing:
Performance Issues:
Solana Blockchain
↓
Substreams
(Rust WASM)
↓
substreams-sink-sql
↓
ClickHouse
(Tables + Views)
↓
Analytics & Queries
This project is licensed under the Apache License 2.0 - see the LICENSE file for details.
substreams gui solana-spl-token@v0.1.2 map_spl_instructions
substreams gui solana-spl-token@v0.1.2 solana_common:blocks_without_votes
substreams gui solana-spl-token@v0.1.2 solana_common:transactions_by_programid_and_account_without_votes
substreams gui solana-spl-token@v0.1.2 solana_common:program_ids_and_accounts_without_votes