Skip to content

aneeshrem/token-launcher

Repository files navigation

Token Launcher

A Solana program built with Anchor that enables easy creation of SPL Token-2022 tokens with metadata. This program provides a simple interface to create tokens with custom metadata, mint an initial supply, and automatically disable further minting.

Features

  • Token-2022 Support: Built on the latest SPL Token-2022 standard
  • Metadata Integration: Includes name, symbol, and URI metadata
  • One-Shot Creation: Create, mint, and lock tokens in a single transaction
  • Automatic Rent Calculation: Handles rent-exempt lamports for metadata storage
  • Mint Authority Removal: Automatically disables further minting after initial creation

Program Details

  • Program ID: CVn1nLhL57hZbAELkFXMEZzMiNLf8ayrcKC3cqLWr3w2
  • Framework: Anchor
  • Token Standard: SPL Token-2022

Prerequisites

Installation

  1. Clone the repository:
git clone <repository-url>
cd token-launcher
  1. Install dependencies:
anchor build
  1. Deploy the program:
anchor deploy

Usage

Creating a Token

The program exposes a single instruction: create_token_2022

Parameters

pub struct Token2022MetadataArgs {
    pub name: String,      // Token name (e.g., "My Token")
    pub symbol: String,    // Token symbol (e.g., "MTK")
    pub uri: String,       // Metadata URI (JSON metadata)
    pub supply: u64,       // Initial token supply (before decimals)
}

Account Structure

pub struct CreateTokenAccount<'info> {
    #[account(mut)]
    pub payer: Signer<'info>,                           // Transaction fee payer
    
    #[account(
        init,
        payer = payer,
        mint::decimals = 6,
        mint::authority = payer.key(),
        extensions::metadata_pointer::authority = payer,
        extensions::metadata_pointer::metadata_address = mint,
    )]
    pub mint: InterfaceAccount<'info, Mint>,            // New token mint
    
    #[account(
        init,
        payer = payer,
        associated_token::mint = mint,
        associated_token::authority = payer,
    )]
    pub payer_token_account: InterfaceAccount<'info, TokenAccount>, // Payer's token account
    
    pub associated_token_program: Program<'info, AssociatedToken>,
    pub system_program: Program<'info, System>,
    pub token_program: Interface<'info, TokenInterface>,
}

Client Integration

TypeScript Example

import * as anchor from "@coral-xyz/anchor";
import { Program } from "@coral-xyz/anchor";
import { TokenLauncher } from "../target/types/token_launcher";

const program = anchor.workspace.TokenLauncher as Program<TokenLauncher>;

async function createToken() {
    const tokenKeypair = anchor.web3.Keypair.generate();
    
    const [payerTokenAccount] = await anchor.web3.PublicKey.findProgramAddress(
        [
            wallet.publicKey.toBuffer(),
            TOKEN_PROGRAM_ID.toBuffer(),
            tokenKeypair.publicKey.toBuffer(),
        ],
        ASSOCIATED_TOKEN_PROGRAM_ID
    );

    const tx = await program.methods
        .createToken2022({
            name: "My Token",
            symbol: "MTK",
            uri: "https://example.com/metadata.json",
            supply: new anchor.BN(1000000), // 1M tokens
        })
        .accounts({
            payer: wallet.publicKey,
            mint: tokenKeypair.publicKey,
            payerTokenAccount,
            associatedTokenProgram: ASSOCIATED_TOKEN_PROGRAM_ID,
            systemProgram: anchor.web3.SystemProgram.programId,
            tokenProgram: TOKEN_2022_PROGRAM_ID,
        })
        .signers([tokenKeypair])
        .rpc();

    console.log("Token created:", tx);
}

Rust Client Example

use anchor_client::solana_sdk::signature::{Keypair, Signer};
use anchor_client::{Client, Cluster};

let payer = Keypair::new();
let mint = Keypair::new();
let client = Client::new(Cluster::Devnet, Rc::new(payer));
let program = client.program(program_id);

let tx = program
    .request()
    .instruction(instruction::create_token_2022(
        program_id,
        Token2022MetadataArgs {
            name: "My Token".to_string(),
            symbol: "MTK".to_string(),
            uri: "https://example.com/metadata.json".to_string(),
            supply: 1_000_000,
        },
    ))
    .accounts(/* ... */)
    .signer(&mint)
    .send()?;

Token Specifications

  • Decimals: 6 (hardcoded)
  • Standard: SPL Token-2022
  • Metadata: Stored on-chain using Token-2022 metadata extension
  • Mint Authority: Automatically removed after creation
  • Supply: Fixed at creation time

Security Features

  1. Rent-Exempt Calculation: Automatically calculates and transfers required lamports for metadata storage
  2. Authority Management: Removes mint authority after initial supply creation
  3. Metadata Validation: Ensures proper metadata initialization
  4. Account Constraints: Uses Anchor's account constraints for security

Testing

Run the test suite:

anchor test

Deployment

Build the Program

anchor build

Step 1: Generate a buffer keypair

solana-keygen new -o path/to/your/buffer/token-launcher-buffer.json

Step 2: Deploy using buffer

solana program deploy --buffer path/to/your/buffer/token-launcher-buffer.json path/to/your/token-launcher/target/deploy/token_launcher.so

Deployment Notes

  • Buffer Method: Useful for large programs or when you need to deploy in multiple steps
  • Anchor Method: Simpler and handles most deployment scenarios automatically
  • Program Binary: Located at target/deploy/token_launcher.so after running anchor build
  • Buffer Benefits: Allows for staged deployments and better resource management

License

This project is licensed under the MIT License - see the LICENSE file for details.

Support

For questions and support:


Note: This program is designed for educational and development purposes. Please audit thoroughly before using in production environments.

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors