Copy-paste recipes
Real, working snippets for the most common flows — burns, treasury splits, live pricing, transactions, signed receipts, and on-chain lookup. Every example runs against @burnkit/sdk.
pnpm add @burnkit/sdk100% burn checkout
The simplest flow: charge a USD price in a token and burn all of it. Omit burnPercent and it defaults to a full burn.
import { createBurnkitClient } from "@burnkit/sdk"; const burnkit = createBurnkitClient({ network: "devnet" }); const intent = await burnkit.createBurnIntent({ mint: "So11111111111111111111111111111111111111112", payer: userWallet, usdAmount: 1, burnPercent: 100, action: "generate_meme_pack",}); const receipt = burnkit.issueReceipt(intent);Partial burn + treasury split
Burn a share and route the rest to a treasury wallet. burnPercent plus all split percents must sum to 100.
const intent = await burnkit.createBurnIntent({ mint: "TOKEN_MINT", payer: "USER_WALLET", usdAmount: 5, burnPercent: 80, splits: [ { type: "treasury", wallet: "TREASURY_WALLET", percent: 20 }, ], action: "unlock_brand_kit",});Convert USD into a token amount
Turn a USD utility price into a precise token amount. Use baseAmount (base units) when building on-chain instructions.
const quote = await burnkit.quote({ mint: "So11111111111111111111111111111111111111112", usdAmount: 2.5,}); // {// uiAmount: 0.0166...,// baseAmount: "16666666",// unitPriceUsd: 150,// decimals: 9,// source: "mock",// }Jupiter + DexScreener with fallback
Prefer Jupiter, fall back to DexScreener, then a deterministic provider so quoting never hard-fails. Decimals resolve on-chain automatically.
import { createBurnkitClient, JupiterPriceProvider, DexScreenerPriceProvider, FallbackPriceProvider, MockPriceProvider,} from "@burnkit/sdk"; const burnkit = createBurnkitClient({ network: "mainnet-beta", rpcUrl: process.env.SOLANA_RPC_URL, priceProvider: new FallbackPriceProvider([ new JupiterPriceProvider({ rpcUrl: process.env.SOLANA_RPC_URL }), new DexScreenerPriceProvider({ rpcUrl: process.env.SOLANA_RPC_URL }), new MockPriceProvider(), ]),});Turn an intent into signable instructions
The optional @burnkit/sdk/web3 subpath builds the SPL instructions. Your app fetches the blockhash, signs, and sends.
import { buildBurnInstructions } from "@burnkit/sdk/web3";import { Transaction } from "@solana/web3.js"; const plan = burnkit.planTransaction(intent);const instructions = buildBurnInstructions(plan); const { blockhash } = await connection.getLatestBlockhash();const tx = new Transaction({ feePayer, recentBlockhash: blockhash,}).add(...instructions); // sign & send with your wallet adapterSign and verify a receipt
Attach an Ed25519 attestation for cryptographic proof of who issued a receipt, then verify digest + signature in one call.
import { createBurnkitClient, Ed25519ReceiptSigner } from "@burnkit/sdk"; const signer = Ed25519ReceiptSigner.fromSecretKey(issuerSecretKey);const burnkit = createBurnkitClient({ network: "mainnet-beta", receiptSigner: signer,}); let receipt = burnkit.issueReceipt(intent, { signature });receipt = await burnkit.signReceipt(receipt); burnkit.verifyReceipt(receipt);// { valid: true, signed: true, signer: "<base58 pubkey>" }Anchor on-chain and read it back
Record the receipt digest in the burn transaction with a Memo instruction, then cross-check a stored receipt by signature.
import { buildReceiptAnchorInstruction } from "@burnkit/sdk/web3"; const instructions = [ ...buildBurnInstructions(plan), buildReceiptAnchorInstruction(receipt, { signers: [payer] }),]; // after the transaction lands:const result = await burnkit.verifyAnchoredReceipt(txSignature, receipt);// { valid, anchored, digestMatches, signed, onChain }Branch on typed error codes
Every error extends BurnkitError with a stable code, so you can handle failures without parsing messages.
import { BurnkitError } from "@burnkit/sdk"; try { await burnkit.createBurnIntent(input);} catch (err) { if (err instanceof BurnkitError) { switch (err.code) { case "VALIDATION": // bad input break; case "PRICE_UNAVAILABLE": // no price for mint break; default: throw err; } }}