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.

Updated 2026-12-01 · By the SQD team

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:

Instruction First byte Accounts, in order Names the mint
transfer 0x03 source, destination, owner or delegate No
transferChecked 0x0c source, mint, destination, owner or delegate Yes, account 1
The two SPL Token instructions that move tokens. The first byte of the instruction data identifies each one; the amount follows as a little-endian u64.

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:

your terminal
mkdir usdc-transfers && cd usdc-transfers
npm init -y && npm pkg set type=module
npm install @subsquid/pipes@1.0.0-beta.12 @clickhouse/client bs58
docker run -d --name clickhouse -p 8123:8123 \
-e CLICKHOUSE_PASSWORD=secret clickhouse/clickhouse-server:25.8

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.

index.ts
import { createClient } from '@clickhouse/client'
import { solanaPortalStream, solanaQuery } from '@subsquid/pipes/solana'
import { clickhouseTarget } from '@subsquid/pipes/targets/clickhouse'
import bs58 from 'bs58'
const TOKEN_PROGRAM = 'TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA'
const USDC = 'EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v' // Circle's USDC mint
const FROM = 476_200_000
const TO = 476_200_099 // 100 slots, inclusive
const query = solanaQuery()
.addFields({
block: { number: true, timestamp: true },
transaction: { transactionIndex: true, signatures: true },
instruction: {
transactionIndex: true, instructionAddress: true,
programId: true, accounts: true, data: true,
},
tokenBalance: {
transactionIndex: true, account: true,
preMint: true, postMint: true, preOwner: true, postOwner: true,
},
})
// transferChecked (d1 = 0x0c) names the mint as account 1, so the
// Portal can filter it to USDC for us.
.addInstructionRequest({
range: { from: FROM, to: TO },
request: {
programId: [TOKEN_PROGRAM], d1: ['0x0c'], a1: [USDC],
isCommitted: true, transaction: true, transactionTokenBalances: true,
},
})
// transfer (d1 = 0x03) does not name the mint at all. Take every one
// and resolve the mint from the transaction's token balances below.
.addInstructionRequest({
range: { from: FROM, to: TO },
request: {
programId: [TOKEN_PROGRAM], d1: ['0x03'],
isCommitted: true, transaction: true, transactionTokenBalances: true,
},
})
const stream = solanaPortalStream({
id: 'usdc-transfers', // cursor key; keep it stable across restarts
portal: 'https://portal.sqd.dev/datasets/solana-mainnet',
outputs: query,
}).pipe((blocks) => {
const rows = []
for (const block of blocks) {
const sigs = new Map(block.transactions.map((t) => [t.transactionIndex, t.signatures[0]]))
const balances = new Map(
block.tokenBalances.map((b) => [`${b.transactionIndex}:${b.account}`, b]),
)
const balance = (tx: number, account: string) => balances.get(`${tx}:${account}`)
for (const ins of block.instructions) {
const data = bs58.decode(ins.data)
const checked = data[0] === 0x0c
const [source, a1, a2, a3] = ins.accounts
const destination = checked ? a2 : a1
const authority = checked ? a3 : a2
const src = balance(ins.transactionIndex, source)
const dst = balance(ins.transactionIndex, destination)
// Both sides of a transfer hold the same mint. Some transactions have
// no balance record for the source account, so fall back to the
// destination's.
const mint = checked ? a1 : (src?.preMint ?? src?.postMint ?? dst?.preMint ?? dst?.postMint)
if (mint !== USDC) continue
rows.push({
slot: block.header.number,
timestamp: block.header.timestamp, // unix seconds
signature: sigs.get(ins.transactionIndex),
instruction_address: ins.instructionAddress.join('.'),
kind: checked ? 'transferChecked' : 'transfer',
source,
destination,
authority,
from_owner: src?.preOwner ?? src?.postOwner ?? '',
to_owner: dst?.postOwner ?? dst?.preOwner ?? '',
amount: new DataView(data.buffer, data.byteOffset).getBigUint64(1, true).toString(),
})
}
}
return rows
})
await stream.pipeTo(
clickhouseTarget({
client: createClient({
url: process.env.CLICKHOUSE_URL ?? 'http://localhost:8123',
password: process.env.CLICKHOUSE_PASSWORD ?? '',
}),
onStart: async ({ store }) => {
await store.command({
query: `
CREATE TABLE IF NOT EXISTS usdc_transfers (
slot UInt64,
timestamp DateTime('UTC'),
signature String,
instruction_address String,
kind LowCardinality(String),
source String,
destination String,
authority String,
from_owner String,
to_owner String,
amount UInt64,
sign Int8 DEFAULT 1
) ENGINE = CollapsingMergeTree(sign)
ORDER BY (slot, signature, instruction_address)`,
})
},
onData: async ({ data, store }) => {
if (data.length) {
await store.insert({ table: 'usdc_transfers', values: data, format: 'JSONEachRow' })
}
},
onRollback: async ({ safeCursor, store }) => {
await store.removeRowsAfter(safeCursor, { tables: ['usdc_transfers'], column: 'slot' })
},
}),
)

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):

your terminal
$ CLICKHOUSE_PASSWORD=secret node index.ts
[15:40:54.599] INFO: usdc-transfers Start indexing from 476,200,000 block

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:

your terminal
$ CLICKHOUSE_PASSWORD=secret node index.ts
[15:40:55.844] INFO: usdc-transfers Resuming indexing from 476,200,099 block

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:

SELECT sum(sign) AS transfers,
uniqExact(signature) AS transactions,
min(slot), max(slot),
min(timestamp), max(timestamp),
round(sum(sign * amount) / 1e6, 2) AS usdc_summed
FROM usdc_transfers FINAL
FORMAT Vertical
clickhouse-client
Row 1:
──────
transfers: 9303
transactions: 5326
min(slot): 476200000 -- 476.20 million
max(slot): 476200099 -- 476.20 million
min(timestamp): 2026-12-01 14:30:41
max(timestamp): 2026-12-01 14:31:03
usdc_summed: 3768347.92 -- 3.77 million

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:

SELECT slot, timestamp, signature, instruction_address, kind,
from_owner, to_owner, amount / 1e6 AS usdc
FROM usdc_transfers FINAL
ORDER BY slot, signature, instruction_address
LIMIT 1
FORMAT Vertical
clickhouse-client
Row 1:
──────
slot: 476200000 -- 476.20 million
timestamp: 2026-12-01 14:30:41
signature: 27yoPpWBWpcPuYvUERAPw6pxkxhGLvC7fV2rfot4vwvTMBRwuMBHko6y6Vw8xY1tfPgMEQLQ96jPDpA8KZbjArSw
instruction_address: 4
kind: transferChecked
from_owner: 5yfBpHixxqkZVajyb477MPHiDzCjmYFFhLxFBFo7T8g3
to_owner: AYuDFzJ3juk9pyNP5RiSVNJqRhLdcRtdQYfAxPBSfVQx
usdc: 66.516033

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:

SELECT kind,
sumIf(sign, instruction_address NOT LIKE '%.%') AS top_level,
sumIf(sign, instruction_address LIKE '%.%') AS inner_cpi,
sum(sign) AS transfers
FROM usdc_transfers
GROUP BY kind
ORDER BY transfers DESC
kind top_level inner_cpi transfers
transferChecked 611 4690 5301
transfer 155 3847 4002
USDC transfers by instruction and call depth, solana-mainnet slots 476,200,000 to 476,200,099 (2026-12-01, 14:30:41 to 14:31:03 UTC).

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:

// Same query, with two more transaction fields:
transaction: { transactionIndex: true, signatures: true,
accountKeys: true, loadedAddresses: true },
// Then, per transaction that moved USDC:
const keys = [
...tx.accountKeys,
...(tx.loadedAddresses?.writable ?? []),
...(tx.loadedAddresses?.readonly ?? []),
]
const namesTheMint = keys.includes(USDC)

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:

your terminal
curl -s https://api.mainnet-beta.solana.com \
-H 'content-type: application/json' \
-d '{"jsonrpc":"2.0","id":1,"method":"getSignaturesForAddress",
"params":["EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v",
{"before":"22DkZmqw5gKHnoctvpBVYPTGsLEM5knE6aXzydw8eP5S8mGpSaWWiJn9smnVy1RaPc8tp3PwgUe4kmJBxowUbZN2",
"limit":1000}]}'
Set Transactions
Moved USDC (ClickHouse table) 77
Returned by getSignaturesForAddress for the mint 223
In both 67
In the table only 10
Returned by the RPC only 156
Slot 476,200,000: transactions in the ClickHouse table compared with signatures getSignaturesForAddress returned for the USDC mint, checked 2026-12-01.

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?
Read the SPL Token program's transfer (first byte 0x03) and transferChecked (0x0c) instructions from a source that includes inner instructions, resolve the mint of each one, and write a row per transfer. With the Pipes SDK that is one TypeScript file: solanaQuery() declares the two instruction requests, solanaPortalStream() reads them from the SQD Portal, a .pipe() step decodes the amount and resolves the mint from the transaction's token balances, and clickhouseTarget() writes the rows and keeps a resumable cursor in ClickHouse.
Why not filter USDC transfers by the mint address?
Only transferChecked names the mint. A plain transfer instruction lists the source account, the destination account and the authority, and nothing else, so a filter on the mint account misses it. In the 100-slot window measured here, plain transfers were 4,002 of 9,303 USDC transfers (43.0%). The mint has to be resolved from the token accounts, which this guide does with the transaction's token balance records.
Does this work for other SPL tokens?
Yes for tokens on the original Token program: change the USDC constant to the other mint. Tokens created under Token-2022 are owned by a different program, TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb, which uses the same first bytes for transfer and transferChecked, so add it to programId. Token-2022 extensions add transfer paths this script does not decode, so check the mint's extensions before trusting the count.
How do I keep the pipeline running at the chain head?
Remove the to bound from both instruction requests. The stream then catches up to the head and keeps following it, and the target saves its position in a sync table in ClickHouse after each batch, so a restart with the same id resumes where it stopped. To rebuild from scratch, drop usdc_transfers and sync, or change the id.
Can I backfill months of Solana history on the free Portal endpoint?
No. The public endpoint is for exploration and returns 529 overloaded under load. This guide's 100-slot window, about 22 seconds of chain time, pulled 18.1 MB uncompressed. At the rates measured here a day of USDC transfer data is roughly 51 to 73 GB, and a backfill of more than a few hours is a paid-plan job. See the pricing page for the plans and their monthly data allowances.

Related guides

Tracking stablecoin flows?

See how teams follow issuance and transfers across chains on the stablecoins solution page.