Build your Codama IDL from Anchor IDL
Creating a Codama IDL from Anchor is extremely straightforward. Once you generate your Anchor IDL with anchor build, we need to install the '@codama/nodes-from-anchor' package:
pnpm install codama @codama/nodes-from-anchor
And then convert the Anchor IDL directly using the rootNodeFromAnchor
function:
import { createFromRoot } from 'codama';
import { rootNodeFromAnchor } from '@codama/nodes-from-anchor';
import anchorIdl from 'anchor-idl.json';
const codama = createFromRoot(rootNodeFromAnchor(anchorIdl));
This gives you a fully functional Codama IDL that's ready for client generation. However, the real power of Codama comes from its ability to enhance and customize your IDL beyond what's possible with raw Anchor definitions.
Since the conversion process focuses on structural translation, you'll often want to add developer-friendly features like custom naming conventions, additional type information, or specialized client methods. Codama's visitor system makes these enhancements straightforward and powerful.
You can learn more on how to customize and enhance your converted IDL using visitors in the Updating Codama IDL lesson.