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
Program ID to initialize IDL for (auto-discovered from IDL if not provided)
Options
Path to the IDL JSON file
Priority fee in micro-lamports per compute unit
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
Program ID to upgrade IDL for (auto-discovered from IDL if not provided)
Options
Path to the new IDL JSON file
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
Program name to build the IDL for (current directory’s program if not specified)
Output file for the IDL (stdout if not specified)
Output file for the TypeScript IDL
Suppress doc strings in output
Do not check for safety comments
Arguments to pass to the underlying
cargo test commandExamples
anchor idl fetch
Fetch an IDL for a program from a cluster.Syntax
Arguments
Program ID to fetch IDL for
Options
Output file for the IDL (stdout if not specified)
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
Path to the legacy IDL file
Options
Output file for the converted IDL (stdout if not specified)
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
Path to the IDL file
Options
Output file for the TypeScript types (stdout if not specified)
Example
anchor idl close
Close a metadata account and recover rent.Syntax
Arguments
The program ID
Options
The seed used for the metadata account
Priority fees in micro-lamports per compute unit
Example
anchor idl create-buffer
Create a buffer account for metadata.Syntax
Options
Path to the metadata file
Priority fees in micro-lamports per compute unit
Example
anchor idl set-buffer-authority
Set a new authority on a buffer account.Syntax
Arguments
The buffer account address
Options
The new authority
Priority fees in micro-lamports per compute unit
Example
anchor idl write-buffer
Write metadata using a buffer account.Syntax
Arguments
The program ID
Options
The buffer account address
The seed to use for the metadata account
Close the buffer after writing
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.