Clients Overview
Clients are a public interface to your program and are usually generated from an Interface Definition Language (IDL) file.
IDL Formats
There are two major IDL formats, Shank and Anchor.
Tools Used
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'));
Functionality of Codama
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.
Packaging the Output
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.