createNewToken
This function creates a new token on the Solana blockchain using the Token-2022 program.
Usage
page.tsx
import { useConnection, useWallet } from "@solana/wallet-adapter-react";
import { createNewToken } from "@okito/sdk";
const {connection} = useConnection();
const wallet = useWallet();
const tokenData = {
name: "My Token", // The name of your token (max 32 characters)
symbol: "MTK", // The symbol for your token (max 10 characters)
imageUrl: "https://example.com/image.png", // A URL pointing to the image to your token
initialSupply: 1000000000, // The initial supply of tokens (in base units)
decimals: 9, // Number of decimal places your token will have
freezeAuthority: false,
description: "This is my token",
externalUrl: "https://example.com", // (Optional) An external URL for your project
}
const tokenResult = await createNewToken(wallet, connection, tokenData, {
enableLogging: true, // Structured logging with operation tracking
enableSimulation: true, // Pre-flight transaction simulation
enableMetrics: true, // Performance monitoring
strictValidation: true, // Enhanced input validation
maxRetries: 3, // Automatic retry on failure
timeoutMs: 120000, // 2-minute timeout for complex operations
confirmationStrategy: 'confirmed' // Transaction confirmation level
});
Capabilities
- Structured logging with operation IDs and context
- Optional pre-flight simulation before sending
- Fee estimation with sensible fallbacks
- Input sanitization for names, symbols, and URIs
- Balance checks and safer initial-supply handling
Parameters
Name | Type | Default |
---|---|---|
wallet | SignerWallet The wallet instance with signing capabilities. |
|
connection | Connection Solana connection instance for blockchain interaction. |
|
tokenData | TokenData Token configuration including name, symbol, decimals, and initial supply. |
|
config | OperationConfig Configuration options such as logging, retries, timeouts, and simulation. |
|
Response
Returns a OperationResult
object with comprehensive information:
Name | Type | Default |
---|---|---|
success | boolean Whether the token creation was successful. |
|
mintAddress | string The newly created token's mint address. |
|
transactionId | string The blockchain transaction ID for verification. |
|
estimatedFee | number Pre-calculated fee estimation in lamports. |
|
actualFee | number Actual transaction fee paid in lamports. |
|
confirmationTime | number Total operation time in milliseconds. |
|
error | string Error message if the operation failed (only present when success is false). |
|
Error Handling
The function provides comprehensive error handling with specific error codes:
WALLET_NOT_CONNECTED
: Wallet is not properly connectedINSUFFICIENT_FUNDS
: Insufficient SOL for transaction feesINVALID_TOKEN_DATA
: Token data validation failedNETWORK_ERROR
: Network connectivity issuesTRANSACTION_FAILED
: Transaction execution failedSIMULATION_FAILED
: Pre-flight simulation failed
Each error includes detailed context and recovery suggestions for automated handling.
Last updated on