Registry / aws / codama

codama

JSON →
library1.6.0jsnpmunverified

Codama is a Solana framework designed to facilitate the building of standardized programs through specifications and code generation. It aims to streamline the development of on-chain programs by providing a structured approach to defining program interfaces and interactions. The package `codama` (currently at version 1.6.0) serves as the main entry point, re-exporting core modules like `@codama/errors`, `@codama/nodes`, `@codama/validators`, and `@codama/visitors`, bundling them into a cohesive API. It offers utilities for managing Solana IDLs, allowing developers to create, manipulate, and validate program definitions from a `RootNode` or JSON representation. The project appears to have an active release cadence, with recent minor updates introducing new node types (e.g., `EventNode`) and functionality like a dynamic client for instruction building, indicating ongoing development and feature expansion within the Solana ecosystem.

npm install codama
INSTALL
IMPORT
SIG · CODAMA
C
codama
awsjavascriptv1.6.0
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

Codama
import type { Codama } from 'codama'
This is primarily a TypeScript interface; runtime instances are created via helper functions.
createFromRoot
import { createFromRoot } from 'codama'
const { createFromRoot } = require('codama')
Prefer ESM imports. CommonJS `require` is not officially supported and may lead to issues.
createFromJson
import { createFromJson } from 'codama'
import createFromJson from 'codama'
Functions are named exports, not default exports.
ProgramNode
import { programNode } from '@codama/nodes'; // or direct from main package if re-exported import { programNode } from 'codama'
import { ProgramNode } from 'codama'
While ProgramNode is a type, `programNode` is the factory function to create an instance. The `codama` package re-exports `programNode` from `@codama/nodes`.

Demonstrates creating a Codama IDL instance from both JSON and a programmatic `RootNode`, then displaying and cloning it.

import { createFromJson, createFromRoot, programNode, type RootNode } from 'codama'; import { getDebugStringVisitor, consoleLogVisitor } from '@codama/visitors'; // Example 1: Creating from a JSON string const jsonIdlString = JSON.stringify({ version: '0.1.0', name: 'my_program', instructions: [ { name: 'initialize', accounts: [], args: [] } ], accounts: [], events: [] }); const codamaFromJson = createFromJson(jsonIdlString); console.log('Codama from JSON:'); codamaFromJson.accept(consoleLogVisitor(getDebugStringVisitor({ indent: true }))); // Example 2: Creating from a RootNode programmatically const myProgramNode: RootNode = programNode({ name: 'myProgram', version: '1.0.0', docs: ['My example program.'], instructions: [], accounts: [], errors: [], types: [], events: [] }); const codamaFromRoot = createFromRoot(myProgramNode); console.log('\nCodama from RootNode:'); codamaFromRoot.accept(consoleLogVisitor(getDebugStringVisitor({ indent: true }))); // Example 3: Modifying a Codama instance (e.g., cloning) const clonedCodama = codamaFromRoot.clone(); console.log('\nCloned Codama JSON:'); console.log(clonedCodama.getJson());
codama --version
Debug
Known issues
gotchaThe Codama framework (specifically `@codama/nodes` and `@codama/node-types`) introduced a new `EventNode` to `ProgramNode` in version 1.6.0. While this is a minor addition and typically backward-compatible, consumers relying on a strict, fixed schema for IDL parsing or code generation might need to update their tooling to properly handle the new node type.
fix
Ensure any custom IDL parsers or code generators are updated to optionally handle the presence of `EventNode` within `ProgramNode` structures. Refer to the `@codama/nodes` and `@codama/node-types` changelogs for full details.
affects: >=1.6.0
gotchaThe `@codama/errors` package, part of the core Codama monorepo, added a new 'dynamic-client' feature in version 1.6.0 for runtime Solana instruction building. While new functionality, users should be aware of potential integration impacts or new APIs to learn if they manage instruction building manually or through other libraries.
fix
Review the `@codama/errors` documentation and examples if you plan to utilize or are affected by the new 'dynamic-client' for runtime instruction construction.
affects: >=1.6.0
gotchaCodama leverages a monorepo structure, and the main `codama` package primarily re-exports functionalities from its sub-packages (e.g., `@codama/nodes`, `@codama/visitors`). Direct imports from sub-packages might be necessary for specific, granular access, or if the main `codama` package doesn't re-export a specific symbol.
fix
If a symbol is not found when importing directly from `codama`, try importing it from the specific sub-package it belongs to (e.g., `import { getDebugStringVisitor } from '@codama/visitors';`).
affects: >=1.0.0
Errors
Common errors & fixes
Error: Cannot find module 'codama' or its corresponding type declarations.
The 'codama' package was not installed or is incorrectly referenced in the project.
fix
Run `npm install codama` or `pnpm install codama` to add the package to your project's dependencies. Ensure your `tsconfig.json` includes `node_modules/@types` if using TypeScript.
TypeError: createFromJson is not a function
Attempting to import `createFromJson` using a CommonJS `require` statement in an ESM context, or using a default import syntax for a named export.
fix
Ensure you are using ESM `import { createFromJson } from 'codama'` for TypeScript/modern JavaScript projects. If forced to use CommonJS, consider transpiling your code or using dynamic `import()`.
Argument of type '{ name: string; version: string; instructions: never[]; accounts: never[]; errors: never[]; types: never[]; }' is not assignable to parameter of type 'ProgramNode'.
Incorrectly providing an object literal that doesn't fully conform to the `ProgramNode` interface or using an outdated schema when trying to create a `RootNode`.
fix
Ensure the object passed to `programNode` or `createFromRoot` strictly adheres to the `ProgramNode` definition from `@codama/nodes` (or re-exported by `codama`), including all required fields and types. Check the latest `@codama/node-types` for schema updates, especially after major/minor version bumps.
Upgrade
Version history
1.6.0latest on npm
Audit
Dependencies
@codama/errorsrequiredProvides error handling and dynamic client functionality for Codama programs.
@codama/nodesrequiredDefines the core Abstract Syntax Tree (AST) nodes for Solana program IDLs.
@codama/node-typesrequiredProvides TypeScript types for the AST nodes defined in @codama/nodes.
@codama/validatorsrequiredOffers validation logic for Codama IDL structures.
@codama/visitorsrequiredEnables traversal and manipulation of Codama IDL ASTs using the visitor pattern.
@codama/visitor-corerequiredCore utilities for implementing visitors in the Codama framework.
Agent activity
17 hits · last 30 days
node
16
OpenAI (training)
1
Resources