What Is IDL in Solana?
An IDL (Interface Definition Language) is a JSON file that describes a Solana program’s interface: its instructions, account structs, custom types, and error codes. Client libraries use the IDL to automatically serialize instruction data and deserialize account state.
What an IDL contains
| Section | Description |
|---|---|
instructions | List of instruction handlers with parameter names and types |
accounts | Named account types with their field layouts |
types | Custom structs and enums used by the program |
errors | Error codes with messages |
metadata | Program address and other metadata |
How IDLs are generated
Anchor automatically generates an IDL when you build a program (anchor build). The IDL is derived from the Rust source code — instruction handler signatures, #[derive(Accounts)] structs, and custom types.
Non-Anchor programs can also have IDLs, but they must be written manually or generated by custom tooling.
Using IDLs in clients
import { Program, AnchorProvider } from "@coral-xyz/anchor";
import idl from "./my_program.json";
const program = new Program(idl, provider);
// Instruction calls are type-safe and auto-serialized
await program.methods
.initialize(42)
.accounts({ state: stateAccount })
.rpc();
On-chain IDLs
Anchor can publish an IDL on-chain using anchor idl init or anchor idl upgrade. On-chain IDLs allow explorers and tools to decode transactions and account data for any program without distributing the JSON file separately.
FAQ
Do all Solana programs have an IDL? No. Only Anchor programs generate IDLs automatically. Native and non-Anchor programs may not have an IDL unless one is manually created.
Can I use an IDL with @solana/kit?
The @solana/kit ecosystem uses Codama for program client generation, which serves a similar purpose to Anchor IDLs but with a different toolchain.
Updated: