Skip to main content

Documentation Index

Fetch the complete documentation index at: https://beta.docs.sqd.dev/llms.txt

Use this file to discover all available pages before exploring further.

SolanaQueryBuilder assembles a typed portal query from a field selection and one or more data-request clauses. Pass .build() to outputs (or to .pipe()) on a Solana source. The resulting object is consumed by solanaPortalStream() and by the solanaInstructionDecoder which composes on top of it.

solanaQuery()

Returns a fresh SolanaQueryBuilder.
import { solanaQuery } from '@subsquid/pipes/solana'

const query = solanaQuery()
  .addFields({
    block: { number: true, timestamp: true },
    instruction: { programId: true, data: true, accounts: true },
  })
  .addInstruction({
    range: { from: 200_000_000 },
    request: {
      programId: ['whirLbMiicVdio4qvUfM5KAg6Ct8VwpYzGff3uctyCc'],
    },
  })
  .build()

SolanaQueryBuilder<F>

class SolanaQueryBuilder<F extends FieldSelection = {}> {
  addFields<T>(fields: Subset<T, FieldSelection>): SolanaQueryBuilder<F & T>
  addInstruction(options: RequestOptions<InstructionRequest>): this
  addTransaction(options: RequestOptions<TransactionRequest>): this
  addLog(options: RequestOptions<LogRequest>): this
  addBalance(options: RequestOptions<BalanceRequest>): this
  addTokenBalance(options: RequestOptions<TokenBalanceRequest>): this
  addReward(options: RequestOptions<RewardRequest>): this
  includeAllBlocks(range?: Range): this
  addRange(range: PortalRange): this
  merge(other?: SolanaQueryBuilder<F>): this
  build(opts?: { setupQuery?: SetupQueryFn<SolanaQueryBuilder<F>> }): QueryAwareTransformer
}
The generic parameter F narrows the block type produced by the stream — only fields explicitly selected with .addFields() appear on the decoded records, at both compile and runtime.

RequestOptions<R> and Range

type RequestOptions<R> = { range: PortalRange; request: R }
type PortalRange = { from?: number | string | 'latest' | Date; to?: number | string | Date }
type Range        = { from: number; to?: number }
PortalRange.from defaults to 0; a Date or numeric timestamp is resolved to a slot via the portal at query start. 'latest' is resolved to the current head. includeAllBlocks() accepts the stricter Range, so dates and 'latest' are not allowed there. In Solana, number identifies a slot. Slot and block height differ: skipped slots do not increment height.

.addFields(fields)

Add to the field selection. Repeated calls are merged recursively.

block

FieldType
numbernumber (slot; always returned)
hashstring (always returned)
heightnumber (block height, skips not counted)
parentNumbernumber
parentHashstring
timestampnumber (Unix seconds)

transaction

FieldType
transactionIndexnumber
version'legacy' | number
accountKeysstring[]
addressTableLookups{ accountKey, readonlyIndexes, writableIndexes }[]
numReadonlySignedAccountsnumber
numReadonlyUnsignedAccountsnumber
numRequiredSignaturesnumber
recentBlockhashstring
signaturesstring[]
errnull | object (error details, null on success)
computeUnitsConsumedbigint
feebigint (lamports)
loadedAddresses{ readonly: string[]; writable: string[] }?
hasDroppedLogMessagesboolean

instruction

FieldType
transactionIndexnumber
instructionAddressnumber[] (path in the call tree)
programIdstring
accountsstring[]
datastring
computeUnitsConsumedbigint?
errorunknown?
isCommittedboolean (false when the enclosing transaction failed)
hasDroppedLogMessagesboolean

log

FieldType
transactionIndexnumber
logIndexnumber
instructionAddressnumber[]
programIdstring
kind'log' | 'data' | 'other'
messagestring

balance

SOL balance change for one account within one transaction.
FieldType
transactionIndexnumber
accountstring
prebigint (lamports before)
postbigint (lamports after)

tokenBalance

SPL-token balance change. Records are a tagged union: some updates carry only pre* fields (token account removed), some only post* (token account created), and some both.
FieldType
transactionIndexnumber
accountstring (token account)
preProgramId, preMint, preDecimals, preOwner, preAmountbefore state
postProgramId, postMint, postDecimals, postOwner, postAmountafter state

reward

FieldType
pubkeystring
lamportsbigint
postBalancebigint
rewardTypestring? (fee, rent, voting, staking)
commissionnumber?

.addInstruction(options)

Filter instructions. List filters AND across fields; values within a field OR. Matches instructions anywhere in the call tree, not just top-level.
FieldTypeMeaning
programIdstring[]Program that executes the instruction.
d1, d2, d4, d8string[]First 1/2/4/8 bytes of data in 0x-prefixed hex — used as Anchor discriminators.
a0a9string[]Account at position 0..9 of the instruction’s account list.
isCommittedbooleanRestrict to committed (successful) instructions.
transactionbooleanAlso fetch the parent transaction.
transactionBalancesbooleanAlso fetch SOL balance updates for parent transactions.
transactionTokenBalancesbooleanAlso fetch token balance updates for parent transactions.
transactionInstructionsbooleanAlso fetch sibling instructions executed by the parent transaction.
innerInstructionsbooleanAlso fetch all inner instructions (entire subtrees) of matching instructions.
logsbooleanAlso fetch logs produced by matching instructions.
An empty request: {} matches every instruction in the range.
solanaQuery().addInstruction({
  range: { from: 200_000_000 },
  request: {
    programId: ['whirLbMiicVdio4qvUfM5KAg6Ct8VwpYzGff3uctyCc'],
    d8: ['0xf8c69e91e17587c8'], // 8-byte Anchor discriminator for Whirlpool `swap`
    isCommitted: true,
    innerInstructions: true,
  },
})
The portal accepts account-position filters up to a15 and a mentionsAccount filter that matches an account anywhere in the list. These are not exposed by the builder; use a raw query via portal.getStream() if you need them.

.addTransaction(options)

Filter transactions.
FieldTypeMeaning
feePayerstring[]Fee-payer account.
instructionsbooleanAlso fetch all instructions executed in matching transactions.
logsbooleanAlso fetch all logs produced by matching transactions.

.addLog(options)

Filter program log messages.
FieldTypeMeaning
programIdstring[]Program that produced the log.
kind('log' | 'data' | 'other')[]Log type.
transactionbooleanAlso fetch the parent transaction.
instructionbooleanAlso fetch the instruction the log was emitted from.

.addBalance(options)

Filter SOL balance updates.
FieldTypeMeaning
accountstring[]Account whose balance changed.
transactionbooleanAlso fetch the parent transaction.
transactionInstructionsbooleanAlso fetch all instructions of parent transactions.

.addTokenBalance(options)

Filter SPL-token balance updates.
FieldTypeMeaning
accountstring[]Token account.
preProgramId, postProgramIdstring[]Token program ID before / after.
preMint, postMintstring[]Mint before / after.
preOwner, postOwnerstring[]Owner before / after.
transactionbooleanAlso fetch the parent transaction.
transactionInstructionsbooleanAlso fetch all instructions of parent transactions.

.addReward(options)

Filter validator rewards.
FieldTypeMeaning
pubkeystring[]Validator public key.

.includeAllBlocks(range?)

Request every slot in range regardless of whether any other filter matches. Useful when you want uninterrupted timestamps or slot progression even across slots with no targeted activity. Without range, applies from slot 0 onward.
solanaQuery().includeAllBlocks({ from: 200_000_000, to: 200_001_000 })

.addRange(range)

Push a range-only request with no filters — typically used to bound a stream built from other sources.

.merge(other)

Merge another builder’s requests and fields in-place. Overlapping ranges are reconciled at build time.

.build(opts?)

Return a QueryAwareTransformer suitable for use as a source output.
solanaPortalStream({
  portal: 'https://portal.sqd.dev/datasets/solana-mainnet',
  outputs: { swaps: solanaQuery().addInstruction({/*…*/}).build() },
})
opts.setupQuery is an advanced hook called when the query is finalized: it receives { query, logger } and can mutate query (e.g. merge additional requests from runtime data). Default behaviour is to merge this into the stream’s root query.

See also