Skip to main content

  1. Mint To creates new tokens of a mint and deposits them to a specified token account.
  2. Before we can mint any tokens, we need an initialized mint account (SPL, Token 2022 or Light) for which we hold the mint authority.
mintToInterface mints tokens to token accounts in a single call.The function auto-detects the token program (SPL, Token 2022, or Light) from the mint address.Compare to SPL:
Find the source code here.
1

Mint Tokens to Light Token Account

Install packages in your working directory:
npm install @lightprotocol/stateless.js@beta \
            @lightprotocol/compressed-token@beta
Install the CLI globally:
npm install -g @lightprotocol/zk-compression-cli@beta
# start local test-validator in a separate terminal
light test-validator
In the code examples, use createRpc() without arguments for localnet.
import "dotenv/config";
import { Keypair } from "@solana/web3.js";
import { createRpc } from "@lightprotocol/stateless.js";
import {
    createMintInterface,
    createAtaInterface,
    mintToInterface,
    getAssociatedTokenAddressInterface,
} from "@lightprotocol/compressed-token";
import { homedir } from "os";
import { readFileSync } from "fs";

// devnet:
const RPC_URL = `https://devnet.helius-rpc.com?api-key=${process.env.API_KEY!}`;
const rpc = createRpc(RPC_URL);
// localnet:
// const rpc = createRpc();

const payer = Keypair.fromSecretKey(
    new Uint8Array(
        JSON.parse(readFileSync(`${homedir()}/.config/solana/id.json`, "utf8"))
    )
);

(async function () {
    const { mint } = await createMintInterface(rpc, payer, payer, null, 9);

    const recipient = Keypair.generate();
    await createAtaInterface(rpc, payer, mint, recipient.publicKey);

    const destination = getAssociatedTokenAddressInterface(mint, recipient.publicKey);
    const tx = await mintToInterface(rpc, payer, mint, destination, payer, 1_000_000_000);

    console.log("Tx:", tx);
})();

Next Steps

Learn to use the transfer interface for Light Token <> SPL token transfers