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.

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

evmQuery()

Returns a fresh EvmQueryBuilder.
import { evmQuery } from '@subsquid/pipes/evm'

const query = evmQuery()
  .addFields({
    block: { timestamp: true },
    log: { address: true, topics: true, data: true },
  })
  .addLog({
    range: { from: 20_000_000 },
    request: { topic0: ['0xddf252ad…'] },
  })
  .build()

EvmQueryBuilder<F>

class EvmQueryBuilder<F extends FieldSelection = {}> {
  addFields<T>(fields: Subset<T, FieldSelection>): EvmQueryBuilder<F & T>
  addLog(options: RequestOptions<LogRequest>): this
  addTransaction(options: RequestOptions<TransactionRequest>): this
  addTrace(options: RequestOptions<TraceRequest>): this
  addStateDiff(options: RequestOptions<StateDiffRequest>): this
  addRange(range: PortalRange): this
  merge(other?: EvmQueryBuilder<F>): this
  build(opts?: { setupQuery?: SetupQueryFn<EvmQueryBuilder<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>

type RequestOptions<R> = { range: PortalRange; request: R }
type PortalRange = { from?: number | string | 'latest' | Date; to?: number | string | Date }
PortalRange.from defaults to 0; a Date or numeric timestamp is resolved to a block number via the portal at query start. 'latest' is resolved to the current head.

.addFields(fields)

Add to the field selection. Repeated calls are merged recursively. Block hash and number are returned regardless of selection.

block

FieldType
numbernumber (always returned)
hashstring (always returned)
parentHashstring
timestampnumber (Unix seconds)
transactionsRootstring
receiptsRootstring
stateRootstring
logsBloomstring
sha3Unclesstring
extraDatastring
minerstring
noncestring
mixHashstring
sizenumber
gasLimitbigint
gasUsedbigint
difficultybigint
totalDifficultybigint?
baseFeePerGasbigint
blobGasUsedbigint
excessBlobGasbigint
l1BlockNumbernumber? (L2 only)

transaction

FieldType
transactionIndexnumber
hashstring
noncebigint
fromstring
tostring?
inputstring
valuebigint
gasbigint
gasPricebigint
maxFeePerGasbigint?
maxPriorityFeePerGasbigint?
v, r, s, yParitybigint/string/string/number?
chainIdnumber?
sighashstring? (first 4 bytes of input)
contractAddressstring? (for create transactions)
gasUsedbigint
cumulativeGasUsedbigint
effectiveGasPricebigint
typenumber
statusnumber (0 = fail, 1 = success)
blobVersionedHashesstring[]?
l1Fee, l1FeeScalar, l1GasPrice, l1GasUsed, l1BlobBaseFee, l1BlobBaseFeeScalar, l1BaseFeeScalarL2 fee metadata

log

FieldType
logIndexnumber
transactionIndexnumber
transactionHashstring
addressstring
datastring
topicsstring[]

trace

Trace records are a tagged union over type. Each type has its own action and (optionally) result sub-objects; the field selection is flat with create…/call…/suicide…/reward… prefixes. Shared:
FieldType
type'create' | 'call' | 'suicide' | 'reward'
transactionIndexnumber
traceAddressnumber[]
subtracesnumber
errorstring | null
revertReasonstring?
Type-specific (appears only on that trace type):
FieldAction/resultType
createFrom, createValue, createGas, createInitcreate actionstring / bigint / bigint / string
createResultGasUsed, createResultCode, createResultAddresscreate resultbigint / string? / string
callCallType, callFrom, callTo, callValue, callGas, callInput, callSighashcall actionstring / string / string / bigint? / bigint / string / string?
callResultGasUsed, callResultOutputcall resultbigint / string?
suicideAddress, suicideRefundAddress, suicideBalancesuicide actionstring / string / bigint
rewardAuthor, rewardValue, rewardTypereward actionstring / bigint / string

stateDiff

State diffs are a tagged union over kind ('+' = add, '-' = delete, '*' = change, '=' = no-change).
FieldType
transactionIndexnumber
addressstring
key'balance' | 'code' | 'nonce' | string (storage slot)
kind'+' | '-' | '*' | '='
prevstring (present for -, *)
nextstring (present for +, *)

.addLog(options)

Filter logs. All list filters AND across fields but OR within a field. Request options:
FieldTypeMeaning
addressstring[]Emitting contract addresses (lowercase).
topic0string[]First topic (typically the event signature hash).
topic1, topic2, topic3string[]Remaining indexed topics.
transactionbooleanAlso fetch the parent transaction of each matching log.
transactionTracesbooleanAlso fetch traces of parent transactions.
transactionLogsbooleanAlso fetch all logs from parent transactions.
transactionStateDiffsbooleanAlso fetch state diffs caused by parent transactions.
An empty request: {} matches every log in the range.
evmQuery().addLog({
  range: { from: 20_000_000, to: 20_000_100 },
  request: {
    address: ['0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48'],
    topic0: ['0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef'],
    transaction: true,
  },
})

.addTransaction(options)

Filter transactions.
FieldTypeMeaning
fromstring[]Sender addresses (lowercase).
tostring[]Recipient addresses (lowercase).
sighashstring[]First 4 bytes of input (e.g. 0xa9059cbb for ERC-20 transfer).
typenumber[]Transaction type (0 legacy, 2 EIP-1559, 3 blob, etc.).
logsbooleanAlso fetch emitted logs.
tracesbooleanAlso fetch execution traces.
stateDiffsbooleanAlso fetch state diffs.

.addTrace(options)

Filter execution traces.
FieldTypeMeaning
type('create' | 'call' | 'suicide' | 'reward')[]Restrict to given trace types.
createFromstring[]Creator address for create traces.
callFromstring[]Caller address for call traces.
callTostring[]Callee address for call traces.
callSighashstring[]input sighash for call traces.
suicideRefundAddressstring[]Refund address for suicide traces.
rewardAuthorstring[]Author of reward traces.
transactionbooleanFetch parent transactions of matching traces.
transactionLogsbooleanFetch all logs emitted by parent transactions.
subtracesbooleanFetch all subtraces of matching traces.
parentsbooleanFetch parent traces of matching traces.

.addStateDiff(options)

Filter storage diffs.
FieldTypeMeaning
addressstring[]Contract or account addresses (lowercase).
keystring[]Storage keys or pseudo-keys (balance, code, nonce).
kind('+' | '-' | '*' | '=')[]Type of change.
transactionbooleanFetch parent transactions.

.addRange(range)

Push a range-only request with no filters. Mostly useful to bound the stream or in combination with includeAllBlocks set elsewhere.
evmQuery().addRange({ from: 20_000_000, to: 20_001_000 })

.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.
evmPortalStream({
  portal: 'https://portal.sqd.dev/datasets/ethereum-mainnet',
  outputs: { transfers: evmQuery().addLog({/*…*/}).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