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.
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
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
- Proof of Concept: Demonstrating token creation on Solana
- Supply Management: Tracking total token supply with mint events
- Authority Control: Learning about access control in blockchain programs
- Educational Tool: Understanding Solana program development
- Loyalty Points System: Businesses could create tokens for customer rewards
- Gaming Tokens: Game developers could mint in-game currency
- Community Tokens: DAOs could create governance tokens
- Event Tickets: Mint limited supply tokens representing tickets
- Achievement Badges: Non-transferable tokens for accomplishments
Devnet: 5ikZo3dXp81Mj9qDegbGNeMJBtzu1DSw6UeZK8o3XKgs
- 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
Before you begin, ensure you have the following installed:
- Rust
- Solana CLI
- Anchor Framework
- Node.js (v16 or higher)
- Yarn
# Create a new Anchor project
anchor init my-token
cd my-tokenmy-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
The program implements two main functions:
-
create_token: Creates a new token with specified name and symbol- Initializes token configuration account
- Sets the token authority
- Starts with zero total supply
-
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
- Authority Control: Only the token creator can mint new tokens
- Overflow Protection: Uses
checked_addto prevent integer overflow - Input Validation: Ensures mint amount is greater than zero
- Custom Error Handling: Clear error messages for different failure scenarios
# Install node modules
yarn install
# Install test dependencies
npm install --save-dev chai @types/chaianchor buildThis compiles the Rust program and generates TypeScript types for client interaction.
# Run tests with built-in validator
anchor testTest output:
my-token
✔ Creates a token (227ms)
✔ Mints tokens (468ms)
✔ Prevents unauthorized minting
3 passing (714ms)
# Switch to devnet
solana config set --url devnet
# Check your wallet balance
solana balance# Request 2 SOL from faucet
solana airdrop 2# Build the program
anchor build
# Deploy to devnet
anchor deploy --provider.cluster devnetDeployment output:
Deploying cluster: https://api.devnet.solana.com
Program Id: 5ikZo3dXp81Mj9qDegbGNeMJBtzu1DSw6UeZK8o3XKgs
Deploy success
// 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();You can view your deployed program on Solana Explorer: https://explorer.solana.com/address/5ikZo3dXp81Mj9qDegbGNeMJBtzu1DSw6UeZK8o3XKgs?cluster=devnet
TokenConfig Account
authority: Pubkey (32 bytes) - Who can mint tokensname: String - Token namesymbol: String - Token symboltotal_supply: u64 (8 bytes) - Current token supply
-
CreateToken
- Creates new TokenConfig account
- Sets initial token parameters
- Assigns minting authority
-
MintTokens
- Increases total supply
- Requires authority signature
- Validates amount > 0
Unauthorized: Caller is not the token authorityInvalidAmount: Mint amount must be greater than zeroOverflow: Token supply would overflow u64 max
# 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-validatorThis is a learning project with intentional limitations:
- ❌ No user balances tracking
- ❌ No transfer functionality
- ❌ No burning mechanism
- ❌ No decimal support
- ❌ Not SPL Token compatible
- User Balances: Add accounts to track individual token holdings
- Transfer Function: Enable token transfers between users
- Burn Mechanism: Allow token destruction to reduce supply
- Decimals Support: Handle fractional token amounts
- SPL Token Integration: Make compatible with Solana's token standard
- Metadata Support: Add token logos, descriptions, and URIs
- Multi-signature Authority: Require multiple signatures for minting
- Minting Caps: Set maximum supply limits
- Time-locked Minting: Restrict minting to specific time periods
- Fee Distribution: Implement transaction fees for token operations
- Web Interface: Create a React/Next.js frontend
- Wallet Integration: Support Phantom, Solflare, etc.
- Token Explorer: Display token statistics and history
- Admin Dashboard: Management interface for token authorities
This project is open source and available under the MIT License.