> ## Documentation Index
> Fetch the complete documentation index at: https://docs.sqd.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Instructions

> Track Solana instruction execution with addInstruction() — filter by program and discriminator.

<h4 id="add-instruction">
  `addInstruction(options)`
</h4>

This allows for tracking program instructions. `options` has the following structure:

```typescript theme={"system"}
{
  // data requests
  where?: {
    programId?: string[]

    d1?: string[]
    d2?: string[]
    d3?: string[]
    d4?: string[]
    d8?: string[]
    discriminator?: string[]

    a0?: string[]
    a1?: string[]
    a2?: string[]
    a3?: string[]
    a4?: string[]
    a5?: string[]
    a6?: string[]
    a7?: string[]
    a8?: string[]
    a9?: string[]

    isCommitted?: boolean
  }

  // related data retrieval
  include?: {
    transaction?: boolean
    transactionBalances?: boolean
    transactionTokenBalances?: boolean
    transactionInstructions?: boolean
    logs?: boolean
    innerInstructions?: boolean
  }

  range?: {
    from: number
    to?: number
  }
}
```

The data requests here are:

* `programId`: the set of program addresses to track. Leave undefined to subscribe to instructions data of all programs from the whole network.
* `d1` through `d8`: sets of 1, 2, 3, 4 and 8-byte instruction discriminators, correspondingly. Discriminators are `0x`-prefixed hexadecimal prefixes of instruction data; each `dN` filter requires exactly that many bytes.
* `discriminator`: a set of instruction data prefixes of any length, `0x`-prefixed hexadecimal.
* `a0` through `a9`: sets of base58-encoded account inputs to the instruction, at positions 0-9 correspondingly.
* `isCommitted`: `true` to request only instructions that did not revert.

Related data retrieval flags:

* `transaction = true`: retrieve the transaction that gave rise to instruction
* `transactionBalances = true`: retrieve all SOL balance records of the parent transaction
* `transactionTokenBalances = true`: retrieve all token balance records of the parent transaction
* `transactionInstructions = true`: retrieve all instructions executed by the parent transaction
* `logs = true`: retrieve all logs emitted due to the instruction
* `innerInstructions = true`: retrieve the data for all instruction calls due to the matching instruction

The related data will be added to the appropriate iterables within the [block data](./context-interfaces). You can also call `augmentBlock()` from `@subsquid/solana-objects` on the block data to populate the convenience reference fields like `instruction.inner`.

Selection of the exact fields to be retrieved for each instruction item and the related data is done with the `setFields()` method documented on the [Field selection](./field-selection) page.

<Tip>
  To decode instructions, generate typed helpers with [Solana typegen](../solana-typegen). `@subsquid/solana-stream` also exports the `getInstructionData()` and `getInstructionDescriptor()` utilities for working with raw instruction data.
</Tip>
