Data access · 10 min read
How to stream Solana token transfers into ClickHouse
To stream Solana token transfers into ClickHouse, you read the SPL Token program's transfer instructions from a source that keeps inner instructions, work out which token each one moved, and write one row per transfer. Both steps have a trap. In 100 slots of Solana mainnet on December 1, 2026, 43% of USDC transfers were instructions that never name the USDC mint, and 92% ran inside another program's call. This guide builds the pipeline with the Pipes SDK against the public SQD Portal, and every output on the page is pasted from that run.
1. Where a USDC transfer is recorded on Solana
A token transfer on Solana is an instruction to the SPL Token program, not an event a contract emits. USDC uses the original Token program, Toke…Q5DA, and its mint is EPjF…Dt1v, the address Circle lists on its USDC contract addresses page. Two instructions move tokens between accounts, and the program's instruction definitions give them different account lists:
The missing mint is the first trap. A filter on the mint address catches every transferChecked and no plain transfer, and in this guide's window plain transfers were 4,002 of the 9,303 USDC transfers, 43.0%. Both accounts in a plain transfer are token accounts of one mint, so the mint can be recovered from the token balance records the transaction left behind, which is what the indexer below does.
The second trap is depth. Most transfers are not instructions the user signed directly; they are inner instructions that a swap router, an AMM or a wallet program issued during its own execution (a cross-program invocation, or CPI). In the same window 8,537 of the 9,303 transfers, 91.8%, were inner instructions. A pipeline that reads only the top-level instructions of each transaction sees fewer than one transfer in ten.
2. Set up the project and ClickHouse
The project needs three packages and a ClickHouse server. The SDK version is pinned to 1.0.0-beta.12, the npm latest tag on December 1, 2026; the SDK is in beta, so check export names against the installed package if you are on a later version. bs58 decodes the instruction data, which the Portal returns base58-encoded. ClickHouse runs in Docker:
The Portal endpoint needs no API key. Node 22.18 or later runs the TypeScript file below directly; on an older Node, run it with npx tsx index.ts instead.
3. The indexer, in one file
The whole indexer is a query, a transform and a target. Save it as index.ts; it is the exact file that produced every output on this page.
The query has two instruction requests because the two instructions need different filters. For transferChecked the Portal filters on the mint itself: a1 matches the instruction's second account, which is the mint. Plain transfer cannot be narrowed that way, so the second request takes every plain transfer of every token and asks for the transaction's token balances alongside (transactionTokenBalances: true). isCommitted: true drops instructions from failed transactions. The Portal returns inner instructions like any other, with an instructionAddress such as [3, 0, 1] that places each one in the call tree.
The transform decides the mint and decodes the amount. A plain transfer's mint comes from the token balance record of its source account, or of its destination when the source has none; anything that does not resolve to USDC is dropped. That discards most of what the second request returns: the window had 11,194 plain transfers across at least 330 mints, and 4,002 of them were USDC. The amount is the eight bytes after the first, read as an unsigned little-endian integer and kept in base units, so 1 USDC is 1,000,000 (USDC has six decimals). The owner columns come from the same balance records, because a token account is not a wallet: from_owner and to_owner are the wallets that own the two token accounts.
The target creates a CollapsingMergeTree table and inserts each batch. On a chain reorganization, or on a restart after a crash, the SDK calls onRollback, and store.removeRowsAfter cancels the rows above the last safe slot by inserting copies with sign = -1. Queries therefore aggregate sum(sign) rather than count(), which keeps them correct before ClickHouse merges the pairs away. The target also creates a sync table and saves the stream's position there, keyed by the id.
4. Run it
Run the script with the password you gave the container. The terminal output below is verbatim; log times are the machine's local clock (UTC+1):
The process exited about a second after it started. The public Portal sheds load when it is busy, and other runs of the same script met that on their first request: the Portal answered 529 with overloaded, the SDK's HTTP client logged a warning, waited ten seconds and retried on its own until a request succeeded. Expect either. Running it again with the same id resumes from the saved position instead of re-reading the window, and adds no rows:
5. Query the table
A first query confirms the window is complete. Open a client with docker exec -it clickhouse clickhouse-client --password secret and run:
The table has 9,303 USDC transfers from 5,326 transactions, about 1.7 per transaction, in every one of the window's 100 slots, which span 22 seconds of block time. The 3.77M USDC figure is a sum of transfer amounts, not settlement volume: a swap routed through two pools moves the same dollars more than once, and each hop is a row.
The first row the table returns, ordered by slot, signature and instruction position, is a top-level transferChecked:
Transaction 27yo…ArSw in slot 476,200,000 moved 66.516033 USDC from a token account owned by 5yfB…T8g3 to one owned by AYuD…fVQx. Solana's own RPC agrees: getTransaction on the public mainnet endpoint lists the same instruction at top-level index 4, type transferChecked, amount 66516033 with 6 decimals, and a block time of 14:30:41 UTC.
Splitting the table by instruction type and call depth shows both traps from the first section in one result:
Only 766 of the 9,303 transfers, 8.2%, were top-level instructions. An indexer that kept top-level transferChecked alone, the easiest pair of filters to write, would have stored 611 rows, 6.6% of the table.
6. Why the usual RPC route misses transfers
The standard JSON-RPC way to list a token's transactions cannot return the plain transfers whose transaction never mentions the mint. That route is getSignaturesForAddress on the mint, which by its documented definition returns signatures of transactions that reference the address in their account keys, at most 1,000 per call. A transaction can move USDC without the mint in its account keys at all. To count those, the measurement re-ran the query with the account key fields added:
Of the 5,326 transactions that moved USDC in the window, 705, or 13.2%, named the mint neither in their account keys nor in their address lookup tables. The first of them is v12N…2omK, also in slot 476,200,000: its 21 account keys, with no lookup table, do not include the mint, yet an Orca Whirlpool swap inside it issued an inner transfer of 34.907175 USDC at instruction address 3.0.1. The RPC's own token balances for that transaction show the source account down and the destination account up by the same 34.907175.
The live endpoint behaves as documented. The request below pages back from a transaction in slot 476,200,002, and one 1,000-signature page reaches slot 476,199,997, so it covers slot 476,200,000 completely:
The ten transactions the RPC did not return are exactly the ten in that slot whose account keys do not name the mint, including the Whirlpool swap above. The first-row transaction from the previous section, which does name it, is in the RPC's list. The 156 extra signatures reference the mint without a committed USDC transfer in the table; an RPC indexer has to fetch each of them with getTransaction to find that out.
The complete RPC route is getBlock on every slot, which returns every transaction with its inner instructions, followed by decoding all of them yourself. At the 0.214 seconds per slot measured between slots 475,000,000 and 476,000,000, that is about 404,000 full blocks a day, with the mint resolution and the depth handling still left to write. The Portal applies the program and discriminator filters, and the mint filter for transferChecked, before anything leaves the server and returns inner instructions with their position in the call tree, so the indexer receives the candidate instructions and their balance records in a single stream.
7. What the table leaves out, and what a backfill costs
The 9,303 is a floor. Of the 11,194 plain transfers of any token in the window, 81 had no balance record for either account, so the script cannot tell which mint they moved and drops them. Solana's RPC shows no token balances for the one checked, either. If every one of them were USDC, the count would rise by at most 81, 0.9%.
The table counts transfers between token accounts and nothing else. Circle's mints and burns are separate instructions (mintTo, burn and their checked forms) and are not in it. The authority column is whoever signed for the source account, which can be a delegate rather than the owner. The owner columns are empty on 28 rows (from_owner) and 20 rows (to_owner), where the matching balance record was missing.
Data volume decides how far back the free endpoint can go. The 100-slot window, about 22 seconds of chain time, pulled 18.1 MB of uncompressed response from the Portal, 181 KB a slot. A wider 500-slot window run the same day averaged 126 KB a slot. Most of the plain transfers in each response are not USDC and get discarded (7,111 of 11,194 in the 100-slot window belong to other tokens, and 81 more have no balance record), because that request cannot be narrowed by mint. At 126 to 181 KB a slot and about 404,000 slots a day, one day of USDC transfer data is roughly 51 to 73 GB.
The public Portal is an exploration endpoint, and the published plans put its allowance at about 50 MB a month, under 400 slots of this workload, which is less than a minute and a half of Solana. A backfill of more than a few hours needs a paid plan: Starter's 25 GB a month covers roughly 8 to 12 hours of this data and Growth's 400 GB roughly 5 to 8 days. Past a plan's allowance the backfill slows rather than stops, and Enterprise has no cap. Billing is not live yet, and the Public Portal keeps today's limits until it starts; the machine-readable version of the plans is at sqd.dev/pricing.md.
Frequently asked questions
How do I stream Solana token transfers into ClickHouse?
Why not filter USDC transfers by the mint address?
Does this work for other SPL tokens?
How do I keep the pipeline running at the chain head?
Can I backfill months of Solana history on the free Portal endpoint?
Related guides
Blockchain data API: the four kinds, and how to query one
The four kinds of blockchain data API and what each is for, then a working query: one request against a public dataset, the same thing in dependency-free Python, and the continuation loop a full day of history needs.
RPC vs indexed data: which do you actually need?
When an RPC endpoint is enough, when you need an indexer, and the costs of each.
Stablecoin data: tracking cross-chain flows and peg health
Following stablecoin transfers across every chain they live on with one query model, aligning windows across chains by timestamp, and reading peg health from DEX trades.
Tracking stablecoin flows?
See how teams follow issuance and transfers across chains on the stablecoins solution page.