Skip to content

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

My Token - Solana Token Program

A custom token program built on Solana using the Anchor framework. This program implements a centralized token system where a single authority (the token creator) has exclusive control over minting new tokens.

What We Built

This is a basic token factory program that allows users to:

  • Create their own custom tokens with unique names and symbols
  • Mint new supply of their tokens on demand
  • Track the total supply of tokens in circulation

Token Type: Centralized Authority Token

Unlike standard SPL tokens, this program implements a simpler, educational token model where:

  • No Transfer Functionality: Tokens cannot be transferred between users (yet)
  • Single Authority: Only the token creator can mint new tokens
  • Supply Tracking: The program tracks total supply but not individual balances
  • Multiple Tokens: Each user can create multiple different tokens

Use Cases and Utility

Current Implementation Use Cases:

  1. Proof of Concept: Demonstrating token creation on Solana
  2. Supply Management: Tracking total token supply with mint events
  3. Authority Control: Learning about access control in blockchain programs
  4. Educational Tool: Understanding Solana program development

Potential Real-World Applications (with extensions):

  1. Loyalty Points System: Businesses could create tokens for customer rewards
  2. Gaming Tokens: Game developers could mint in-game currency
  3. Community Tokens: DAOs could create governance tokens
  4. Event Tickets: Mint limited supply tokens representing tickets
  5. Achievement Badges: Non-transferable tokens for accomplishments

Program ID

Devnet: 5ikZo3dXp81Mj9qDegbGNeMJBtzu1DSw6UeZK8o3XKgs

Features

  • Token Creation: Create new tokens with custom name and symbol
  • Minting: Mint new tokens (restricted to token authority)
  • Security: Built-in overflow protection and authorization checks
  • Testing: Comprehensive test suite with edge case coverage

Prerequisites

Before you begin, ensure you have the following installed:

Project Setup

1. Initialize the Project

# Create a new Anchor project
anchor init my-token
cd my-token

2. Project Structure

my-token/
├── Anchor.toml          # Project configuration
├── Cargo.toml          # Rust dependencies
├── programs/           # Solana programs
│   └── my-token/
│       └── src/
│           └── lib.rs  # Main program code
├── tests/              # JavaScript tests
│   └── my-token.ts     # Test suite
└── target/             # Build artifacts

Implementation

Program Code (programs/my-token/src/lib.rs)

The program implements two main functions:

  1. create_token: Creates a new token with specified name and symbol

    • Initializes token configuration account
    • Sets the token authority
    • Starts with zero total supply
  2. mint_tokens: Mints new tokens (authority only)

    • Validates caller is the token authority
    • Checks for valid mint amount (> 0)
    • Uses safe math to prevent overflow

Key Security Features

  • Authority Control: Only the token creator can mint new tokens
  • Overflow Protection: Uses checked_add to prevent integer overflow
  • Input Validation: Ensures mint amount is greater than zero
  • Custom Error Handling: Clear error messages for different failure scenarios

Building and Testing

1. Install Dependencies

# Install node modules
yarn install

# Install test dependencies
npm install --save-dev chai @types/chai

2. Build the Program

anchor build

This compiles the Rust program and generates TypeScript types for client interaction.

3. Run Tests

# Run tests with built-in validator
anchor test

Test output:

my-token
  ✔ Creates a token (227ms)
  ✔ Mints tokens (468ms)
  ✔ Prevents unauthorized minting

3 passing (714ms)

Deployment to Devnet

1. Configure Solana CLI

# Switch to devnet
solana config set --url devnet

# Check your wallet balance
solana balance

2. Get Devnet SOL (if needed)

# Request 2 SOL from faucet
solana airdrop 2

3. Build and Deploy

# Build the program
anchor build

# Deploy to devnet
anchor deploy --provider.cluster devnet

Deployment output:

Deploying cluster: https://api.devnet.solana.com
Program Id: 5ikZo3dXp81Mj9qDegbGNeMJBtzu1DSw6UeZK8o3XKgs
Deploy success

Interacting with the Program

Using Anchor Client (TypeScript)

// Create a token
const tx = await program.methods
  .createToken("My Token", "MTK")
  .accounts({
    tokenConfig: tokenConfigKeypair.publicKey,
    user: wallet.publicKey,
    systemProgram: SystemProgram.programId,
  })
  .signers([tokenConfigKeypair])
  .rpc();

// Mint tokens
const mintTx = await program.methods
  .mintTokens(new anchor.BN(1000))
  .accounts({
    tokenConfig: tokenConfigKeypair.publicKey,
    authority: wallet.publicKey,
  })
  .rpc();

View on Solana Explorer

You can view your deployed program on Solana Explorer: https://explorer.solana.com/address/5ikZo3dXp81Mj9qDegbGNeMJBtzu1DSw6UeZK8o3XKgs?cluster=devnet

Program Architecture

Account Structure

TokenConfig Account

  • authority: Pubkey (32 bytes) - Who can mint tokens
  • name: String - Token name
  • symbol: String - Token symbol
  • total_supply: u64 (8 bytes) - Current token supply

Instructions

  1. CreateToken

    • Creates new TokenConfig account
    • Sets initial token parameters
    • Assigns minting authority
  2. MintTokens

    • Increases total supply
    • Requires authority signature
    • Validates amount > 0

Error Codes

  • Unauthorized: Caller is not the token authority
  • InvalidAmount: Mint amount must be greater than zero
  • Overflow: Token supply would overflow u64 max

Development Commands

# Start local validator
solana-test-validator

# View logs
solana logs

# Check program deployment
solana program show 5ikZo3dXp81Mj9qDegbGNeMJBtzu1DSw6UeZK8o3XKgs

# Run tests in watch mode
anchor test --skip-local-validator

Limitations of Current Implementation

This is a learning project with intentional limitations:

  • ❌ No user balances tracking
  • ❌ No transfer functionality
  • ❌ No burning mechanism
  • ❌ No decimal support
  • ❌ Not SPL Token compatible

Next Steps to Make It Production-Ready

Essential Features:

  1. User Balances: Add accounts to track individual token holdings
  2. Transfer Function: Enable token transfers between users
  3. Burn Mechanism: Allow token destruction to reduce supply
  4. Decimals Support: Handle fractional token amounts

Advanced Features:

  1. SPL Token Integration: Make compatible with Solana's token standard
  2. Metadata Support: Add token logos, descriptions, and URIs
  3. Multi-signature Authority: Require multiple signatures for minting
  4. Minting Caps: Set maximum supply limits
  5. Time-locked Minting: Restrict minting to specific time periods
  6. Fee Distribution: Implement transaction fees for token operations

UI/UX Improvements:

  1. Web Interface: Create a React/Next.js frontend
  2. Wallet Integration: Support Phantom, Solflare, etc.
  3. Token Explorer: Display token statistics and history
  4. Admin Dashboard: Management interface for token authorities

License

This project is open source and available under the MIT License.

Resources

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages