Mint Token
Description
Authentication
Request
Headers
Content-Type: application/json
Authorization: Bearer <your_jwt_token>
Body Parameters
Parameter
Type
Required
Description
Response
Success Response
Error Responses
Example Usage
import { Connection, PublicKey, Transaction } from "@solana/web3.js";
import bs58 from "bs58";
async function mintToken(
tokenMintAddress: string,
amount: string,
wallet: any // Wallet adapter
) {
try {
const response = await fetch('https://api.heyhal.xyz/api/v1/coin/mint', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': `Bearer ${localStorage.getItem('auth_token')}`
},
body: JSON.stringify({
token: tokenMintAddress,
amount: amount
})
});
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
}
const { serializedTransaction } = await response.json();
// Deserialize and sign the transaction
const transaction = Transaction.from(
bs58.decode(serializedTransaction)
);
// Sign and send the transaction
const signature = await wallet.sendTransaction(
transaction,
connection
);
console.log('Mint transaction sent:', signature);
return signature;
} catch (error) {
console.error('Error minting token:', error);
throw error;
}
}
Transaction Details
Implementation Notes
// Example of constructing a mint transaction manually
async function constructMintTransaction(
mint: PublicKey,
payer: PublicKey,
metadata: {
name: string;
symbol: string;
uri: string;
}
) {
const transaction = new Transaction();
// 1. Create mint account
const lamports = await getMinimumBalanceForRentExemptMint(connection);
transaction.add(
SystemProgram.createAccount({
fromPubkey: payer,
newAccountPubkey: mint,
space: MINT_SIZE,
lamports,
programId: TOKEN_PROGRAM_ID,
})
);
// 2. Initialize mint
transaction.add(
createInitializeMintInstruction(
mint,
9, // decimals
payer,
payer,
TOKEN_PROGRAM_ID
)
);
// ... Add remaining instructions
return transaction;
}
Best Practices
Last updated