ClearMint SDK

Production-grade TypeScript SDK for deterministic token minting on Solana. Built for protocol teams and infrastructure builders.

Installation

npm

npm install @clearmint/sdk @solana/web3.js

The SDK requires Node.js 16+ and is fully typed with TypeScript support.

Quick Start

Basic Usage

import { ClearMint } from '@clearmint/sdk';
import { Connection, Keypair } from '@solana/web3.js';

// Initialize connection
const connection = new Connection('https://api.mainnet-beta.solana.com');
const wallet = Keypair.generate();

// Create ClearMint client
const client = new ClearMint({
  connection,
  wallet,
});

// Mint a token
const result = await client.mintToken({
  name: 'Protocol Token',
  symbol: 'PTK',
  totalSupply: '1000000',
  decimals: 9,
});

console.log('Token mint address:', result.mintAddress);
console.log('Transaction signature:', result.signature);

Core Methods

mintToken()

Create a new SPL token with specified parameters

Parameters

namestringToken name
symbolstringToken symbol
totalSupplystringTotal token supply
decimalsnumberToken decimals (0-9)
mintAuthority?PublicKey | nullMint authority address
freezeAuthority?PublicKey | nullFreeze authority address
immutable?booleanMake metadata immutable

Returns

Promise<MintResult>

previewMint()

Preview mint operation without executing

Parameters

paramsMintParamsMint parameters

Returns

Promise<MintPreview>

getTokenInfo()

Retrieve token information by mint address

Parameters

mintAddressPublicKeyToken mint address

Returns

Promise<TokenInfo>

updateAuthority()

Update mint or freeze authority

Parameters

mintAddressPublicKeyToken mint address
authorityType'mint' | 'freeze'Authority type
newAuthorityPublicKey | nullNew authority address

Returns

Promise<UpdateResult>

Error Handling

The ClearMint SDK provides typed error responses for all operations, enabling deterministic error handling in your application.

import { ClearMint, ClearMintError } from '@clearmint/sdk';

try {
  const result = await client.mintToken({
    name: 'Protocol Token',
    symbol: 'PTK',
    totalSupply: '1000000',
    decimals: 9,
  });
  
  console.log('Token minted:', result.mintAddress);
} catch (error) {
  if (error instanceof ClearMintError) {
    switch (error.code) {
      case 'INVALID_PARAMS':
        console.error('Invalid parameters:', error.message);
        break;
      case 'INSUFFICIENT_BALANCE':
        console.error('Insufficient SOL balance');
        break;
      case 'TRANSACTION_FAILED':
        console.error('Transaction failed:', error.details);
        break;
      default:
        console.error('Unknown error:', error);
    }
  }
}

Error Codes

INVALID_PARAMSInvalid input parameters provided
INSUFFICIENT_BALANCEWallet has insufficient SOL for transaction
TRANSACTION_FAILEDOn-chain transaction execution failed
WALLET_NOT_CONNECTEDNo wallet connection detected
NETWORK_ERRORRPC network communication error

Advanced Usage

Custom Authority Configuration

import { PublicKey } from '@solana/web3.js';

// Mint with custom authorities
const result = await client.mintToken({
  name: 'DAO Token',
  symbol: 'DAO',
  totalSupply: '10000000',
  decimals: 9,
  mintAuthority: new PublicKey('YOUR_MINT_AUTHORITY_ADDRESS'),
  freezeAuthority: new PublicKey('YOUR_FREEZE_AUTHORITY_ADDRESS'),
});

// Mint with renounced authority (fixed supply)
const fixedSupplyToken = await client.mintToken({
  name: 'Fixed Token',
  symbol: 'FIXED',
  totalSupply: '1000000',
  decimals: 9,
  mintAuthority: null, // Renounced - no more minting possible
});

Transaction Preview

Preview transaction details before execution to ensure parameters are correct.

const preview = await client.previewMint({
  name: 'Protocol Token',
  symbol: 'PTK',
  totalSupply: '1000000',
  decimals: 9,
});

console.log('Estimated cost:', preview.estimatedCost);
console.log('Token parameters:', preview.parameters);
console.log('Authorities:', preview.authorities);

// Execute if preview looks correct
if (preview.estimatedCost < maxAllowedCost) {
  const result = await client.executeMint(preview);
}

Immutable Token Creation

Create tokens with immutable metadata to prevent any future modifications.

const immutableToken = await client.mintToken({
  name: 'Immutable Protocol Token',
  symbol: 'IPT',
  totalSupply: '1000000',
  decimals: 9,
  immutable: true, // Metadata cannot be changed after creation
});