Documents › Usage Examples › Mint Token
import { Wallet, MintQuoteState } from '@cashu/cashu-ts';
const mintUrl = 'http://localhost:3338';
const wallet = new Wallet(mintUrl);
await wallet.loadMint(); // wallet is now ready to use
const mintQuote = await wallet.createMintQuoteBolt11(64);
// pay the invoice here before you continue...
const mintQuoteChecked = await wallet.checkMintQuoteBolt11(mintQuote.quote);
if (mintQuoteChecked.state === MintQuoteState.PAID) {
const proofs = await wallet.mintProofsBolt11(64, mintQuote.quote);
}
// store proofs in your app ..
prepareMint() / completeMint()The two-step process gives you a chance to persist the preview before calling the mint. This works well with NUT-19 transport retries and lets you recover safely if your app restarts between steps.
import { Wallet, MintQuoteState } from '@cashu/cashu-ts';
const wallet = new Wallet('http://localhost:3338');
await wallet.loadMint();
const mintQuote = await wallet.createMintQuoteBolt11(64);
// pay the invoice here before continuing...
const mintQuoteChecked = await wallet.checkMintQuoteBolt11(mintQuote.quote);
if (mintQuoteChecked.state !== MintQuoteState.PAID) {
throw new Error('Mint quote is not paid yet');
}
const preview = await wallet.prepareMint('bolt11', 64, mintQuote.quote, undefined, {
type: 'deterministic',
counter: 0,
});
// Persist `preview` here if you want to retry safely later.
const proofs = await wallet.completeMint(preview);
import { Wallet } from '@cashu/cashu-ts';
import { secp256k1 } from '@noble/curves/secp256k1.js';
import { bytesToHex, randomBytes } from '@noble/hashes/utils.js';
const wallet = new Wallet('http://localhost:3338');
await wallet.loadMint();
const privkey = randomBytes(32);
const pubkey = bytesToHex(secp256k1.getPublicKey(privkey, true));
const mintQuote = await wallet.createMintQuoteBolt12(pubkey, {
amount: 64,
description: 'Top up wallet',
});
// pay the BOLT12 offer here, then re-check the quote...
const updatedQuote = await wallet.checkMintQuoteBolt12(mintQuote.quote);
const availableAmount = updatedQuote.amount_paid - updatedQuote.amount_issued;
if (availableAmount <= 0) {
throw new Error('No paid amount available to mint');
}
const preview = await wallet.prepareMint('bolt12', availableAmount, updatedQuote, {
privkey: bytesToHex(privkey),
});
const proofs = await wallet.completeMint(preview);