Nenhuma descrição

github-actions[bot] 547a9ae732 [1.x] Publish packages (#916) 2 dias atrás
.changeset 36df852972 [1.x] Publish packages (#916) 2 dias atrás
.github 5e85d9fc3a Use install-solana action from solana-program (#852) 2 meses atrás
packages 36df852972 [1.x] Publish packages (#916) 2 dias atrás
.gitignore bb2289e537 Make prettier ignore CHANGELOG.md files 1 ano atrás
.prettierignore bb2289e537 Make prettier ignore CHANGELOG.md files 1 ano atrás
LICENSE 1794ecdd3f Update license dates (#835) 2 meses atrás
README.md c3baa4167e feat: add dart renderer to publicly listed codama renderers (#895) 3 semanas atrás
eslint.config.mjs a16123fcc4 Bump pnpm and node requirement (#847) 2 meses atrás
package.json 8050a63eee build(deps-dev): bump vitest from 4.0.9 to 4.0.10 (#912) 3 dias atrás
pnpm-lock.yaml 538d0f3f5e build(deps): bump @noble/hashes from 1.8.0 to 2.0.1 (#863) 2 dias atrás
pnpm-workspace.yaml 092b55b7f3 Design an empty monorepo setup (#1) 1 ano atrás
tsconfig.json 760dda5775 Inline scripts in packages (#842) 2 meses atrás
tsup.config.base.ts 760dda5775 Inline scripts in packages (#842) 2 meses atrás
turbo.json 2622727abf Upgrade ESLint to v9 (#334) 11 meses atrás
vitest.config.base.mts 760dda5775 Inline scripts in packages (#842) 2 meses atrás
vitest.config.mts 760dda5775 Inline scripts in packages (#842) 2 meses atrás

README.md

Codama

npm npm-downloads ci

Codama is a tool that describes any Solana program in a standardised format called a Codama IDL.

A Codama IDL can be used to:

  • ✨ Generate program clients in various languages and frameworks.
  • 📚 Generate documentation and tooling for your programs.
  • 🗃️ Register your IDL for others to discover and index.
  • 🔭 Provide valuable information to explorers and wallets.

Table of contents

Getting started

Installation

To get started with Codama, simply install codama to your project and run the init command like so:

pnpm install codama
codama init

You will be prompted for the path of your IDL and asked to select any script presets you would like to use. This will create a Codama configuration file at the root of your project.

Usage

You may then use the codama run command to execute any script defined in your configuration file.

codama run --all # Run all Codama scripts.
codama run js    # Generates a JavaScript client.
codama run rust  # Generates a Rust client.

Coming from Anchor

If you are using Anchor or Shank macros, then you should already have an Anchor IDL. To make it work with Codama, you simply need to provide the path to your Anchor IDL in your Codama configuration file. Codama will automatically identify this as an Anchor IDL and will convert it to a Codama IDL before executing your scripts.

{
    "idl": "path/to/my/anchor/idl.json"
}

Codama scripts

You can use your Codama configuration file to define any script you want by using one or more visitors that will be invoked when the script is ran.

Visitors are objects that will visit your Codama IDL and either perform some operation — like generating a program client — or update the IDL further — like renaming accounts. You can either use visitors from external packages or from a local file, and — in both cases — you can provide any argument the visitor may require.

For instance, the example script below will invoke three visitors:

  • The first will use the default import from the my-external-visitor package and pass 42 as the first argument.
  • The second will use the withDefaults import from the my-external-visitor package.
  • The third will use a local visitor located next to the configuration file.

    {
    "scripts": {
        "my-script": [
            { "from": "my-external-visitor", "args": [42] },
            "my-external-visitor#withDefaults",
            "./my-local-visitor.js"
        ]
    }
    }
    

Note that if an external visitor in your script isn’t installed locally, you will be asked to install it next time you try to run that script.

❯ codama run my-script

▲ Your script requires additional dependencies.
▲ Install command: pnpm install my-external-visitor
? Install dependencies? › (Y/n)

You can learn more about the Codama CLI here.

Available visitors

The tables below aim to help you discover visitors from the Codama ecosystem that you can use in your scripts.

Feel free to PR your own visitor here for others to discover. Note that they are ordered alphabetically.

Generates documentation

Visitor Description Maintainer
@codama/renderers-demo (docs) Generates simple documentation as a template to help others create new visitors. Codama

Generates program clients

Visitor Description Maintainer
@codama/renderers-js (docs) Generates a JavaScript client compatible with Solana Kit. Anza
@codama/renderers-js-umi (docs) Generates a JavaScript client compatible with the Umi framework. Metaplex
@codama/renderers-rust (docs) Generates a Rust client compatible with the Solana SDK. Anza
@codama/renderers-vixen-parser (docs) Generates Yellowstone account and instruction parsers. Triton One
@limechain/codama-dart (docs) Generates a Dart client. LimeChain
codama-py (docs) Generates a Python client. Solar

Provides utility

Visitor Description Maintainer
@codama/visitors#* (docs) Provides a big library of utility visitors that can be used to manipulate Codama IDLs. For instance, updateErrorsVisitor can be used to update error messages in your IDL . Check out the docs to see all available visitors. Codama
@codama/visitors-core#* (docs) Everything included in visitors-core is also included in visitors. The helpers offered in this package are slightly more advanced and can be used to help you build your own visitors. Codama

Getting a Codama IDL

We are currently working on a set of transparent macros that can be added to any program in order to extract a Codama IDL from it. There are still a lot more macros and scenarios for us to support but most programs can already benefit from these macros. You can then extract an IDL from the provided crate path using the Codama API like so:

use codama::Codama;

let codama = Codama::load(crate_path)?;
let idl_json = codama.get_json_idl()?;

We will add documentation on Codama macros when they are fully implemented but feel free to check this example that extract a Codama IDL from the System program interface using a build script.

Codama's architecture

The Codama IDL is designed as a tree of nodes starting with the RootNode which contains a ProgramNode and additional data such as the Codama version used when the IDL was created. Codama provides over 60 different types of nodes that help describe nearly every aspect of your Solana programs. You can read more about the Codama nodes here.

A small example of a Codama IDL as a tree of nodes. It starts with a RootNode and goes down to ProgramNode, AccountNode, InstructionNode, etc.

Because everything is designed as a Node, we can transform the IDL, aggregate information, and output various utility tools using special objects that can traverse node trees known as visitors. See this documentation to learn more about Codama visitors.

Other resources