Solana IDL reference › How to find memcmp offsets for getProgramAccounts

How to find memcmp offsets for getProgramAccounts

getProgramAccounts returns every account owned by a program. A memcmp filter keeps only accounts whose data has the given bytes at a given offset, and dataSize keeps only accounts of an exact length. Both need the byte layout of the account.

1. Start with the discriminator

Anchor accounts begin with an 8-byte discriminator: by default the first 8 bytes of sha256("account:<AccountName>"); Anchor 0.30+ IDLs publish the bytes. A memcmp at offset 0 with those 8 bytes (base58-encoded in the bytes field) selects one account type. Native programs such as SPL Token have no discriminator; filter them by dataSize instead (165 for a token account, 82 for a mint).

2. Add up field sizes

Borsh, the default Anchor serialization, writes fields in order with no padding. The offset of a field is the discriminator length plus the sizes of all earlier fields: u8/bool 1, u16 2, u32/i32 4, u64/i64 8, u128 16, Pubkey 32, [T; N] N × size(T). A nested struct is the sum of its fields. SPL's COption<T> is a 4-byte tag plus T, always full size.

3. Stop at the first variable-length field

Vec, String and Option take a different number of bytes per account (a 4-byte length, or a 1-byte tag with or without the value), so fields after them do not have one fixed offset. Put fields you filter on before them, or filter on something earlier.

4. Zero-copy accounts

Zero-copy (#[account(zero_copy)], bytemuck) accounts are raw memory images. With repr(C, packed) there is no padding. With plain repr(C) the compiler pads fields to their alignment, so well-designed zero-copy structs add explicit padding fields. Rugsight's pages only show offsets where every field is naturally aligned or the struct is packed.

Examples from the snapshot

AccountFieldOffsetAccount size
SPL Token Token accountowner32165
SPL Token Token accountmint0165
Orca Whirlpools WhirlpooltokenMintA101653
Raydium CPMM (CP Swap) PoolStatetoken_0_mint168637
Raydium AMM V3 (CLMM) PoolStatetoken_mint_0731544
Meteora DLMM LbPairtoken_x_mint88904
Raydium AMM V4 AmmInfocoinMint400752
Pump.fun Bonding Curve BondingCurvecreator4981

Each row links to the full layout with a ready filter. Sizes are from the 2026-11-17 snapshot; programs can add fields in upgrades, so prefer a discriminator filter over dataSize when a program may have resized an account.

All programs in the IDL reference · Explain a transaction

Data: solana-idls@1.2.1 (MIT, © Obsidian Protocol) and SPL Token / Token-2022 state layouts (Apache-2.0), snapshot 2026-11-17. Programs can upgrade and an IDL snapshot can lag the deployed program, so check important offsets against current account data.