Overview
Theanchor idl command provides subcommands for managing Interface Definition Language (IDL) files, including building, uploading, fetching, and converting IDLs.
Subcommands
init- Initialize a program’s IDL account on-chainupgrade- Upgrade the IDL to a new filebuild- Generate the IDL for a programfetch- Fetch an IDL from a clusterconvert- Convert legacy IDLs to the new IDL spectype- Generate TypeScript types from an IDLclose- Close a metadata account and recover rentcreate-buffer- Create a buffer account for metadataset-buffer-authority- Set a new authority on a buffer accountwrite-buffer- Write metadata using a buffer account
anchor idl init
Initialize a program’s IDL account on-chain. Can only be run once per program.Syntax
Arguments
pubkey
Program ID to initialize IDL for (auto-discovered from IDL if not provided)
Options
string
required
Path to the IDL JSON file
number
Priority fee in micro-lamports per compute unit
flag
default:"false"
Create non-canonical metadata account (third-party metadata)
Example
anchor idl upgrade
Upgrade the IDL to a new file. This is an alias for writing and then setting the IDL buffer account.Syntax
Arguments
pubkey
Program ID to upgrade IDL for (auto-discovered from IDL if not provided)
Options
string
required
Path to the new IDL JSON file
number
Priority fee in micro-lamports per compute unit
Example
anchor idl build
Generate the IDL for a program using the compilation method.Syntax
Alias
Options
string
Program name to build the IDL for (current directory’s program if not specified)
string
Output file for the IDL (stdout if not specified)
string
Output file for the TypeScript IDL
flag
default:"false"
Suppress doc strings in output
flag
default:"false"
Do not check for safety comments
string
Arguments to pass to the underlying
cargo test commandExamples
anchor idl fetch
Fetch an IDL for a program from a cluster.Syntax
Arguments
pubkey
required
Program ID to fetch IDL for
Options
string
Output file for the IDL (stdout if not specified)
flag
default:"false"
Fetch non-canonical metadata account (third-party metadata)
Examples
anchor idl convert
Convert legacy IDLs (pre Anchor 0.30) to the new IDL spec.Syntax
Arguments
string
required
Path to the legacy IDL file
Options
string
Output file for the converted IDL (stdout if not specified)
pubkey
Program ID to set in the IDL (auto-discovered from IDL if not provided)
Example
anchor idl type
Generate TypeScript type definitions from an IDL.Syntax
Arguments
string
required
Path to the IDL file
Options
string
Output file for the TypeScript types (stdout if not specified)
Example
anchor idl close
Close a metadata account and recover rent.Syntax
Arguments
pubkey
required
The program ID
Options
string
default:"idl"
The seed used for the metadata account
number
Priority fees in micro-lamports per compute unit
Example
anchor idl create-buffer
Create a buffer account for metadata.Syntax
Options
string
required
Path to the metadata file
number
Priority fees in micro-lamports per compute unit
Example
anchor idl set-buffer-authority
Set a new authority on a buffer account.Syntax
Arguments
pubkey
required
The buffer account address
Options
pubkey
required
The new authority
number
Priority fees in micro-lamports per compute unit
Example
anchor idl write-buffer
Write metadata using a buffer account.Syntax
Arguments
pubkey
required
The program ID
Options
pubkey
required
The buffer account address
string
default:"idl"
The seed to use for the metadata account
flag
default:"false"
Close the buffer after writing
number
Priority fees in micro-lamports per compute unit
Example
IDL Structure
A modern Anchor IDL includes:Notes
IDLs are automatically uploaded during
anchor deploy unless --no-idl is specified.The
--non-canonical flag is for third-party metadata accounts. Most users should use the canonical IDL account.