ReviewOS

stacks/ts-tokens

public
Clone

Push over the same URL. A password will not work: create a token under access tokens and use it in place of one.

main
· 24 branches · 232 commits

Mirrored from stacksjs/ts-tokens · syncing is switched off

README.md

Social Card of this repo

npm version GitHub Actions Commitizen friendly

ts-tokens

A TypeScript library, CLI, and components for managing fungible and non-fungible tokens on Solana.

Features

  • 🪙 Fungible Tokens: Create, mint, transfer, and burn SPL tokens
  • 🎨 NFT Collections: Full NFT lifecycle management with collections
  • 🍬 Candy Machine: Launch NFT drops with guards and allowlists
  • 🗜️ Compressed NFTs: Cost-effective cNFTs with Merkle trees
  • 📦 Zero Dependencies: Only official Solana packages required
  • 🚀 Fast: Built with performance in mind
  • 📜 TypeScript: Fully typed with excellent DX
  • 🛠️ Library & CLI: Use programmatically or from the command line
  • ⚛️ React Components: Ready-to-use wallet and token components
  • 💚 Vue Components: Vue 3 components for token UIs
  • 🔐 Security First: Built-in security checks and best practices

Install

# Using bun (recommended)
bun add ts-tokens

# Using npm
npm install ts-tokens

# Using yarn
yarn add ts-tokens

# Using pnpm
pnpm add ts-tokens

Quick Start

Create a Fungible Token

import { createToken, mintTokens } from 'ts-tokens'

// Create a new token
const token = await createToken({
  name: 'My Token',
  symbol: 'MTK',
  decimals: 9,
  initialSupply: 1_000_000_000n, // 1 billion tokens
})

console.log(`Token created: ${token.mint}`)

// Mint more tokens
await mintTokens({
  mint: token.mint,
  amount: 500_000_000n,
  destination: recipientAddress,
})

Create an NFT Collection

import { createCollection, mintNFT } from 'ts-tokens'

// Create a collection
const collection = await createCollection({
  name: 'My NFT Collection',
  symbol: 'MNFT',
  uri: 'https://arweave.net/collection-metadata.json',
  sellerFeeBasisPoints: 500, // 5% royalty
})

// Mint an NFT to the collection
const nft = await mintNFT({
  name: 'NFT #1',
  symbol: 'MNFT',
  uri: 'https://arweave.net/nft-1-metadata.json',
  collection: collection.mint,
  sellerFeeBasisPoints: 500,
})

console.log(`NFT minted: ${nft.mint}`)

CLI Usage

# Configure your wallet
tokens config init

# Create a token
tokens create --name "My Token" --symbol "MTK" --decimals 9

# Mint tokens
tokens mint <mint-address> 1000000 --to <recipient>

# Create an NFT collection
tokens collection create --name "My Collection" --symbol "MNFT"

# Mint an NFT
tokens nft create --name "NFT #1" --collection <collection-address>

# Check balances
tokens balance <mint-address>

Configuration

Create a tokens.config.ts file in your project root:

import { defineConfig } from 'ts-tokens'

export default defineConfig({
  // Blockchain settings
  chain: 'solana',
  network: 'devnet', // 'mainnet-beta' | 'devnet' | 'testnet' | 'localnet'

  // Wallet configuration
  wallet: {
    keypairPath: '~/.config/solana/id.json',
  },

  // Storage provider for metadata
  storageProvider: 'arweave', // 'arweave' | 'ipfs' | 'shadow-drive'

  // Transaction settings
  commitment: 'confirmed',
  autoCreateAccounts: true,

  // Security
  securityChecks: true,
  dryRun: false,
})

Packages

PackageDescription
ts-tokensCore library and CLI
@ts-tokens/reactReact components and hooks
@ts-tokens/vueVue 3 components and composables
ts-governanceDAO governance and voting

Documentation

Why ts-tokens

Zero External Dependencies: Unlike Metaplex SDKs, ts-tokens only depends on official Solana packages (@solana/web3.js, @solana/spl-token). We implement all program interactions using raw instructions.

Better Developer Experience: Simpler APIs, better error messages, and TypeScript-first design.

Full Feature Parity: Everything you can do with Metaplex, you can do with ts-tokens—often with less code.

// Metaplex: 3+ instructions, multiple accounts
// ts-tokens: 1 instruction, clean API
await createNFT({
  name: 'My NFT',
  royalty: 5, // 5% - not basis points!
})

Testing

bun test

Changelog

Please see our releases page for more information on what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Community

For help, discussion about best practices, or any other conversation that would benefit from being searchable:

Discussions on GitHub

For casual chit-chat with others using this package:

Join the Stacks Discord Server

Postcardware

“Software that is free, but hopes for a postcard.” We love receiving postcards from around the world showing where tokens is being used! We showcase them on our website too.

Our address: Stacks.js, 12665 Village Ln #2306, Playa Vista, CA 90094, United States 🌎

Sponsors

We would like to extend our thanks to the following sponsors for funding Stacks development. If you are interested in becoming a sponsor, please reach out to us.

License

The MIT License (MIT). Please see LICENSE for more information.

Made with 💙

[codecov-href]: https://codecov.io/gh/stacksjs/ts-tokens -->