Overview
The IDL (Interface Definition Language) is a JSON structure that describes an Anchor program’s interface. It defines instructions, accounts, types, events, and errors in a machine-readable format.Idl
The root IDL type that describes an entire Anchor program.string
required
The on-chain program address.
IdlMetadata
required
Program metadata including name, version, and spec version.
string[]
Documentation comments from the Rust program.
IdlInstruction[]
required
Array of program instructions.
IdlAccount[]
Array of account type definitions.
IdlEvent[]
Array of event definitions.
IdlErrorCode[]
Array of custom error codes.
IdlTypeDef[]
Array of custom type definitions (structs, enums).
IdlConst[]
Array of program constants.
IdlMetadata
Program metadata and version information.string
required
The program name.
string
required
The program version (e.g., “0.1.0”).
string
required
The IDL spec version (e.g., “0.1.0”).
string
Program description.
string
Source code repository URL.
IdlDependency[]
External program dependencies.
IdlInstruction
Defines a single program instruction.string
required
The instruction name in snake_case.
string[]
Documentation from Rust doc comments.
number[]
required
8-byte instruction discriminator for identifying the instruction.
IdlInstructionAccountItem[]
required
Required accounts for the instruction.
IdlField[]
required
Instruction arguments.
IdlType
Return type if the instruction returns a value.
IdlInstructionAccount
Defines a single account required by an instruction.string
required
Account name.
boolean
Whether the account is writable. Defaults to false.
boolean
Whether the account must be a signer. Defaults to false.
boolean
Whether the account is optional. Defaults to false.
string
Hardcoded account address if known at compile time.
IdlPda
PDA derivation information if this account is a PDA.
string[]
Related accounts for validation.
IdlPda
Defines how to derive a Program Derived Address.IdlSeed[]
required
Array of seeds used to derive the PDA.
IdlSeed
Optional program ID seed. Defaults to the current program.
IdlAccount
Defines an account type stored by the program.string
required
The account type name.
number[]
required
8-byte account discriminator for identifying the account type.
IdlEvent
Defines an event that can be emitted by the program.string
required
Event name in PascalCase.
number[]
required
8-byte event discriminator.
IdlTypeDef
Defines a custom type (struct or enum).string
required
Type name.
IdlTypeDefTy
required
The type definition (struct, enum, or type alias).
IdlTypeDefGeneric[]
Generic type parameters.
IdlType
Represents any Anchor type.Primitive Types
boolean
Boolean value.
number
Integer types that fit in JavaScript number.
BN
Large integer types requiring BN (Big Number) in JavaScript.
number
Floating point types.
Uint8Array
Raw bytes.
string
UTF-8 string.
PublicKey
Solana public key.
Complex Types
{ option: IdlType }
Rust
Option<T> type.{ coption: IdlType }
Compact option for primitives.
{ vec: IdlType }
Dynamic array (Rust
Vec<T>).{ array: [IdlType, number] }
Fixed-size array.
{ defined: { name: string } }
Custom defined type (references a type in
idl.types).IdlField
A named field with a type.string
required
Field name.
IdlType
required
Field type.
string[]
Field documentation.
IdlErrorCode
Defines a custom error.string
required
Error name.
number
required
Error code (starting at 6000 for custom errors).
string
Error message.
Helper Functions
<I extends Idl>(idl: I) => I
Converts IDL from snake_case to camelCase for TypeScript.The
Program class automatically applies this conversion.async (programId: PublicKey) => Promise<PublicKey>
Derives the deterministic IDL account address for a program.
(data: Buffer) => IdlProgramAccount
Decodes an on-chain IDL account.
(item: IdlInstructionAccountItem) => boolean
Type guard to check if an account item is a nested accounts group.