Canonical: https://solanashreds.xyz/learn/anchor-discriminators

# The 8-byte Anchor discriminator, explained for decoders

An Anchor instruction discriminator is the first 8 bytes of a hash of the instruction name. Compute and match it, with account and event versions.

An Anchor instruction discriminator is the first eight bytes of the SHA-256 hash of the text `global:` followed by the instruction's name in snake_case. Anchor puts those eight bytes at the start of the instruction data, so a decoder compares them against the program's list to learn which instruction it holds, then reads the arguments that follow.

## Instruction discriminators

Anchor builds every discriminator the same way: hash a namespace, a colon and a name, then keep the first eight bytes. For instructions the namespace is `global` and the name is the Rust function name, which is snake_case. The instruction `buy` therefore starts with `sha256("global:buy")[0..8]`.

Two details trip people up. The name is snake_case even when a client library shows it in camelCase, so `createV2` in TypeScript hashes as `create_v2`. And the bytes are taken from the start of the digest in order; nothing is reversed or read as an integer.

## Three real discriminators, computed and checked

Each value below was computed from its preimage and compared with the program's published IDL.

| Kind | Preimage | First 8 bytes (hex) | Published IDL |
| --- | --- | --- | --- |
| Instruction, Pump.fun `buy` | `global:buy` | `66063d1201daebea` | matches pump-public-docs 639b87f |
| Account, Pump.fun `BondingCurve` | `account:BondingCurve` | `17b7f83760d8ac60` | matches |
| Event, Pump.fun `TradeEvent` | `event:TradeEvent` | `bddb7fd34ee661ee` | matches |

All 56 instructions in that Pump.fun IDL follow the hash rule. The same check holds for every instruction in the current IDLs of PumpSwap, Raydium CPMM and CLMM, Orca Whirlpool and Meteora DLMM and DAMM v2.

## Account discriminators

Accounts that Anchor programs own start with their own eight-byte tag, made with the namespace `account` and the struct name as written, in PascalCase: `account:BondingCurve`. The program checks it before trusting an account's data.

A shred decoder rarely needs this, because transactions name accounts but do not carry their data. It matters when you fetch account state to go with a transaction: the tag tells you which struct layout to apply to the bytes you got back.

## Event discriminators and the emit_cpi tag

Events use the namespace `event` and the event's struct name: `event:TradeEvent`. With `emit!`, the program writes those eight bytes and the event's fields to the log, base64 encoded on a `Program data:` line.

With `emit_cpi!`, the program calls itself, and the instruction data of that self-call starts with a fixed tag, `0x1d9acb512ea545e4`, stored little-endian as the bytes `e4 45 a5 2e 51 cb 9a 1d`, followed by the event discriminator and the fields. Both forms are produced at run time, so neither appears in a raw transaction. [Inner instructions and CPIs](https://solanashreds.xyz/learn/inner-instructions-and-cpi) explains why.

## Custom discriminators in newer Anchor

Since Anchor 0.31.0 a program may choose its own discriminator for an instruction, account or event instead of the hash, and it can be shorter than eight bytes. Programs do use this. Jupiter v6's on-chain IDL lists 21 instructions, and one of them, `create_idempotent_associated_token_account`, carries `5368c096b4479cc6` where the hash rule would give `bdbcecfa3cff996f`.

The rule for a decoder follows directly: read discriminators from the IDL when it lists them, and compute the hash only when it does not. Older IDLs, such as the copy in Jupiter's CPI repository, list no discriminators at all, which is when computing them is the only option. [Reading an IDL](https://solanashreds.xyz/learn/reading-an-idl) shows where each field lives.

## Matching discriminators in a shred decoder

From shreds you get each instruction as raw bytes with no name attached. The discriminator is the cheapest possible test of what it is: build a map from eight-byte values to instruction definitions once, at startup, for each program you care about, then look up the first eight bytes of every instruction whose program you recognise. One lookup per instruction, and no parsing of anything you are not interested in.

The match also tells you how to read the rest, because each instruction's arguments follow in [Borsh](https://solanashreds.xyz/learn/borsh-encoding). A worked decoder is in [decoding Anchor instructions](https://solanashreds.xyz/docs/decode/anchor-instructions).

## Questions about discriminators

### Why eight bytes and not one?

Eight bytes of a hash make accidental collisions between instruction names practically impossible, without any registry of numbers. Programs that are not built with Anchor often use a single tag byte instead; [instruction data](https://solanashreds.xyz/learn/compiled-instructions) covers those layouts.

### Is the discriminator the same across program upgrades?

As long as the instruction keeps its name and no custom value is set, yes. A rename or a new custom discriminator changes it, which is one way [IDL drift](https://solanashreds.xyz/blog/idl-drift) breaks decoders.

### Can two programs share a discriminator?

Yes. `global:initialize` hashes to the same eight bytes in every program that has an `initialize` instruction. Always check the program ID first, then the discriminator.

## What a discriminator match does not prove

A match tells you which instruction the sender asked for, and nothing about whether it ran. The instruction can still fail, or its arguments can be malformed: when a program adds a new argument, older clients keep sending the shorter form, and in our mainnet sample one Pump.fun `buy` arrived without its two newest optional arguments, while 13 `buy_exact_quote_in_v3` calls left out the newest one. Decode defensively and treat the result as a request until you reconcile it.

## Put discriminators to work

The [Anchor decoding guide](https://solanashreds.xyz/docs/decode/anchor-instructions) turns this into an IDL-driven decoder, the [Pump.fun recipe](https://solanashreds.xyz/docs/programs/pump-fun) applies it to one program, and the [shred decoder documentation](https://solanashreds.xyz/docs) has the rest. Pump.fun discriminators against live traffic start with [a first decode](https://solanashreds.xyz/docs/quickstart).
