// 1) Create/select a token in the Brale dashboard and get an API key
// 2) Server-side mint to a Spark address
const BRALE_API = 'https://api.brale.xyz'; // example base URL
const BRALE_API_KEY = process.env.BRALE_API_KEY!;
const TOKEN_ID = process.env.BRALE_TOKEN_ID!; // your Brale-issued token id
type MintRequest = {
tokenId: string;
amount: string; // integer string amount in smallest units
recipientSparkAddress: string; // Spark address (bech32m) to receive tokens
};
async function mintToSpark(req: MintRequest) {
const res = await fetch(`${BRALE_API}/v1/tokens/${req.tokenId}/mint`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': `Bearer ${BRALE_API_KEY}`,
},
body: JSON.stringify({
amount: req.amount,
recipient: req.recipientSparkAddress,
}),
});
if (!res.ok) {
const err = await res.text();
throw new Error(`Brale mint failed: ${res.status} ${err}`);
}
return await res.json();
}
// Example usage
await mintToSpark({
tokenId: TOKEN_ID,
amount: '1000000', // e.g., 1.000000 unit if 6 decimals
recipientSparkAddress: 'spark1xxxxx',
});