Home

Awesome

Codama

npm npm-downloads ci

[!NOTE]
Wait, wasn't this called Kinobi before? It was! We've renamed this project Codama. Check out this PR for more details.

Codama is a tool that describes any Solana program in a powerful standardised format known as the Codama IDL. This IDL can then be used to create a variety of utility such as rendering client code for your programs in various languages/frameworks, generating CLIs and providing more information to explorers.

Codama header: A small double-sided mind-map with the Codama logo in the middle. On the left, we see the various ways to get a Codama IDL from your Solana programs such as "Anchor Program" and "Shank macros". On the right, we see the various utility tools that are offered for the IDL such as "Rendering client code" or "Rendering documentation".

Nodes and visitors

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 just about any 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.

A small example of how a visitor can transform a Codama IDL into another Codama IDL. This example illustrates the "deleteNodesVisitor" which recursively removes NumberTypeNodes from a tree of nested TypleTypeNodes.

From program to Codama

There are various ways to extract information from your Solana programs in order to obtain a Codama IDL.

Transforming Codama

Once you have your Codama IDL, you may use visitors to transform it. This can be useful when the Codama IDL was obtained from another source that may not contain some necessary information. Here is an example using two provided visitors that adjusts the accounts and instructions on the program.

import { updateAccountsVisitor, updateInstructionsVisitor } from 'codama';

codama.update(updateAccountsVisitor({ ... }));
codama.update(updateInstructionsVisitor({ ... }));

From Codama to utility

Now that you have the perfect Codama IDL for your Solana program, you can benefit from all the visitors and tools that provide utility such as rendering client code or registering your IDL on-chain so explorers can dynamically display relevant information for your program.

Note that some features such as rendering CLIs are not yet available. However, because the Codama IDL is designed as a tree of nodes, these features are only a visitor away from being ready. Feel free to reach out if you’d like to contribute to this Codama ecosystem.