Skip to main content
See the Handling program instructions guide for usage examples and ABI generation. Returns a query-transformer combo that instructs the source to fetch and decode Solana program instructions.
Parameters:
  • range: Slot range { from: number | string | 'latest', to?: number } (required)
  • program: The program the instructions belong to, usually its typegen module with programId and instructions (required). The decoder reads one address, program.programId. Every entry in instructions must be one of program.instructions.
  • programId: Deprecated, use program. Program address(es) string | string[], accepted in place of program. The decoder then checks discriminators only, so an instruction from another program with the same discriminator can decode under the wrong key.
  • instructions: Map of instruction names to ABI instruction objects (required)
  • profiler: Profiler config shard that’ll be used for labeling the transformer in profiling data { name: string } (optional)
  • onError: Error handler (ctx: BatchContext, error: any) => unknown | Promise<unknown> (optional)
Example:

Decoded instruction structure

Each entry in the output arrays is a DecodedInstruction object:

Instruction discriminators

Instructions are filtered by discriminators (prefix bytes of instruction data). The discriminator name indicates how many leading bytes of the instruction data it covers: The decoder automatically extracts the appropriate discriminator from the ABI instruction definition.

Multiple programs

A decoder covers one program. Anchor derives an instruction’s discriminator from its name alone, so two programs that each have a swap share a discriminator, and one decoder could not tell them apart. Give each program its own decoder and pass both as outputs:
To decode the same program deployed at another address, pass a copy of the module with that address: program: { ...orcaWhirlpool, programId: '<address>' }. The decoder checks this when it starts. An instruction that is not one of program.instructions, a program with an empty address, an instruction with no discriminator or more than one, discriminators of mixed widths, or two instructions that share a discriminator fail with E0003.

Error handling

Handle decoding errors: