Coda

Quick Start

Generate your first TypeScript client with Coda

Get started with Coda in seconds using our project scaffolding tool.

The fastest way to start is with create-coda:

# Using npm
npm create @macalinao/create-coda@latest my-client
cd my-client
npm install

# Using bun
bun create @macalinao/create-coda my-client
cd my-client
bun install

This creates a complete project with:

  • TypeScript and ESLint pre-configured
  • Coda configuration ready to use
  • Example IDL to get started
  • All necessary build scripts

Then add your IDL and generate:

# Replace example.json with your Anchor IDL
cp path/to/your/program/target/idl/your_program.json idls/

# Generate the TypeScript client
bun run codegen

# Build the project
bun run build

Option 2: Add to Existing Project

If you have an existing project with an Anchor IDL:

Step 1: Install Coda

# Using npm
npm install -D @macalinao/coda

# Using bun
bun add -D @macalinao/coda

Step 2: Generate the Client

# Using npm
npx coda generate

# Using bun
bunx coda generate

Coda will:

  • Locate your IDL (defaults to ./idls/*.json or ./target/idl/)
  • Generate a complete TypeScript client
  • Output files to ./src/generated/

No configuration required for standard Anchor projects.

Step 3: Use the Generated Client

Import and use the generated functions in your application:

import {
  createTransferInstruction,
  fetchTokenAccount,
  findVaultPda,
} from "./src/generated";

// Create instructions with full type safety
const instruction = createTransferInstruction({
  source: sourceAccount,
  destination: destAccount,
  authority: signer,
  amount: 1000n,
});

// Fetch and decode accounts
const account = await fetchTokenAccount(rpc, address);
console.log(account.balance); // Fully typed

// Find program-derived addresses
const [vault] = await findVaultPda({
  user: userPubkey,
  seed: "vault",
});

Generated Client Components

Coda generates a comprehensive TypeScript client including:

Instructions

Typed builders for every program instruction with full IntelliSense support.

Accounts

Fetchers and decoders for all account types with automatic deserialization.

Types

All custom types from your IDL including enums, structs, and unions.

PDAs

Helper functions for program-derived address calculation.

Errors

Typed error definitions for proper error handling.

File Structure

The generated client is organized as follows:

src/generated/
├── index.ts              # Main export file
├── instructions/         # Instruction builders
├── accounts/            # Account types and fetchers
├── types/              # Custom type definitions
├── pdas/              # PDA helper functions
├── programs/          # Program metadata
└── errors/            # Error definitions

Next Steps

  • Start building: Use the generated client in your application
  • Customize generation: See configuration for advanced options
  • View examples: Check out example projects for reference

Troubleshooting

IDL not found: Ensure your Anchor program is built with anchor build

Import errors: Use .js extensions in imports (required for ES modules)

Type errors: Run tsc --noEmit to check TypeScript compilation

For additional help, please open an issue on GitHub.