What is an IDL?
The IDL contains:- Program metadata (name, version, address)
- Instruction definitions with parameters
- Account structures and types
- Custom type definitions
- Error codes and messages
- Events emitted by the program
Generating IDLs
Anchor automatically generates IDLs during the build process:- JSON format:
target/idl/<program_name>.json - TypeScript format:
target/types/<program_name>.ts
IDL build feature
To generate IDLs, programs must have theidl-build feature enabled in Cargo.toml:
IDL structure
Basic example
Instructions
Each instruction includes:Account types
Custom types
Error codes
Using IDLs
TypeScript client
Anchor generates TypeScript types from the IDL:Rust client
Usedeclare_program! to generate Rust types:
IDL CLI commands
Build IDL
Generate IDL without building the program:Fetch IDL
Download IDL from a deployed program:Initialize IDL account
Upload IDL to the blockchain:Upgrade IDL
Update an existing on-chain IDL:Discriminators
Discriminators are 8-byte identifiers that uniquely identify instructions and accounts:IDL parsing
Read and parse IDL files programmatically:Best practices
Upload IDLs on-chain - Use
anchor deploy (which uploads IDL by default) or anchor idl init for client discoverability.Next steps
TypeScript client
Use IDLs with the TypeScript client
IDL CLI reference
Complete IDL command reference