Overview
TheProgram class is the primary interface for interacting with Anchor programs. It provides a type-safe, IDL-driven API for sending transactions, fetching accounts, and listening to events.
Constructor
(idl, provider?, coder?, getCustomResolver?) => Program
Creates a new Program instance.
Static Methods
async (address, provider?) => Promise<Program>
Fetches the IDL from the blockchain and creates a Program instance.
async (address, provider?) => Promise<Idl | null>
Fetches the IDL from the blockchain without creating a Program instance.
Properties
PublicKey
The on-chain address of the program.
IDL
The IDL in camelCase format for TypeScript compatibility.
Idl
The original IDL without camelCase conversion (snake_case from Rust).
Provider
The wallet and network provider used by this program.
Coder
The coder used for serializing and deserializing data.
Namespaces
methods
MethodsNamespace<IDL>
The recommended builder API for constructing and sending transactions.The methods namespace provides:
.accounts()- Set instruction accounts.signers()- Add transaction signers.remainingAccounts()- Add extra accounts.preInstructions()- Add instructions before.postInstructions()- Add instructions after.rpc()- Send and confirm transaction.instruction()- Build TransactionInstruction.transaction()- Build Transaction.simulate()- Simulate transaction.view()- Call read-only instruction
account
AccountNamespace<IDL>
Provides access to account clients for fetching and subscribing to account data.See AccountClient for full details.
rpc (deprecated)
RpcNamespace<IDL>
Legacy API for sending signed transactions. Use
methods instead.transaction (deprecated)
TransactionNamespace<IDL>
Legacy API for building Transaction objects. Use
methods instead.simulate (deprecated)
SimulateNamespace<IDL>
Legacy API for simulating transactions. Use
methods instead.instruction (deprecated)
InstructionNamespace<IDL>
Legacy API for building TransactionInstruction objects. Use
methods instead.Event Handling
(eventName, callback, commitment?) => number
Subscribe to program events emitted in transaction logs.
async (listener) => Promise<void>
Unsubscribe from a program event.