Mesh for AI Coding Agents
What an AI coding agent needs to write correct Mesh code: install, current package versions, canonical TxBuilder snippets, and where to read more.
This page is written for AI coding agents such as Claude Code, Cursor, Codex and ChatGPT, and for the people who set them up. It is short on purpose: read it first, then fetch the pages it links to as needed.
Rules
- Prefer
TxBuilder. Build every new transaction withTxBuilderand its parts (output,mint,spend, ...).MeshTxBuilder, the chain of calls, is legacy: it still works, but do not write new code with it. To convert existing code, see Migrating to TxBuilder. - Use the docs, not memory. Mesh 2.0 changed the transaction API. Code from training data that calls
txOut(...),changeAddress(...)andcomplete()on a builder is the legacy API. - Amounts are
bigint. Write5_000_000n, not5000000. - Never rebuild to retry. Call
submit()again on the sameBuiltTx; see Errors. - Wallets: see Wallets for how to connect a browser wallet or create a server-side wallet. This page shows no wallet code.
Install
npm install @meshsdk/coreFor React apps, add the React package:
npm install @meshsdk/reactPackage Versions
| Package | Version on npm |
|---|---|
@meshsdk/core | 2.0.0 |
@meshsdk/transaction | 2.0.0 |
@meshsdk/wallet | 2.0.0 |
@meshsdk/react | 2.0.0-beta.2 |
@meshsdk/core re-exports @meshsdk/transaction, @meshsdk/wallet and the providers, so most code imports from @meshsdk/core only. Check the current version with npm view @meshsdk/core version.
Canonical Snippets
These come from Transaction Basics and Mint and Burn Assets. They use provider (a provider such as BlockfrostProvider, see Providers), wallet (see Wallets), and recipient, an address.
Create a Builder
import { TxBuilder } from "@meshsdk/core";
const builder = new TxBuilder({ network: "preprod", provider });Send Lovelace
import { output } from "@meshsdk/core";
const built = await builder.build(
output({ address: recipient, value: { lovelace: 5_000_000n } }),
{ payer: wallet },
);
await built.sign(); // the payer signs
await built.submit({ submitter: wallet }); // the wallet sends it
const { slot } = await built.awaitInclusion(); // found in a blockThe builder selects inputs, adds change and sets the fee. build() signs and sends nothing; built.tx is the unsigned transaction as CBOR hex and built.txHash is known before signing.
Mint a Token with a Native Script
import { ForgeScript, mint, stringToHex } from "@meshsdk/core";
const changeAddress = await wallet.getChangeAddress();
const forgingScript = ForgeScript.withOneSignature(changeAddress);
const built = await builder.build(
mint.native({
script: forgingScript,
assets: { [stringToHex("MeshToken")]: 1n },
}),
{ payer: wallet },
);A negative quantity burns. Sign and submit as above.
Handle Errors
Every error of TxBuilder is a TxError with a code. Check the code, not the message, with TxError.is(error, "CODE"). The Errors page lists every code and which ones a retry can fix.
Where to Read More
- TxBuilder and the Cookbook: recipes for payments, tokens, scripts, staking and governance
- Errors: every error code and what to do about it
- llms.txt: an index of every page, each linked as plain markdown. Add
.mdto any docs URL for its markdown; llms.txt explains the section files. - MCP Server: search and read these docs from your agent, at
https://meshjs.dev/mcp, no API key - Agent Skills: installable Mesh skills for coding agents
- Examples: complete example apps
AI Integration
Build Cardano applications faster with AI-powered tools for documentation, code generation, and debugging
Agent Skills for AI Coding Assistants
Install MeshJS Agent Skills so Claude Code, Cursor, Codex and other AI assistants write Mesh TxBuilder, wallet and serialization code correctly.