Skip to content
Codama generates TypeScript and Rust clients from a program’s IDL file. The generated clients include functions for calling instructions and fetching accounts, eliminating the need to manually serialize and deserialize program accounts or instruction data.
Codama is in active development and subject to change. Refer to the linked repositories in the quick reference for the latest information.

​Quick Reference

​CLI Commands

CommandDescription
codama initGenerate a codama configuration file
codama runGenerate program clients from the configuration file

​Client Generators

PackageDescription
@codama/renderers-jsGenerate @solana/kit compatible TypeScript clients
@codama/renderers-rustGenerate solana_sdk compatible Rust clients
@codama/nodes-from-anchorConvert Anchor IDLs to Codama IDLs for generating clients

​Additional Resources

ResourceDescription
CodamaCodama GitHub
Codama CLICodama CLI GitHub
Codama MacrosCodama Macros GitHub. Generate Codama IDL from native Rust programs with Codama macros
Codama Macros Example ProgramExample program demonstrating Codama macros usage

​Example

This example walks through the process of generating clients from an Anchor program IDL.
1

Setup Project Files

To follow along, create a new directory called example and add the idl.json file and the package.json file from code snippets.
This example uses a counter program IDL. View source.In an Anchor project, the IDL is found at target/idl/<program_name>.json after running anchor build.
example/idl.json
example/package.json
2

Create Codama Configuration File

Codama uses a configuration file to specify where the IDL file is located, which client languages to generate, and where to output the generated code.Install the Codama CLI and the renderers at the versions this walkthrough uses:
Terminal
Then create codama.json in the example directory with this configuration:
example/codama.json
example/package.json
npx codama init can write codama.json for you through a series of prompts, but it installs the latest renderers (@codama/renderers-js 2.x and @codama/renderers-rust 3.x) and writes a different configuration. Their generated output differs from the snippets below, and @codama/renderers-js 2.x also writes a clients/js/package.json.
3

Generate Clients

Once the configuration file is created, run the generation command to generate the clients:
Terminal
This will generate the program clients in file paths specified in the codama configuration file.
codama.json
Not all generated files are shown in corresponding code snippets.
With formatCode: true, the Rust renderer runs cargo fmt against clients/rust/Cargo.toml. Until that file exists, codama run prints a (cargo-fmt) cargo metadata exited with an error warning and leaves mod.rs unformatted. The run still succeeds. Create a minimal clients/rust/Cargo.toml first (or set formatCode to false) to avoid the warning.
example/clients/js/src/generated/index.ts
example/clients/rust/src/generated/mod.rs

​Using the Generated Clients

With the renderer versions above, the generated clients include source code for interacting with your program but do not include package.json (for TypeScript) or Cargo.toml (for Rust) files. @codama/renderers-js 2.x and later also writes a clients/js/package.json that lists @solana/kit as a peer dependency. You will need to either create a new package.json and Cargo.toml files or add the required dependencies from the generated clients to your project’s existing files.

​Integrated Into Your Application

Generate the client directly into your application’s source directory and then add the required dependencies to your existing package.json or Cargo.toml. Use this approach when building an application where the client code doesn’t need to be shared or published.

​Standalone Packages or Crates

Create separate TypeScript packages or Rust crates for each client. For example, add package.json in clients/js/ and Cargo.toml in clients/rust/. Use this approach to publish the client as a reusable library (npm or crates.io) or share the client across multiple applications in a monorepo.