Generating TS Clients
Generate TypeScript clients from Anchor IDL for typed account resolution, instruction builders, and error decoding.
Search across all documentation pages
Generate TypeScript clients from Anchor IDL for typed account resolution, instruction builders, and error decoding.
anchor build
# Legacy Anchor client
anchor idl parse -f target/idl/my_program.json -o app/src/idl.tsimport { Program, AnchorProvider } from "@coral-xyz/anchor";
import idl from "./idl/my_program.json";
const program = new Program(idl as MyProgram, provider);
await program.methods.initialize().accounts({ payer }).rpc();When to reach for this: You build dApps or integration tests against Anchor programs.
import { AnchorProvider, Wallet, Program } from "@coral-xyz/anchor";
import { Connection, Keypair } from "@solana/web3.js";
import idl from "../target/idl/counter.json";
const connection = new Connection("http://127.0.0.1:8899");
const wallet = new Wallet(Keypair.generate());
const provider = new AnchorProvider(connection, wallet, {});
const program = new Program(idl, provider);
await program.methods
.increment()
.accounts({
counter: counterPda,
authority: wallet.publicKey,
})
.rpc();What this demonstrates:
For greenfield apps, prefer Codama + @solana/kit 7.0.0 generated clients (see next article). Anchor TS client remains common in anchor test workflows.
Ship IDL npm package or commit generated types in CI.
| Alternative | Use When | Don't Use When |
|---|---|---|
| Codama + @solana/kit | Modern kit-native clients | Legacy anchor test stack |
| Hand-rolled instruction bytes | Minimal deps | Anchor IDL available |
| anchorpy (Python) | Python bots | TypeScript dApps |
0.32.1 across advanced topics.
Large fixed layouts when Borsh CU too high.
Not easily; plan forward growth.
No; document separately.
Callee IDL JSON at compile time.
Yes with correct account metas.
Avoid different IDL per feature on mainnet.
LiteSVM, Surfpool, devnet simulation.
No; last resort.
See Related links for ts client.
Stack versions: This page was written for Agave 4.1.1, Solana CLI 3.0.10, Anchor 0.32.1, anchor-lang 0.32.1, Rust 1.91.1, @solana/kit 7.0.0, Surfpool 0.12.0, and LiteSVM 0.6.x.
Reviewed by Chris St. John·Last updated Jul 19, 2026