Soldev

Solana clients

Last updated:

Clients are a public interface to your program and are usually generated from an Interface Definition Language (IDL) file.

There are two major IDL formats, Shank and Anchor.

We use tools like Codama to take our IDL and produce all the javascript files with functions required to produce valid instructions for your specific program.

import { createFromRoot } from 'codama';
import { rootNodeFromAnchor } from '@codama/nodes-from-anchor';
import { renderJavaScriptVisitor, renderRustVisitor } from '@codama/renderers';

import anchorIdl from 'anchor-idl.json';

const codama = createFromRoot(rootNodeFromAnchor(anchorIdl as AnchorIdl))

codama.accept(renderJavaScriptVisitor('clients/js/src/generated'));
codama.accept(renderRustVisitor('clients/rust/src/generated'));

Codama is essentially a transpiler that takes in IDL and outputs code in whatever language that has a renderer written for it.

Each renderer implements the visitor pattern to traverse the abstract syntax tree (AST) and walk through each node, generating code as it goes.

Finally we can take these files and package them, along with the code that calls them, with our frontend bundle which the user would download and use to interact with our real program on-chain.