Quick Start
Mint Tokens

Mint Tokens

  • create mint, ata, mint tokens

How to Mint Tokens to a Token Account

https://beta.solpg.io/660cea45cffcf4b13384d012

Starter Code

  • open solana playground
  • starter code
client.ts
import {
  Connection,
  Transaction,
  clusterApiUrl,
  sendAndConfirmTransaction,
  Keypair,
} from "@solana/web3.js";
import {
  createMint,
  createAccount,
  TOKEN_2022_PROGRAM_ID,
  createMintToInstruction,
} from "@solana/spl-token";
 
const wallet = pg.wallet;
const connection = new Connection(clusterApiUrl("devnet"), "confirmed");
 
// Create new Mint Account
const mint = await createMint(
  connection,
  wallet.keypair, // payer
  wallet.publicKey, // mint authority
  wallet.publicKey, // freeze authority
  2, // decimals
  new Keypair(), // keypair for mint account
  null,
  TOKEN_2022_PROGRAM_ID,
);
 
// Create new Token Account, defaults to ATA
const tokenAccount = await createAccount(
  connection,
  wallet.keypair, // payer
  mint, // mint address
  wallet.publicKey, // token account owner
  null,
  null,
  TOKEN_2022_PROGRAM_ID,
);

Build Mint To Instruction

client.ts
const instruction = createMintToInstruction(
  mint, // mint address
  tokenAccount, // destination
  wallet.publicKey, // mint authority
  100, // amount
  [],
  TOKEN_2022_PROGRAM_ID,
);

Add Instruction to Transaction

client.ts
const transaction = new Transaction().add(instruction);

Send Transaction

client.ts
const transactionSignature = await sendAndConfirmTransaction(
  connection,
  transaction,
  [
    wallet.keypair, // payer, mint authority
  ],
);
client.ts
console.log(
  "\nTransaction Signature:",
  `https://explorer.solana.com/tx/${transactionSignature}?cluster=devnet`,
);
 
console.log(
  "\nToken Account: ",
  `https://explorer.solana.com/address/${tokenAccount}?cluster=devnet`,
);

Run script

Terminal
run
Output
Running client...
  client.ts:
 
Transaction Signature: https://explorer.solana.com/tx/9Hk9qVgrpE2ANVJFh7frSu9nka6QhgHFU4tBs7ueRfwxGFEnMD3WGwgidRbt8Zs5KoumEaLo9ubF2PRNEtBb26n?cluster=devnet
 
Token Account:  https://explorer.solana.com/address/E16whVPaH8R7kMETbbZRn9RQCkAyeSLYkbMPdZFaJcko?cluster=devnet