Mint Token
Endpoint: POST /api/v1/coin/mint
Description
This endpoint creates and returns a serialized transaction for minting new tokens, setting up metadata, creating liquidity pools, and executing initial swaps. The transaction includes token creation, metadata initialization, and initial liquidity setup.
Authentication
Required: Yes
Type: Bearer Token (JWT)
Request
Headers
Content-Type: application/json
Authorization: Bearer <your_jwt_token>
Body Parameters
token
string
Yes
The mint address of the token
amount
string
Yes
The amount to swap in the initial transaction
Example Request:
{
"token": "TokenMintAddress123...",
"amount": "1000000000"
}
Response
Success Response
Status Code: 200 OK
Content-Type: application/json
interface MintResponse {
serializedTransaction: string; // base58 encoded serialized transaction
}
Error Responses
Token Not Found
Status Code: 404
"token not found"
Server Error
Status Code: 500
{
"error": "An internal error occurred. Please try again later."
}
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.cybers.app/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
The created transaction includes multiple instructions:
1. Create Token Account
Creates the token mint account
Allocates space for mint data
Pays for rent exemption
Initialize Mint
Sets decimals (fixed at 9)
Sets mint and freeze authorities
Initializes supply
Create Associated Token Account
Creates the token account for the minter
Links it to the mint
Mint Tokens
Mints the initial supply
Amount is set to config.constants.tokenSupply * 10^9
Create Metadata
Creates on-chain metadata
Sets name, symbol, and URI
Makes metadata immutable
Revoke Authorities
Removes mint authority
Removes freeze authority
Create Liquidity Pool
Sets up initial liquidity pool
Adds initial liquidity
Execute Initial Swap
Performs initial token swap
Sets initial price
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
1. Transaction Handling
async function handleMintTransaction(
tokenMintAddress: string,
amount: string
) {
try {
// 1. Get the transaction
const { serializedTransaction } = await getMintTransaction(
tokenMintAddress,
amount
);
// 2. Add retry logic for network issues
const MAX_RETRIES = 3;
let retries = 0;
while (retries < MAX_RETRIES) {
try {
const signature = await sendAndConfirmTransaction(
serializedTransaction
);
return signature;
} catch (error) {
retries++;
if (retries === MAX_RETRIES) throw error;
await new Promise(resolve => setTimeout(resolve, 1000 * retries));
}
}
} catch (error) {
console.error('Mint transaction failed:', error);
throw error;
}
}
Error Handling
function validateMintParams(
tokenMintAddress: string,
amount: string
) {
if (!tokenMintAddress || !amount) {
throw new Error('Missing required parameters');
}
const amountNum = Number(amount);
if (isNaN(amountNum) || amountNum <= 0) {
throw new Error('Invalid amount');
}
try {
new PublicKey(tokenMintAddress);
} catch {
throw new Error('Invalid token mint address');
}
}
Transaction Monitoring
async function monitorMintTransaction(signature: string) {
const MAX_ATTEMPTS = 60; // 1 minute with 1s intervals
let attempts = 0;
while (attempts < MAX_ATTEMPTS) {
const status = await connection.getSignatureStatus(signature);
if (status.value?.confirmationStatus === 'confirmed') {
return true;
}
await new Promise(resolve => setTimeout(resolve, 1000));
attempts++;
}
throw new Error('Transaction confirmation timeout');
}
Last updated