How to Create Your Own Token on Solana Using Solana CLI and TypeScript

·

Creating your own cryptocurrency token has never been more accessible. With the rise of blockchain platforms like Solana, developers and enthusiasts can now mint custom tokens with minimal technical overhead. In this comprehensive guide, you’ll learn how to create, manage, and distribute your own Solana token using the Solana CLI and TypeScript. Whether you're building a community token, launching a project prototype, or simply exploring Web3 development, this step-by-step walkthrough will give you hands-on experience with real blockchain operations.


Understanding Solana Token Mechanics

Before diving into code, it’s essential to understand how tokens work on the Solana network. Unlike Ethereum, where each token typically requires deploying a new smart contract, Solana uses a shared SPL Token Program—a standardized protocol that allows efficient creation and management of fungible tokens without writing custom smart contracts.

Here’s a breakdown of key concepts:

🔗 Core Components of Solana Tokens

💡 Note: On Solana, every action—minting, transferring, updating metadata—is a transaction. These are recorded on-chain and can be explored publicly.

We’ll use Devnet, Solana’s public development network, which allows testing with free SOL tokens. This ensures zero financial risk during development.


Step 1: Set Up Your Development Environment

Install Solana CLI Tools

The Solana Command Line Interface (CLI) is essential for interacting with the network. Follow the official installation guide at docs.solana.com/cli/install-solana-cli-tools.

To verify installation:

solana --version

👉 Start building your Solana token with the latest developer tools


Step 2: Configure Devnet and Fund Your Wallet

Switch to the Devnet environment:

solana config set --url https://api.devnet.solana.com

Generate a new keypair (your "bank wallet"):

solana-keygen new

This stores your private key in ~/.config/solana/id.json. Keep this secure—it controls your assets.

Airdrop yourself some Devnet SOL for transaction fees:

solana airdrop 1
solana balance

You should now see a balance of 1 SOL.


Step 3: Create Your Custom Token

Use the SPL Token CLI to generate a new token:

spl-token create-token

This returns a mint address and sets the default decimal precision to 9. Your token exists—but has no supply yet.

Next, create a token account to hold the supply:

spl-token create-account [MINT_ADDRESS]

Now mint 10,000 tokens into your bank account:

spl-token mint [MINT_ADDRESS] 10000

Check your balance:

spl-token balance [MINT_ADDRESS]

Your token appears on Solana Explorer under its mint address—but shows as “Unknown Token” because metadata is missing.


Step 4: Attach Metadata Using TypeScript

To make your token recognizable in wallets like Backpack or Phantom, you need to attach metadata using Metaplex’s Token Metadata Standard.

Prerequisites

Install dependencies:

npm install @solana/web3.js @metaplex-foundation/js @solana/spl-token ts-node

Upload your token image to a decentralized storage service like IPFS or Arweave. We'll use Arweave via Metaplex’s Bundlr integration.

TypeScript Code: Upload Metadata

import {
  Connection,
  Keypair,
  PublicKey,
} from "@solana/web3.js";
import {
  Metaplex,
  keypairIdentity,
  bundlrStorage,
  UploadMetadataInput,
} from "@metaplex-foundation/js";
import { DataV2, findMetadataPda } from "@metaplex-foundation/mpl-token-metadata";
import secret from './walletSecret.json';

const endpoint = 'https://api.devnet.solana.com';
const solanaConnection = new Connection(endpoint);
const bankWalletKeyPair = Keypair.fromSecretKey(new Uint8Array(secret));
const metaplex = Metaplex.make(solanaConnection)
  .use(keypairIdentity(bankWalletKeyPair))
  .use(bundlrStorage({
    address: 'https://devnet.bundlr.network',
    providerUrl: endpoint,
  }));

const MY_TOKEN_METADATA: UploadMetadataInput = {
  name: "HippoCoin",
  symbol: "HIPP0",
  description: "This is a hippo token!",
  image: "https://ipfs.io/ipfs/bafybeidljnhkf3oaoyux7gubcl6glv5sptqvbmqpg2dgmk7lkliai5g7de?filename=DALL%C2%B7E%202023-03-16%2017.26.56%20-%20Cute%20cartoon%20hippo%20looking%20in%20front.png",
};

const ON_CHAIN_METADATA: DataV2 = {
  name: MY_TOKEN_METADATA.name,
  symbol: MY_TOKEN_METADATA.symbol,
  uri: '',
  sellerFeeBasisPoints: 0,
  creators: null,
  collection: null,
  uses: null,
  collectionDetails: null,
};

async function uploadMetadata() {
  const { uri } = await metaplex.nfts().uploadMetadata(MY_TOKEN_METADATA);
  console.log("Arweave URI:", uri);
  return uri;
}

Attach Metadata to Mint

async function createMetadataTransaction(mint: PublicKey) {
  const metadataPDA = await findMetadataPda(mint);
  const { Transaction } = require("@michaelzhangui/solana-web3.js"); // Fixed import if needed

  const tx = new Transaction().add(
    createCreateMetadataAccountV2Instruction(
      {
        metadata: metadataPDA,
        mint,
        mintAuthority: bankWalletKeyPair.publicKey,
        payer: bankWalletKeyPair.publicKey,
        updateAuthority: bankWalletKeyPair.publicKey,
      },
      {
        createMetadataAccountArgsV2: {
          data: ON_CHAIN_METADATA,
          isMutable: true,
        },
      }
    )
  );

  const txId = await sendAndConfirmTransaction(solanaConnection, tx, [bankWalletKeyPair]);
  console.log(`Metadata attached! Tx: https://explorer.solana.com/tx/${txId}?cluster=devnet`);
}

Run with:

ts-node upload-metadata.ts

After execution, your token will display its name and image in Solana Explorer and compatible wallets.


Step 5: Transfer Tokens Programmatically

Now let’s send tokens using TypeScript.

import {
  getOrCreateAssociatedTokenAccount,
  createTransferInstruction,
} from "@solana/spl-token";
import { sendAndConfirmTransaction } from "@solana/web3.js";

async function sendTokens(destinationWallet: string, amount: number) {
  const mintPublicKey = new PublicKey("[YOUR_MINT_ADDRESS]");
  const destinationPublicKey = new PublicKey(destinationWallet);

  const sourceAccount = await getOrCreateAssociatedTokenAccount(
    solanaConnection,
    bankWalletKeyPair,
    mintPublicKey,
    bankWalletKeyPair.publicKey
  );

  const destinationAccount = await getOrCreateAssociatedTokenAccount(
    solanaConnection,
    bankWalletKeyPair,
    mintPublicKey,
    destinationPublicKey
  );

  const decimals = await getNumberDecimals(mintPublicKey.toString());
  const tx = new Transaction().add(
    createTransferInstruction(
      sourceAccount.address,
      destinationAccount.address,
      bankWalletKeyPair.publicKey,
      amount * Math.pow(10, decimals)
    )
  );

  const signature = await sendAndConfirmTransaction(solanaConnection, tx, [bankWalletKeyPair]);
  console.log(`Transfer successful! https://explorer.solana.com/tx/${signature}?cluster=devnet`);
}

This function automatically creates a token account for the recipient if one doesn’t exist.

👉 Learn how to scale your token project with advanced blockchain tools


Step 6: Lock Token Supply Permanently

To ensure scarcity and trust, disable future minting:

spl-token authorize [MINT_ADDRESS] mint --disable

Once disabled:

Verify in Solana Explorer—the token will now show Fixed Supply.


Frequently Asked Questions (FAQ)

Q1: Can I create multiple tokens using the same wallet?

Yes. Each token has a unique mint address. You can create as many tokens as needed from one wallet.

Q2: What happens if I lose my wallet’s secret key?

You lose access to all associated tokens and minting rights. Always back up your id.json file securely.

Q3: Is it possible to update token metadata after locking supply?

Only if isMutable: true was set during creation. After disabling mint authority, metadata updates are blocked.

Q4: Why do I need a token account for each wallet?

Solana separates holdings by token type for security and efficiency. One wallet can hold many accounts for different tokens.

Q5: Are there costs involved in creating tokens on Devnet?

No. Devnet provides free SOL for testing. Mainnet operations require real SOL for gas fees.

Q6: Can I migrate my Devnet token to Mainnet?

Not directly. You must redeploy on Mainnet with the same parameters and re-attach metadata.


Final Thoughts

You’ve now built a fully functional Solana token—from creation and metadata attachment to programmatic transfer and supply control. This foundation empowers you to explore NFTs, DAOs, DeFi projects, or launch your own community currency.

As blockchain adoption grows, understanding core Web3 mechanics like tokenization becomes increasingly valuable. With Solana’s speed and low cost, it's an ideal platform for innovation.

👉 Discover how OKX supports developers in launching real-world blockchain applications


Core Keywords: Solana token creation, SPL Token Program, Metaplex metadata, Solana CLI, TypeScript blockchain development, decentralized storage, fixed supply token, Web3 programming