Typescript
Token2022 with Web3.js

Token2022 with Web3.js

The Non Transferable Extension

The NonTransferable extension is a Mint account extension that prevents tokens from being transferred between accounts, making them permanently bound to their current holders.

Initializing the Mint Account

To initialize the MintCloseAuthority extension on a Mint account we're going to need the initializeNonTransferableMint() function.

Here's how to create a mint with the Non Transferable extension:

ts
import { Keypair, SystemProgram, Transaction, sendAndConfirmTransaction } from "@solana/web3.js";
import {
  createInitializeMintInstruction,
  createInitializeNonTransferableMintInstruction,
  getMintLen,
  ExtensionType,
  TOKEN_2022_PROGRAM_ID,
} from "@solana/spl-token";

const mint = Keypair.generate();

// Calculate the size needed for a Mint account with Non Transferable extension
const mintLen = getMintLen([ExtensionType.NonTransferable]);

// Calculate minimum lamports required for rent exemption
const lamports = await connection.getMinimumBalanceForRentExemption(mintLen);

// Create the account with the correct size and owner
const createAccountInstruction = SystemProgram.createAccount({
  fromPubkey: keypair.publicKey,
  newAccountPubkey: mint.publicKey,
  space: mintLen,
  lamports,
  programId: TOKEN_2022_PROGRAM_ID,
});

// Initialize the Non Transferable extension
const initializeMintNonTransferable = createInitializeNonTransferableMintInstruction(
  mint.publicKey,
  TOKEN_2022_PROGRAM_ID,
);

// Initialize the mint itself
const initializeMintInstruction = createInitializeMintInstruction(
  mint.publicKey,
  6,
  keypair.publicKey,
  null,
  TOKEN_2022_PROGRAM_ID,
);

// Combine all instructions in the correct order
const transaction = new Transaction().add(
  createAccountInstruction,
  initializeMintNonTransferable,
  initializeMintInstruction,
);

const signature = await sendAndConfirmTransaction(connection, transaction, [keypair, mint]);

console.log(
  `Mint created! Check out your TX here: https://explorer.solana.com/tx/${signature}?cluster=devnet`,
);
Expand
[38 more lines]
Contents
View Source
Blueshift © 2026Commit: 3c44267