Generate Parsers with Codama
How-to generate Vixen parser with Codama
This guide walks you through generating a Vixen Parser using Codama, a tool for rendering Rust SDKs and parser implementations from IDLs.
Vixen is a framework for building real-time program data pipelines in Rust. This guide helps you scaffold a parser that can be used in the Vixen runtime to decode and process Solana program data.
Prerequisites
An
idl.json
file: Either Anchor-generated or custom.Install pnpm: Or use npm/yarn if preferred.
Initialize a JavaScript Project:
pnpm init
Installation
Install the required Codama packages:
pnpm install @codama/renderers-vixen-parser
Also, install dependencies for the parser generation script:
pnpm install \
@codama/nodes \
@codama/nodes-from-anchor \
@codama/renderers-core \
@codama/visitors-core
Setup
Create a Parser Generation Script
Create a new file, codama.cjs
:
const path = require("node:path");
const { rootNode } = require("@codama/nodes");
const { rootNodeFromAnchor } = require("@codama/nodes-from-anchor");
const { readJson } = require("@codama/renderers-core");
const { visit } = require("@codama/visitors-core");
const { renderVisitor } = require("@codama/renderers-vixen-parser");
const projectName = "example-parser";
const idl = readJson(path.join(__dirname, "idl.json"));
const node = rootNodeFromAnchor(idl);
visit(
node,
renderVisitor({
projectFolder: __dirname,
projectName,
}),
);
Tip: The
projectName
is used for the Cargo crate name of the generated parser.
Run the Code Generation Script
node codama.cjs
Your folder structure should look like:
example-parser/
├── proto/
│ └── example_parser.proto
├── src/
│ ├── generated_parser/
│ ├── generated_sdk/
│ └── lib.rs
├── build.rs
├── Cargo.toml
├── codama.cjs
└── idl.json
Build and Verify
cargo build
If successful, you now have a working parser for Solana account data using Yellowstone Vixen.
Completion
Congratulations! You now have a custom Vixen parser ready for integration into a Vixen pipeline.
Last updated
Was this helpful?