Mesh SDK API Reference
Build Cardano applications with Mesh's comprehensive SDK for wallets, transactions, data handling, utilities, and x402 payments.
Overview
The Mesh SDK provides everything you need to build Cardano applications: wallet integrations, transaction builders, data serialization, utility functions, and x402 payments. Choose the APIs that fit your use case.
Quick Start
npm install @meshsdk/coreimport { MeshTxBuilder, BlockfrostProvider } from "@meshsdk/core";
import { MeshCardanoBrowserWallet } from "@meshsdk/wallet";
// Connect to a browser wallet
const wallet = await MeshCardanoBrowserWallet.enable("eternl");
// Initialize provider and transaction builder
const provider = new BlockfrostProvider("<YOUR_API_KEY>");
const txBuilder = new MeshTxBuilder({ fetcher: provider });
// Build and submit a transaction
const utxos = await wallet.getUtxosMesh();
const changeAddress = await wallet.getChangeAddressBech32();
const unsignedTx = await txBuilder
.txOut("addr_test1...", [{ unit: "lovelace", quantity: "5000000" }])
.changeAddress(changeAddress)
.selectUtxosFrom(utxos)
.complete();
const signedTx = await wallet.signTx(unsignedTx, false);
const txHash = await wallet.submitTx(signedTx);API Categories
| Category | Purpose | Key Classes |
|---|---|---|
| Wallets | Connect and interact with user wallets | MeshCardanoBrowserWallet, MeshCardanoHeadlessWallet |
| Transaction Builder | Construct and customize transactions | MeshTxBuilder |
| Transaction Parser | Parse and test transaction data | MeshTxParser, TxTester |
| Data | Handle Cardano data types and conversions | MeshValue, JSON/Mesh formats |
| Utilities | Serialize, deserialize, and resolve data | Serializers, deserializers, resolvers |
| x402 Payments | Charge for an HTTP resource with Cardano | fetchWithPayment, createPaywall, createFacilitatorApp |
Wallets
Connect to browser extension wallets (CIP-30) or create server-side wallets for backend applications.
// Browser wallet (frontend)
import { MeshCardanoBrowserWallet } from "@meshsdk/wallet";
const wallet = await MeshCardanoBrowserWallet.enable("eternl");
// Headless wallet (backend)
import { MeshCardanoHeadlessWallet, AddressType } from "@meshsdk/wallet";
const wallet = await MeshCardanoHeadlessWallet.fromMnemonic({
networkId: 0,
walletAddressType: AddressType.Base,
fetcher: provider,
mnemonic: ["..."],
});Transaction Builder
Build any type of Cardano transaction with fine-grained control over inputs, outputs, metadata, and scripts.
import { MeshTxBuilder } from "@meshsdk/core";
const txBuilder = new MeshTxBuilder({ fetcher: provider });
const unsignedTx = await txBuilder
.txOut(recipient, [{ unit: "lovelace", quantity: "5000000" }])
.mint("1", policyId, assetName)
.mintingScript(forgingScript)
.metadataValue(721, metadata)
.changeAddress(changeAddress)
.selectUtxosFrom(utxos)
.complete();Learn more about Transaction Builder →
Data Handling
Work with Cardano's data types and convert between different formats.
import { MeshValue, mConStr0 } from "@meshsdk/core";
// Work with multi-asset values
const value = new MeshValue();
value.addAsset({ unit: "lovelace", quantity: "5000000" });
// Create Plutus data
const datum = mConStr0([pubKeyHash]);Utilities
Serialize addresses, deserialize transactions, and resolve various Cardano identifiers.
import {
deserializeAddress,
serializeNativeScript,
resolveScriptHash
} from "@meshsdk/core";
// Get key hash from address
const { pubKeyHash } = deserializeAddress(address);
// Create and serialize a native script
const { address, scriptCbor } = serializeNativeScript(nativeScript);
// Get policy ID from script
const policyId = resolveScriptHash(forgingScript);x402 Payments
Charge for an API or page with @meshsdk/x402. The server answers 402 with a price, the client signs a Cardano payment, and a facilitator settles it before the content is released.
import { fetchWithPayment } from "@meshsdk/x402";
const { response, paymentResponse } = await fetchWithPayment(
"http://localhost:3000/weather",
undefined,
wallet,
{ fetcher: provider, protocol, currentSlot },
);Learn more about x402 Payments →
Available APIs
Related
- Providers - Connect to blockchain data sources
- React Integration - UI components and hooks for React apps
- Smart Contracts - Pre-built contract interactions
- Guides - Step-by-step tutorials