1
Freeze one account
Freezing targets a single holder. Use it when one account needs to stop and the
rest of the token should keep working: a suspected compromise, a client under
investigation, or an account pending new documents. Token ACL holds the freeze
authority, so the freeze goes through it, signed by the config authority. Save
this as Confirm the holder cannot transfer. Run Then thaw it. This is the authority thaw, which does not ask the gate. Save
this as Freezing on its own leaves the wallet on the list, so its account can still be
thawed through the gate. Removing the wallet from the list is offboarding, the
last step on this page.
freeze.ts (in Rust, src/bin/freeze.rs) and run it with $HOLDER.- Mosaic SDK
- Kit
- Web3.js v3
- Rust
Mosaic SDK
// npx tsx freeze.ts <wallet>
import { address } from "@solana/kit";
import { getFreezeWalletTransaction } from "@solana/mosaic-sdk";
import { arg, env, loadSigner, rpc, sendMessage } from "./common";
// The Token ACL config authority is the key that created the mint.
const payer = await loadSigner("tokenization-demo");
// Freezes the wallet's associated token account through Token ACL.
await sendMessage(
await getFreezeWalletTransaction({
rpc,
payer,
authority: payer,
wallet: address(arg(1, "the wallet to freeze")),
mint: address(env("MINT")),
}),
);
Freezing the holder’s account
Output
Signature: 3JutY32kjEE9LMD6L7WJ7eW479bgfY9aSdQekwsHxuKQ1Y4kWRsyinin6RBuWESKfff4EzcjiirbyVWMamdDSwND
Kit
// npx tsx freeze.ts <wallet>
import { address } from "@solana/kit";
import {
findAssociatedTokenPda,
TOKEN_2022_PROGRAM_ADDRESS,
} from "@solana-program/token-2022";
import { findMintConfigPda, getFreezeInstruction } from "@solana/token-acl-sdk";
import { arg, env, loadSigner, send } from "./common";
// The Token ACL config authority is the key that created the mint.
const payer = await loadSigner("tokenization-demo");
const mint = address(env("MINT"));
const [tokenAccount] = await findAssociatedTokenPda({
mint,
owner: address(arg(1, "the wallet to freeze")),
tokenProgram: TOKEN_2022_PROGRAM_ADDRESS,
});
const [mintConfig] = await findMintConfigPda({ mint });
// Token ACL holds the mint's freeze authority; its config authority signs.
await send(payer, [
getFreezeInstruction({ authority: payer, mint, tokenAccount, mintConfig }),
]);
Freezing the holder’s account
Output
Signature: 3C5y6aZm3bDPXrdYPjPG6hTFYVWPwEuRpBn94s6eFjVuMd58c9VashY8dWZeVzy683ZjFnTarPR3apE94hDBXHx9
Web3.js v3
// npx tsx freeze.ts <wallet>
import {
findAssociatedTokenPda,
TOKEN_2022_PROGRAM_ADDRESS,
} from "@solana-program/token-2022";
import { findMintConfigPda, getFreezeInstruction } from "@solana/token-acl-sdk";
import { addressOf, arg, env, loadKeypair, send } from "./common";
// The Token ACL config authority is the key that created the mint.
const payer = await loadKeypair("tokenization-demo");
const mint = addressOf(env("MINT"));
const [tokenAccount] = await findAssociatedTokenPda({
mint,
owner: addressOf(arg(1, "the wallet to freeze")),
tokenProgram: TOKEN_2022_PROGRAM_ADDRESS,
});
const [mintConfig] = await findMintConfigPda({ mint });
// Token ACL holds the mint's freeze authority; its config authority signs.
await send(
[payer],
[getFreezeInstruction({ authority: payer, mint, tokenAccount, mintConfig })],
);
Freezing the holder’s account
Output
Signature: 5GVCzqEEDi6vjMro8GPwJrL8ob7QVNfRXRVgDztYHRSTkEjeWoY6zcn6kyqPKpayTAfHzco46kC13gRNMGCafE3a
Rust
// cargo run --release --bin freeze -- <wallet>
use anyhow::Result;
use gated_token::{acl, arg_pubkey, ata, env, load_keypair, rpc, send};
use solana_sdk::signature::Signer;
#[tokio::main]
async fn main() -> Result<()> {
let rpc = rpc();
// The Token ACL config authority is the key that created the mint.
let payer = load_keypair("tokenization-demo")?;
let mint = env("MINT")?;
let token_account = ata(&mint, &arg_pubkey(1, "the wallet to freeze")?);
// Token ACL holds the mint's freeze authority; its config authority signs.
send(
&rpc,
&[&payer],
&[acl::freeze(&payer.pubkey(), &mint, &token_account)],
)
.await
}
Freezing the holder’s account
Output
Signature: 5kPkS4Hs34xvWGLGE9k2Kfr81USmoreeADRL8MzPVLzKGwbYKNUtXG1g2LWtmk5Em66auGrHcmkPDvzyMbvCXcmh
transfer.ts again with $OUTSIDER 1.
The transfer fails on the source account being frozen, even though the
recipient is on the list with a thawed account. Custom program error 0x11
(17) is Token-2022’s AccountFrozen:- Mosaic SDK
- Kit
- Web3.js v3
- Rust
Mosaic SDK
// npx tsx transfer.ts <recipient> <amount>
import { address } from "@solana/kit";
import { createTransferTransaction } from "@solana/mosaic-sdk";
import { arg, env, loadSigner, rpc, sendMessage } from "./common";
// The holder signs and pays for its own transfer.
const holder = await loadSigner("demo-holder");
const mint = address(env("MINT"));
// Creates the recipient's token account if it is missing and thaws it
// through the gate before the transfer, so the gate decides whether the
// recipient may hold the token.
await sendMessage(
await createTransferTransaction({
rpc,
mint,
from: holder.address,
to: address(arg(1, "the recipient wallet")),
feePayer: holder,
authority: holder,
amount: arg(2, "the amount"),
}),
);
Sending 1 from the frozen holder account
Output
Failed: Program TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb failed: custom program error: 0x11
Kit
// npx tsx transfer.ts <recipient> <amount>
import { address } from "@solana/kit";
import {
fetchMint,
findAssociatedTokenPda,
getTransferCheckedInstruction,
TOKEN_2022_PROGRAM_ADDRESS,
} from "@solana-program/token-2022";
import { arg, env, loadSigner, rpc, send, toBaseUnits } from "./common";
import { openThroughGate } from "./gate";
// The holder signs and pays for its own transfer.
const holder = await loadSigner("demo-holder");
const mint = address(env("MINT"));
const list = address(env("LIST"));
const { data } = await fetchMint(rpc, mint);
const [source] = await findAssociatedTokenPda({
mint,
owner: holder.address,
tokenProgram: TOKEN_2022_PROGRAM_ADDRESS,
});
// The thaw is where an unlisted recipient fails: the gate rejects the owner
// and the whole transaction is dropped before any token moves.
const { tokenAccount: destination, instructions } = await openThroughGate(
holder,
mint,
address(arg(1, "the recipient wallet")),
list,
);
await send(holder, [
...instructions,
getTransferCheckedInstruction({
source,
mint,
destination,
authority: holder,
amount: toBaseUnits(arg(2, "the amount"), data.decimals),
decimals: data.decimals,
}),
]);
Sending 1 from the frozen holder account
Output
Failed: Program TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb failed: custom program error: 0x11
Web3.js v3
// npx tsx transfer.ts <recipient> <amount>
import { PublicKey } from "@solana/web3.js";
import {
findAssociatedTokenPda,
getMintDecoder,
getTransferCheckedInstruction,
TOKEN_2022_PROGRAM_ADDRESS,
} from "@solana-program/token-2022";
import {
addressOf,
arg,
connection,
env,
loadKeypair,
send,
toBaseUnits,
} from "./common";
import { openThroughGate } from "./gate";
// The holder signs and pays for its own transfer.
const holder = await loadKeypair("demo-holder");
const mint = addressOf(env("MINT"));
const list = addressOf(env("LIST"));
const mintAccount = await connection.getAccountInfo(new PublicKey(mint));
const { decimals } = getMintDecoder().decode(mintAccount!.data);
const [source] = await findAssociatedTokenPda({
mint,
owner: holder.publicKey.toBase58(),
tokenProgram: TOKEN_2022_PROGRAM_ADDRESS,
});
// The thaw is where an unlisted recipient fails: the gate rejects the owner
// and the whole transaction is dropped before any token moves.
const { tokenAccount: destination, instructions } = await openThroughGate(
holder,
mint,
addressOf(arg(1, "the recipient wallet")),
list,
);
await send(
[holder],
[
...instructions,
getTransferCheckedInstruction({
source,
mint,
destination,
authority: holder,
amount: toBaseUnits(arg(2, "the amount"), decimals),
decimals,
}),
],
);
Sending 1 from the frozen holder account
Output
Failed: Program TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb failed: custom program error: 0x11
Rust
// cargo run --release --bin transfer -- <recipient> <amount>
use anyhow::Result;
use gated_token::{
acl, arg, arg_pubkey, ata, env, load_keypair, mint_decimals, rpc, send, to_base_units,
TOKEN_2022,
};
use solana_sdk::signature::Signer;
use spl_token_2022_interface::instruction::transfer_checked;
#[tokio::main]
async fn main() -> Result<()> {
let rpc = rpc();
// The holder signs and pays for its own transfer.
let holder = load_keypair("demo-holder")?;
let mint = env("MINT")?;
let list = env("LIST")?;
let recipient = arg_pubkey(1, "the recipient wallet")?;
let decimals = mint_decimals(&rpc, &mint).await?;
// The thaw is where an unlisted recipient fails: the gate rejects the
// owner and the whole transaction is dropped before any token moves.
let (destination, mut instructions) =
acl::open_through_gate(&rpc, &holder.pubkey(), &mint, &recipient, &list).await?;
instructions.push(transfer_checked(
&TOKEN_2022,
&ata(&mint, &holder.pubkey()),
&mint,
&destination,
&holder.pubkey(),
&[],
to_base_units(&arg(2, "the amount")?, decimals)?,
decimals,
)?);
send(&rpc, &[&holder], &instructions).await
}
Sending 1 from the frozen holder account
Output
Failed: Program TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb failed: custom program error: 0x11
thaw.ts (in Rust, src/bin/thaw.rs) and run it with $HOLDER.- Mosaic SDK
- Kit
- Web3.js v3
- Rust
Mosaic SDK
// npx tsx thaw.ts <wallet>
import { address } from "@solana/kit";
import { getThawTransaction, resolveTokenAccount } from "@solana/mosaic-sdk";
import { arg, env, loadSigner, rpc, sendMessage } from "./common";
const payer = await loadSigner("tokenization-demo");
// Thaw takes the token account, so look up the wallet's account first.
const { tokenAccount } = await resolveTokenAccount(
rpc,
address(arg(1, "the wallet to thaw")),
address(env("MINT")),
);
await sendMessage(
await getThawTransaction({ rpc, payer, authority: payer, tokenAccount }),
);
Thawing the holder’s account
Output
Signature: 3HmxUThvXCurmkZm6CbGa1Beu7ethtQz9vELmFrYYgHge45Rp71GWuEhk3q1F9MMvhA4kTam4VxzyCuYQ7rcpN9S
Kit
// npx tsx thaw.ts <wallet>
import { address } from "@solana/kit";
import {
findAssociatedTokenPda,
TOKEN_2022_PROGRAM_ADDRESS,
} from "@solana-program/token-2022";
import { findMintConfigPda, getThawInstruction } from "@solana/token-acl-sdk";
import { arg, env, loadSigner, send } from "./common";
const payer = await loadSigner("tokenization-demo");
const mint = address(env("MINT"));
const [tokenAccount] = await findAssociatedTokenPda({
mint,
owner: address(arg(1, "the wallet to thaw")),
tokenProgram: TOKEN_2022_PROGRAM_ADDRESS,
});
const [mintConfig] = await findMintConfigPda({ mint });
// The authority thaw. Unlike the permissionless thaw, it does not ask the
// gate.
await send(payer, [
getThawInstruction({ authority: payer, mint, tokenAccount, mintConfig }),
]);
Thawing the holder’s account
Output
Signature: m2mffJz7xP3wT52rS4xqUsinLqhCK5Mbia7HcRyCWYaobQfXg4kea3cUQ7ncy24jpHctocynCsRXa9BeGfjfFoR
Web3.js v3
// npx tsx thaw.ts <wallet>
import {
findAssociatedTokenPda,
TOKEN_2022_PROGRAM_ADDRESS,
} from "@solana-program/token-2022";
import { findMintConfigPda, getThawInstruction } from "@solana/token-acl-sdk";
import { addressOf, arg, env, loadKeypair, send } from "./common";
// The Token ACL config authority is the key that created the mint.
const payer = await loadKeypair("tokenization-demo");
const mint = addressOf(env("MINT"));
const [tokenAccount] = await findAssociatedTokenPda({
mint,
owner: addressOf(arg(1, "the wallet to thaw")),
tokenProgram: TOKEN_2022_PROGRAM_ADDRESS,
});
const [mintConfig] = await findMintConfigPda({ mint });
// The authority thaw. Unlike the permissionless thaw, it does not ask the
// gate.
await send(
[payer],
[getThawInstruction({ authority: payer, mint, tokenAccount, mintConfig })],
);
Thawing the holder’s account
Output
Signature: cxAGCNHsrUYmzZxLckpH6sFTmvJBYx5Des77o8xymfEpFdDt6CwDxhHLnWNckoBVgyvNCVpupoiDvQWt5SPMh4Q
Rust
// cargo run --release --bin thaw -- <wallet>
use anyhow::Result;
use gated_token::{acl, arg_pubkey, ata, env, load_keypair, rpc, send};
use solana_sdk::signature::Signer;
#[tokio::main]
async fn main() -> Result<()> {
let rpc = rpc();
// The Token ACL config authority is the key that created the mint.
let payer = load_keypair("tokenization-demo")?;
let mint = env("MINT")?;
let token_account = ata(&mint, &arg_pubkey(1, "the wallet to thaw")?);
// The authority thaw. Unlike the permissionless thaw, it does not ask the
// gate.
send(
&rpc,
&[&payer],
&[acl::thaw(&payer.pubkey(), &mint, &token_account)],
)
.await
}
Thawing the holder’s account
Output
Signature: fKNS3Uj5WAi1jHtjqQGrZr5ukATnkWT26WaeZbZ7zkeKXNVq6ExyCeXSPt2BXKcNoMQW3VZ4AGzvQQjLFxJEaDo
2
Pause the whole token
Pausing halts mint, burn, and transfer activity for every holder at once. This
is the incident-response control, so its authority needs to be reachable on
the timescale an incident requires. Save this as While the token is paused, a transfer fails with custom program error Then resume. Save this as
pause.ts (in Rust,
src/bin/pause.rs) and run it.- Mosaic SDK
- Kit
- Web3.js v3
- Rust
Mosaic SDK
// npx tsx pause.ts
import { address } from "@solana/kit";
import { createPauseTransaction, getTokenPauseState } from "@solana/mosaic-sdk";
import { env, loadSigner, rpc, sendMessage } from "./common";
const payer = await loadSigner("tokenization-demo");
// The pause authority is its own key, from step 1 of create the mint.
const pauseAuthority = await loadSigner("demo-authorities/pause");
const mint = address(env("MINT"));
// Halts mint, burn, and transfer activity for every holder of the token.
const { transactionMessage } = await createPauseTransaction(rpc, {
mint,
pauseAuthority,
feePayer: payer,
});
await sendMessage(transactionMessage);
console.log("Paused:", await getTokenPauseState(rpc, mint));
Pausing the token
Output
Signature: 33qj4KZSgAnq6XkWXM1JX86T3UPheTogUJGGYDaUnQrDoPL6LVrZzxPZShpNBkpW8veBYXjWF2Z9wihQnTf7umjE
Paused: true
Kit
// npx tsx pause.ts
import { address } from "@solana/kit";
import { fetchMint, getPauseInstruction } from "@solana-program/token-2022";
import { env, loadSigner, rpc, send } from "./common";
const payer = await loadSigner("tokenization-demo");
// The pause authority is its own key, from step 1 of create the mint.
const pauseAuthority = await loadSigner("demo-authorities/pause");
const mint = address(env("MINT"));
// Halts mint, burn, and transfer activity for every holder of the token.
await send(payer, [getPauseInstruction({ mint, authority: pauseAuthority })]);
// The pause flag lives in the mint's PausableConfig extension.
const { data } = await fetchMint(rpc, mint);
const extensions =
data.extensions.__option === "Some" ? data.extensions.value : [];
const pausable = extensions.find((ext) => ext.__kind === "PausableConfig");
console.log(
"Paused:",
pausable?.__kind === "PausableConfig" && pausable.paused,
);
Pausing the token
Output
Signature: 23XK8LxK7q8sTVBfcb2VLTRLuc28RyEmDy4oXGxoZF487N2hjvaX1ZPNpusvLBSUUdRTZEN1QJeENZkxoEHQxwUF
Paused: true
Web3.js v3
// npx tsx pause.ts
import { PublicKey } from "@solana/web3.js";
import {
getPauseInstruction,
getMintDecoder,
} from "@solana-program/token-2022";
import { addressOf, connection, env, loadKeypair, send } from "./common";
const payer = await loadKeypair("tokenization-demo");
// The pause authority is its own key, from step 1 of create the mint.
const pauseAuthority = await loadKeypair("demo-authorities/pause");
const mint = addressOf(env("MINT"));
// Halts mint, burn, and transfer activity for every holder of the token.
await send(
[payer, pauseAuthority],
[getPauseInstruction({ mint, authority: pauseAuthority })],
);
// The pause flag lives in the mint's PausableConfig extension.
const mintAccount = await connection.getAccountInfo(new PublicKey(mint));
const { extensions } = getMintDecoder().decode(mintAccount!.data);
const pausable = (extensions.__option === "Some" ? extensions.value : []).find(
(ext) => ext.__kind === "PausableConfig",
);
console.log(
"Paused:",
pausable?.__kind === "PausableConfig" && pausable.paused,
);
Pausing the token
Output
Signature: kF6DtbucMEH8ehwtTtSadjbcyaPGykQicUm3Vc5inb9x9t2tgmWUdH3HWHmHyU7kKV6TeZCPVxKDbwD6KKXtpiF
Paused: true
Rust
// cargo run --release --bin pause
use anyhow::Result;
use gated_token::{env, load_keypair, rpc, send, TOKEN_2022};
use solana_sdk::signature::Signer;
use spl_token_2022_interface::{
extension::{
pausable::{instruction::pause, PausableConfig},
BaseStateWithExtensions, StateWithExtensions,
},
state::Mint,
};
#[tokio::main]
async fn main() -> Result<()> {
let rpc = rpc();
let payer = load_keypair("tokenization-demo")?;
// The pause authority is its own key, from step 1 of create the mint.
let pause_authority = load_keypair("demo-authorities/pause")?;
let mint = env("MINT")?;
// Halts mint, burn, and transfer activity for every holder of the token.
let instruction = pause(&TOKEN_2022, &mint, &pause_authority.pubkey(), &[])?;
send(&rpc, &[&payer, &pause_authority], &[instruction]).await?;
// The pause flag lives in the mint's PausableConfig extension.
let data = rpc.get_account_data(&mint).await?;
let state = StateWithExtensions::<Mint>::unpack(&data)?;
let paused: bool = state.get_extension::<PausableConfig>()?.paused.into();
println!("Paused: {paused}");
Ok(())
}
Pausing the token
Output
Signature: 2diQLmcwSm4as9vWpVRx49tLCSo9m93bniTEwJBdUwGF5d6GvHS9LSKFvcC4D4sNg2jjAiN8J83eZbcm9WX93a9
Paused: true
0x43
(67), Token-2022’s MintPaused:- Mosaic SDK
- Kit
- Web3.js v3
- Rust
Mosaic SDK
// npx tsx transfer.ts <recipient> <amount>
import { address } from "@solana/kit";
import { createTransferTransaction } from "@solana/mosaic-sdk";
import { arg, env, loadSigner, rpc, sendMessage } from "./common";
// The holder signs and pays for its own transfer.
const holder = await loadSigner("demo-holder");
const mint = address(env("MINT"));
// Creates the recipient's token account if it is missing and thaws it
// through the gate before the transfer, so the gate decides whether the
// recipient may hold the token.
await sendMessage(
await createTransferTransaction({
rpc,
mint,
from: holder.address,
to: address(arg(1, "the recipient wallet")),
feePayer: holder,
authority: holder,
amount: arg(2, "the amount"),
}),
);
Sending 1 while the token is paused
Output
Failed: Program TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb failed: custom program error: 0x43
Kit
// npx tsx transfer.ts <recipient> <amount>
import { address } from "@solana/kit";
import {
fetchMint,
findAssociatedTokenPda,
getTransferCheckedInstruction,
TOKEN_2022_PROGRAM_ADDRESS,
} from "@solana-program/token-2022";
import { arg, env, loadSigner, rpc, send, toBaseUnits } from "./common";
import { openThroughGate } from "./gate";
// The holder signs and pays for its own transfer.
const holder = await loadSigner("demo-holder");
const mint = address(env("MINT"));
const list = address(env("LIST"));
const { data } = await fetchMint(rpc, mint);
const [source] = await findAssociatedTokenPda({
mint,
owner: holder.address,
tokenProgram: TOKEN_2022_PROGRAM_ADDRESS,
});
// The thaw is where an unlisted recipient fails: the gate rejects the owner
// and the whole transaction is dropped before any token moves.
const { tokenAccount: destination, instructions } = await openThroughGate(
holder,
mint,
address(arg(1, "the recipient wallet")),
list,
);
await send(holder, [
...instructions,
getTransferCheckedInstruction({
source,
mint,
destination,
authority: holder,
amount: toBaseUnits(arg(2, "the amount"), data.decimals),
decimals: data.decimals,
}),
]);
Sending 1 while the token is paused
Output
Failed: Program TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb failed: custom program error: 0x43
Web3.js v3
// npx tsx transfer.ts <recipient> <amount>
import { PublicKey } from "@solana/web3.js";
import {
findAssociatedTokenPda,
getMintDecoder,
getTransferCheckedInstruction,
TOKEN_2022_PROGRAM_ADDRESS,
} from "@solana-program/token-2022";
import {
addressOf,
arg,
connection,
env,
loadKeypair,
send,
toBaseUnits,
} from "./common";
import { openThroughGate } from "./gate";
// The holder signs and pays for its own transfer.
const holder = await loadKeypair("demo-holder");
const mint = addressOf(env("MINT"));
const list = addressOf(env("LIST"));
const mintAccount = await connection.getAccountInfo(new PublicKey(mint));
const { decimals } = getMintDecoder().decode(mintAccount!.data);
const [source] = await findAssociatedTokenPda({
mint,
owner: holder.publicKey.toBase58(),
tokenProgram: TOKEN_2022_PROGRAM_ADDRESS,
});
// The thaw is where an unlisted recipient fails: the gate rejects the owner
// and the whole transaction is dropped before any token moves.
const { tokenAccount: destination, instructions } = await openThroughGate(
holder,
mint,
addressOf(arg(1, "the recipient wallet")),
list,
);
await send(
[holder],
[
...instructions,
getTransferCheckedInstruction({
source,
mint,
destination,
authority: holder,
amount: toBaseUnits(arg(2, "the amount"), decimals),
decimals,
}),
],
);
Sending 1 while the token is paused
Output
Failed: Program TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb failed: custom program error: 0x43
Rust
// cargo run --release --bin transfer -- <recipient> <amount>
use anyhow::Result;
use gated_token::{
acl, arg, arg_pubkey, ata, env, load_keypair, mint_decimals, rpc, send, to_base_units,
TOKEN_2022,
};
use solana_sdk::signature::Signer;
use spl_token_2022_interface::instruction::transfer_checked;
#[tokio::main]
async fn main() -> Result<()> {
let rpc = rpc();
// The holder signs and pays for its own transfer.
let holder = load_keypair("demo-holder")?;
let mint = env("MINT")?;
let list = env("LIST")?;
let recipient = arg_pubkey(1, "the recipient wallet")?;
let decimals = mint_decimals(&rpc, &mint).await?;
// The thaw is where an unlisted recipient fails: the gate rejects the
// owner and the whole transaction is dropped before any token moves.
let (destination, mut instructions) =
acl::open_through_gate(&rpc, &holder.pubkey(), &mint, &recipient, &list).await?;
instructions.push(transfer_checked(
&TOKEN_2022,
&ata(&mint, &holder.pubkey()),
&mint,
&destination,
&holder.pubkey(),
&[],
to_base_units(&arg(2, "the amount")?, decimals)?,
decimals,
)?);
send(&rpc, &[&holder], &instructions).await
}
Sending 1 while the token is paused
Output
Failed: Program TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb failed: custom program error: 0x43
resume.ts (in Rust, src/bin/resume.rs) and run
it.- Mosaic SDK
- Kit
- Web3.js v3
- Rust
Mosaic SDK
// npx tsx resume.ts
import { address } from "@solana/kit";
import {
createResumeTransaction,
getTokenPauseState,
} from "@solana/mosaic-sdk";
import { env, loadSigner, rpc, sendMessage } from "./common";
const payer = await loadSigner("tokenization-demo");
const pauseAuthority = await loadSigner("demo-authorities/pause");
const mint = address(env("MINT"));
const { transactionMessage } = await createResumeTransaction(rpc, {
mint,
pauseAuthority,
feePayer: payer,
});
await sendMessage(transactionMessage);
console.log("Paused:", await getTokenPauseState(rpc, mint));
Resuming the token
Output
Signature: 3EGztQzw6vYFBemMBXW5vJ5iBZvtrVsf3mNva6brXRMNECkzzSJahTjwpXqnPqj3ybVYzL3y6Dx3cUqMKsLipzCx
Paused: false
Kit
// npx tsx resume.ts
import { address } from "@solana/kit";
import { fetchMint, getResumeInstruction } from "@solana-program/token-2022";
import { env, loadSigner, rpc, send } from "./common";
const payer = await loadSigner("tokenization-demo");
// The pause authority is its own key, from step 1 of create the mint.
const pauseAuthority = await loadSigner("demo-authorities/pause");
const mint = address(env("MINT"));
await send(payer, [getResumeInstruction({ mint, authority: pauseAuthority })]);
const { data } = await fetchMint(rpc, mint);
const extensions =
data.extensions.__option === "Some" ? data.extensions.value : [];
const pausable = extensions.find((ext) => ext.__kind === "PausableConfig");
console.log(
"Paused:",
pausable?.__kind === "PausableConfig" && pausable.paused,
);
Resuming the token
Output
Signature: 3hFU3JhuUVFoLxL6Sv4izv5z2KsKf8S2xQxUpTx5XBDaJgejUSm92791NSHS54G2VxfEK7Y5rzjMer9c8qtph8R7
Paused: false
Web3.js v3
// npx tsx resume.ts
import { PublicKey } from "@solana/web3.js";
import {
getResumeInstruction,
getMintDecoder,
} from "@solana-program/token-2022";
import { addressOf, connection, env, loadKeypair, send } from "./common";
const payer = await loadKeypair("tokenization-demo");
// The pause authority is its own key, from step 1 of create the mint.
const pauseAuthority = await loadKeypair("demo-authorities/pause");
const mint = addressOf(env("MINT"));
await send(
[payer, pauseAuthority],
[getResumeInstruction({ mint, authority: pauseAuthority })],
);
// The pause flag lives in the mint's PausableConfig extension.
const mintAccount = await connection.getAccountInfo(new PublicKey(mint));
const { extensions } = getMintDecoder().decode(mintAccount!.data);
const pausable = (extensions.__option === "Some" ? extensions.value : []).find(
(ext) => ext.__kind === "PausableConfig",
);
console.log(
"Paused:",
pausable?.__kind === "PausableConfig" && pausable.paused,
);
Resuming the token
Output
Signature: 5o3nAatBNFvmuYnbR3gCcf9ztH3q1ypEgfxv9STcgA51cz6aYvfUo61VFLwqfvsCqijehU7SkYQryiX1KQEYHTY6
Paused: false
Rust
// cargo run --release --bin resume
use anyhow::Result;
use gated_token::{env, load_keypair, rpc, send, TOKEN_2022};
use solana_sdk::signature::Signer;
use spl_token_2022_interface::{
extension::{
pausable::{instruction::resume, PausableConfig},
BaseStateWithExtensions, StateWithExtensions,
},
state::Mint,
};
#[tokio::main]
async fn main() -> Result<()> {
let rpc = rpc();
let payer = load_keypair("tokenization-demo")?;
// The pause authority is its own key, from step 1 of create the mint.
let pause_authority = load_keypair("demo-authorities/pause")?;
let mint = env("MINT")?;
let instruction = resume(&TOKEN_2022, &mint, &pause_authority.pubkey(), &[])?;
send(&rpc, &[&payer, &pause_authority], &[instruction]).await?;
// The pause flag lives in the mint's PausableConfig extension.
let data = rpc.get_account_data(&mint).await?;
let state = StateWithExtensions::<Mint>::unpack(&data)?;
let paused: bool = state.get_extension::<PausableConfig>()?.paused.into();
println!("Paused: {paused}");
Ok(())
}
Resuming the token
Output
Signature: 3rVbGWRQmyeeHsFBBDso8BFsnhNadDdyE2v55VZuiGUnyGDRquTDKTUvHPb8GkwaYt2C5Lfz2pdcE2cjtkc2zGpu
Paused: false
3
Force a transfer
The permanent delegate can move any holder’s balance without their signature.
This is the power used to comply with a court order, to recover from a lost
key, and to move a balance after a fraudulent transfer. It moves tokens onward;
the original transfer stays on the ledger. Save this as The destination still has to be able to hold the token. The script opens a new
or frozen destination account through the gate, and the gate rejects that thaw
if the wallet is not on the list, so a forced transfer to an unlisted wallet
fails with the same
force-transfer.ts
(in Rust, src/bin/force-transfer.rs) and run it with $HOLDER $OUTSIDER 10.- Mosaic SDK
- Kit
- Web3.js v3
- Rust
Mosaic SDK
// npx tsx force-transfer.ts <from wallet> <to wallet> <amount>
import { address } from "@solana/kit";
import { createForceTransferTransaction } from "@solana/mosaic-sdk";
import { arg, env, loadSigner, rpc, sendMessage } from "./common";
const payer = await loadSigner("tokenization-demo");
const permanentDelegate = await loadSigner("demo-authorities/delegate");
// Moves a holder's balance without the holder's signature. The permanent
// delegate signs; the fee payer only pays.
await sendMessage(
await createForceTransferTransaction(
rpc,
address(env("MINT")),
address(arg(1, "the source wallet")),
address(arg(2, "the destination wallet")),
Number(arg(3, "the amount")),
permanentDelegate,
payer,
),
);
Moving 10 from the holder to the outsider with the permanent delegate
Output
Signature: 2hdXbtDnow76CDRhfpVgEA3oUx9qLNfCyi8EEpeTKTr47PXcjhtx6vC5uFGe655rRiwNsdyYBMonH1Hpn3EisZmG
Kit
// npx tsx force-transfer.ts <from wallet> <to wallet> <amount>
import { address } from "@solana/kit";
import {
fetchMint,
findAssociatedTokenPda,
getTransferCheckedInstruction,
TOKEN_2022_PROGRAM_ADDRESS,
} from "@solana-program/token-2022";
import { arg, env, loadSigner, rpc, send, toBaseUnits } from "./common";
import { openThroughGate } from "./gate";
const payer = await loadSigner("tokenization-demo");
const permanentDelegate = await loadSigner("demo-authorities/delegate");
const mint = address(env("MINT"));
const list = address(env("LIST"));
const { data } = await fetchMint(rpc, mint);
const [source] = await findAssociatedTokenPda({
mint,
owner: address(arg(1, "the source wallet")),
tokenProgram: TOKEN_2022_PROGRAM_ADDRESS,
});
// The destination still has to be able to hold the token, so it is opened
// through the gate like any other recipient.
const { tokenAccount: destination, instructions } = await openThroughGate(
payer,
mint,
address(arg(2, "the destination wallet")),
list,
);
// An ordinary TransferChecked, signed by the permanent delegate in place of
// the holder.
await send(payer, [
...instructions,
getTransferCheckedInstruction({
source,
mint,
destination,
authority: permanentDelegate,
amount: toBaseUnits(arg(3, "the amount"), data.decimals),
decimals: data.decimals,
}),
]);
Moving 10 from the holder to the outsider with the permanent delegate
Output
Signature: M5LUgTQ8Y38UhGUBRmQiyewkAqRWvBm8BoW1cgE933JFYQoixhK9255dg9mVFb75raXksBaw6BfNd8sfF4gzqoh
Web3.js v3
// npx tsx force-transfer.ts <from wallet> <to wallet> <amount>
import { PublicKey } from "@solana/web3.js";
import {
findAssociatedTokenPda,
getMintDecoder,
getTransferCheckedInstruction,
TOKEN_2022_PROGRAM_ADDRESS,
} from "@solana-program/token-2022";
import {
addressOf,
arg,
connection,
env,
loadKeypair,
send,
toBaseUnits,
} from "./common";
import { openThroughGate } from "./gate";
const payer = await loadKeypair("tokenization-demo");
const permanentDelegate = await loadKeypair("demo-authorities/delegate");
const mint = addressOf(env("MINT"));
const list = addressOf(env("LIST"));
const mintAccount = await connection.getAccountInfo(new PublicKey(mint));
const { decimals } = getMintDecoder().decode(mintAccount!.data);
const [source] = await findAssociatedTokenPda({
mint,
owner: addressOf(arg(1, "the source wallet")),
tokenProgram: TOKEN_2022_PROGRAM_ADDRESS,
});
// The destination still has to be able to hold the token, so it is opened
// through the gate like any other recipient.
const { tokenAccount: destination, instructions } = await openThroughGate(
payer,
mint,
addressOf(arg(2, "the destination wallet")),
list,
);
// An ordinary TransferChecked, signed by the permanent delegate in place of
// the holder.
await send(
[payer, permanentDelegate],
[
...instructions,
getTransferCheckedInstruction({
source,
mint,
destination,
authority: permanentDelegate,
amount: toBaseUnits(arg(3, "the amount"), decimals),
decimals,
}),
],
);
Moving 10 from the holder to the outsider with the permanent delegate
Output
Signature: 47U2gotoupCjxfpFaUSWPE93LgmH6xKQ3NArRdKvzuwJGnnzKL6SzeyyG3P5Lb284veL5f7h3WWWzeCvWxsGUKbe
Rust
// cargo run --release --bin force-transfer -- <from wallet> <to wallet> <amount>
use anyhow::Result;
use gated_token::{
acl, arg, arg_pubkey, ata, env, load_keypair, mint_decimals, rpc, send, to_base_units,
TOKEN_2022,
};
use solana_sdk::signature::Signer;
use spl_token_2022_interface::instruction::transfer_checked;
#[tokio::main]
async fn main() -> Result<()> {
let rpc = rpc();
let payer = load_keypair("tokenization-demo")?;
let permanent_delegate = load_keypair("demo-authorities/delegate")?;
let mint = env("MINT")?;
let list = env("LIST")?;
let from = arg_pubkey(1, "the source wallet")?;
let to = arg_pubkey(2, "the destination wallet")?;
let decimals = mint_decimals(&rpc, &mint).await?;
// The destination still has to be able to hold the token, so it is opened
// through the gate like any other recipient.
let (destination, mut instructions) =
acl::open_through_gate(&rpc, &payer.pubkey(), &mint, &to, &list).await?;
// An ordinary TransferChecked, signed by the permanent delegate in place
// of the holder.
instructions.push(transfer_checked(
&TOKEN_2022,
&ata(&mint, &from),
&mint,
&destination,
&permanent_delegate.pubkey(),
&[],
to_base_units(&arg(3, "the amount")?, decimals)?,
decimals,
)?);
send(&rpc, &[&payer, &permanent_delegate], &instructions).await
}
Moving 10 from the holder to the outsider with the permanent delegate
Output
Signature: ZaStMvGWNtg4KHUzXvo64d92C3grUo7yPLbzp68638d84r1e6Mp9SsKSC8o7TDEuFbGWL9vjzixAqGBvuEpfoEa
0x1002 as a blocked transfer. Move the balance to a
listed recovery wallet.This works here because no holder has turned on Confidential Balances. On a
mint where a holder has moved a balance into its confidential balance, the
delegate reaches the public balance only; see
privacy and transfer controls.In this tutorial the permanent delegate is its own key. In production, holding
it offline and behind a quorum reduces the chance that a compromise of
day-to-day operations keys reaches it.4
Redeem with the holder
This mint carries permissioned burn, so a holder cannot burn their own balance
alone: the burn authority co-signs. On this mint, that is the redemption path:
the holder instructs, the issuer confirms the offchain leg has settled, and the
two signatures extinguish the position together. While the extension has a
burn authority, Token-2022 rejects a plain
Burn or BurnChecked on this mint
with InvalidInstruction; a burn has to use the extension’s own burn
instruction, which the burn authority signs. Save this as burn.ts (in Rust,
src/bin/burn.rs) and run it with 1.- Mosaic SDK
- Kit
- Web3.js v3
- Rust
Mosaic SDK
// npx tsx burn.ts <amount>
import { address } from "@solana/kit";
import { createBurnTransaction } from "@solana/mosaic-sdk";
import { arg, env, loadSigner, rpc, sendMessage } from "./common";
// The holder burns its own balance, and the burn authority co-signs because
// the mint carries permissioned burn.
const holder = await loadSigner("demo-holder");
const burnAuthority = await loadSigner("demo-authorities/burn");
await sendMessage(
await createBurnTransaction(
rpc,
address(env("MINT")),
holder, // owner of the tokens
Number(arg(1, "the amount")),
holder, // fee payer
burnAuthority,
),
);
The holder burning 1 with the burn authority’s co-signature
Output
Signature: 4XKBYPVa9tmb56B8Nn4tuEouckA71GQMHDzAJp1wudTuLkNgZaLrfhUvUs8vVKGMx6UjFTQwEKZ4kxkEozpMdMjs
Kit
// npx tsx burn.ts <amount>
import { address } from "@solana/kit";
import {
fetchMint,
findAssociatedTokenPda,
getPermissionedBurnCheckedInstruction,
TOKEN_2022_PROGRAM_ADDRESS,
} from "@solana-program/token-2022";
import { arg, env, loadSigner, rpc, send, toBaseUnits } from "./common";
const holder = await loadSigner("demo-holder");
const burnAuthority = await loadSigner("demo-authorities/burn");
const mint = address(env("MINT"));
const { data } = await fetchMint(rpc, mint);
const [account] = await findAssociatedTokenPda({
mint,
owner: holder.address,
tokenProgram: TOKEN_2022_PROGRAM_ADDRESS,
});
// Token-2022 rejects a plain burn on this mint. The permissioned burn
// instruction carries both signers: the holder and the burn authority.
await send(holder, [
getPermissionedBurnCheckedInstruction({
account,
mint,
permissionedBurnAuthority: burnAuthority,
authority: holder,
amount: toBaseUnits(arg(1, "the amount"), data.decimals),
decimals: data.decimals,
}),
]);
The holder burning 1 with the burn authority’s co-signature
Output
Signature: MhKw2csJM3THu7ptwKdyM6L64VMNt3bWbVkLwpeMYXwT2jiTFjeYCEUe7grh3nmtWxETm54u7Miae4mLaCc32bQ
Web3.js v3
// npx tsx burn.ts <amount>
import { PublicKey } from "@solana/web3.js";
import {
findAssociatedTokenPda,
getMintDecoder,
getPermissionedBurnCheckedInstruction,
TOKEN_2022_PROGRAM_ADDRESS,
} from "@solana-program/token-2022";
import {
addressOf,
arg,
connection,
env,
loadKeypair,
send,
toBaseUnits,
} from "./common";
const holder = await loadKeypair("demo-holder");
const burnAuthority = await loadKeypair("demo-authorities/burn");
const mint = addressOf(env("MINT"));
const mintAccount = await connection.getAccountInfo(new PublicKey(mint));
const { decimals } = getMintDecoder().decode(mintAccount!.data);
const [account] = await findAssociatedTokenPda({
mint,
owner: holder.publicKey.toBase58(),
tokenProgram: TOKEN_2022_PROGRAM_ADDRESS,
});
// Token-2022 rejects a plain burn on this mint. The permissioned burn
// instruction carries both signers: the holder and the burn authority.
await send(
[holder, burnAuthority],
[
getPermissionedBurnCheckedInstruction({
account,
mint,
permissionedBurnAuthority: burnAuthority,
authority: holder,
amount: toBaseUnits(arg(1, "the amount"), decimals),
decimals,
}),
],
);
The holder burning 1 with the burn authority’s co-signature
Output
Signature: 4JcnizepFRCp5sQzH4PmhBwYyJLfQoiudZ7pNbas2nzBRBcaDetDSWwwsVEEcMmJiVAMZivBSdS2EL7Uhos7ZbPi
Rust
// cargo run --release --bin burn -- <amount>
use anyhow::Result;
use gated_token::{
arg, ata, env, load_keypair, mint_decimals, rpc, send, to_base_units, TOKEN_2022,
};
use solana_sdk::signature::Signer;
use spl_token_2022_interface::extension::permissioned_burn::instruction::burn_checked;
#[tokio::main]
async fn main() -> Result<()> {
let rpc = rpc();
let holder = load_keypair("demo-holder")?;
let burn_authority = load_keypair("demo-authorities/burn")?;
let mint = env("MINT")?;
let decimals = mint_decimals(&rpc, &mint).await?;
// Token-2022 rejects a plain burn on this mint. The permissioned burn
// instruction carries both signers: the holder and the burn authority.
let instruction = burn_checked(
&TOKEN_2022,
&ata(&mint, &holder.pubkey()),
&mint,
&burn_authority.pubkey(),
&holder.pubkey(),
&[],
to_base_units(&arg(1, "the amount")?, decimals)?,
decimals,
)?;
send(&rpc, &[&holder, &burn_authority], &[instruction]).await
}
The holder burning 1 with the burn authority’s co-signature
Output
Signature: 3TuMHp2YTTvmdB8rRBHxvHyc15cpbVrZi2qdTreUsnpJXX2BwwPtABSdkjxboNCsRZVcnTwphEUbFEiVbzd6AM8n
5
Burn without the holder
The permanent delegate can burn a balance without the holder’s signature, for
redemptions where there is no cooperating holder: a lost key, an unresponsive
account, or a position being extinguished under a court order. Because the
mint carries permissioned burn on a separate key, the burn authority co-signs
this path too. Save this as Token-2022 does not burn from a frozen account. The script thaws a frozen
source through the gate first, which works only while the wallet is on the
list; for an offboarded wallet, re-add it for the duration of the burn.Where the token records an asset held elsewhere, record each burn in the
offchain register with a shared reference; see
token design.
force-burn.ts (in Rust, src/bin/force-burn.rs)
and run it with $OUTSIDER 1.- Mosaic SDK
- Kit
- Web3.js v3
- Rust
Mosaic SDK
// npx tsx force-burn.ts <wallet> <amount>
import { address } from "@solana/kit";
import { createForceBurnTransaction } from "@solana/mosaic-sdk";
import { arg, env, loadSigner, rpc, sendMessage } from "./common";
const payer = await loadSigner("tokenization-demo");
const permanentDelegate = await loadSigner("demo-authorities/delegate");
const burnAuthority = await loadSigner("demo-authorities/burn");
// Burns without the holder. The permanent delegate signs, and the burn
// authority co-signs because the mint carries permissioned burn.
await sendMessage(
await createForceBurnTransaction(
rpc,
address(env("MINT")),
address(arg(1, "the wallet to burn from")),
Number(arg(2, "the amount")),
permanentDelegate,
payer,
burnAuthority,
),
);
Burning 1 from the outsider without the holder
Output
Signature: 24CiHSMrLn1okeKMMRra1TjpyRoQSVGVsKgcTbU7LGvrWdrVfpu6FHa5HbhwR7SzQxMGBdB8iiej1He2iWo8nU6T
Kit
// npx tsx force-burn.ts <wallet> <amount>
import { address, type Instruction } from "@solana/kit";
import {
AccountState,
fetchMaybeToken,
fetchMint,
findAssociatedTokenPda,
getPermissionedBurnCheckedInstruction,
TOKEN_2022_PROGRAM_ADDRESS,
} from "@solana-program/token-2022";
import { arg, env, loadSigner, rpc, send, toBaseUnits } from "./common";
import { thawThroughGate } from "./gate";
const payer = await loadSigner("tokenization-demo");
const permanentDelegate = await loadSigner("demo-authorities/delegate");
const burnAuthority = await loadSigner("demo-authorities/burn");
const mint = address(env("MINT"));
const list = address(env("LIST"));
const owner = address(arg(1, "the wallet to burn from"));
const { data } = await fetchMint(rpc, mint);
const [account] = await findAssociatedTokenPda({
mint,
owner,
tokenProgram: TOKEN_2022_PROGRAM_ADDRESS,
});
// Token-2022 does not burn from a frozen account, so a frozen source is
// thawed through the gate first. That only works while the wallet is listed.
const instructions: Instruction[] = [];
const existing = await fetchMaybeToken(rpc, account);
if (existing.exists && existing.data.state === AccountState.Frozen) {
instructions.push(await thawThroughGate(payer, mint, account, owner, list));
}
// The permanent delegate signs in place of the holder, and the burn
// authority co-signs because the mint carries permissioned burn.
await send(payer, [
...instructions,
getPermissionedBurnCheckedInstruction({
account,
mint,
permissionedBurnAuthority: burnAuthority,
authority: permanentDelegate,
amount: toBaseUnits(arg(2, "the amount"), data.decimals),
decimals: data.decimals,
}),
]);
Burning 1 from the outsider without the holder
Output
Signature: 44PnrVXNbG1c2NGCmeKupYNS5Q31HchJDwjo1PSrfN3HnBxshcuiT3AfonWPuYtpMUnZPvSMK1GWJSEihX5BDyat
Web3.js v3
// npx tsx force-burn.ts <wallet> <amount>
import type { Instruction } from "@solana/kit";
import { PublicKey } from "@solana/web3.js";
import {
AccountState,
findAssociatedTokenPda,
getMintDecoder,
getPermissionedBurnCheckedInstruction,
getTokenDecoder,
TOKEN_2022_PROGRAM_ADDRESS,
} from "@solana-program/token-2022";
import {
addressOf,
arg,
connection,
env,
loadKeypair,
send,
toBaseUnits,
} from "./common";
import { thawThroughGate } from "./gate";
const payer = await loadKeypair("tokenization-demo");
const permanentDelegate = await loadKeypair("demo-authorities/delegate");
const burnAuthority = await loadKeypair("demo-authorities/burn");
const mint = addressOf(env("MINT"));
const list = addressOf(env("LIST"));
const owner = addressOf(arg(1, "the wallet to burn from"));
const mintAccount = await connection.getAccountInfo(new PublicKey(mint));
const { decimals } = getMintDecoder().decode(mintAccount!.data);
const [account] = await findAssociatedTokenPda({
mint,
owner,
tokenProgram: TOKEN_2022_PROGRAM_ADDRESS,
});
// Token-2022 does not burn from a frozen account, so a frozen source is
// thawed through the gate first. That only works while the wallet is listed.
const instructions: Instruction[] = [];
const existing = await connection.getAccountInfo(new PublicKey(account));
if (
existing &&
getTokenDecoder().decode(existing.data).state === AccountState.Frozen
) {
instructions.push(await thawThroughGate(payer, mint, account, owner, list));
}
// The permanent delegate signs in place of the holder, and the burn
// authority co-signs because the mint carries permissioned burn.
await send(
[payer, permanentDelegate, burnAuthority],
[
...instructions,
getPermissionedBurnCheckedInstruction({
account,
mint,
permissionedBurnAuthority: burnAuthority,
authority: permanentDelegate,
amount: toBaseUnits(arg(2, "the amount"), decimals),
decimals,
}),
],
);
Burning 1 from the outsider without the holder
Output
Signature: 55zwqpGZmG6MwFnAQaNwzNtXXj2ttYAT2GuXTVp3493dPcMhU4o9eCrLrqXZH1kfUKbfSP2nPEMZ3U78GaUWbjVF
Rust
// cargo run --release --bin force-burn -- <wallet> <amount>
use anyhow::Result;
use gated_token::{
acl, arg, arg_pubkey, ata, env, load_keypair, mint_decimals, rpc, send, to_base_units,
token_account_state, TOKEN_2022,
};
use solana_sdk::signature::Signer;
use spl_token_2022_interface::{
extension::permissioned_burn::instruction::burn_checked, state::AccountState,
};
#[tokio::main]
async fn main() -> Result<()> {
let rpc = rpc();
let payer = load_keypair("tokenization-demo")?;
let permanent_delegate = load_keypair("demo-authorities/delegate")?;
let burn_authority = load_keypair("demo-authorities/burn")?;
let mint = env("MINT")?;
let list = env("LIST")?;
let owner = arg_pubkey(1, "the wallet to burn from")?;
let account = ata(&mint, &owner);
let decimals = mint_decimals(&rpc, &mint).await?;
// Token-2022 does not burn from a frozen account, so a frozen source is
// thawed through the gate first. That only works while the wallet is listed.
let mut instructions = Vec::new();
if token_account_state(&rpc, &account).await? == Some(AccountState::Frozen) {
instructions.push(acl::thaw_through_gate(
&payer.pubkey(),
&mint,
&account,
&owner,
&list,
));
}
// The permanent delegate signs in place of the holder, and the burn
// authority co-signs because the mint carries permissioned burn.
instructions.push(burn_checked(
&TOKEN_2022,
&account,
&mint,
&burn_authority.pubkey(),
&permanent_delegate.pubkey(),
&[],
to_base_units(&arg(2, "the amount")?, decimals)?,
decimals,
)?);
send(
&rpc,
&[&payer, &permanent_delegate, &burn_authority],
&instructions,
)
.await
}
Burning 1 from the outsider without the holder
Output
Signature: 65Jr8CsN3UjdugUiB8EThkcfz7cqZscxyU5ViGfj45cSeCsEpsZd88saGBgxRTRQACGSW8ZEDdJ8iDfY5amdgCVG
Permissioned burn can only be added at creation, and the extension stays on
the mint. Its authority can sign a
SetAuthority that clears it, which lets
holders burn alone again and cannot be undone. Pointing the permissioned burn authority at the permanent delegate’s key
at creation lets one signer cover both roles on a forced burn; keeping them
separate, as this tutorial does, means two signatures stand behind every
reduction of supply. Both designs are in use.6
Offboard a holder
Offboarding removes the wallet from the allowlist. Removal alone stops future
thaws but leaves an open account usable, so the same transaction also freezes
the wallet’s token account if it is open and thawed. An offboarded holder can
then neither receive nor send. Save this as Read the account back. The reads take the outsider’s token account, not the
wallet, so derive its address first:Then read it with The balance is intact and the state is
allowlist-remove.ts (in Rust,
src/bin/allowlist-remove.rs) and run it with $OUTSIDER.- Mosaic SDK
- Kit
- Web3.js v3
- Rust
Mosaic SDK
// npx tsx allowlist-remove.ts <wallet>
import { address } from "@solana/kit";
import { createRemoveFromAllowlistTransaction } from "@solana/mosaic-sdk";
import { arg, env, loadSigner, rpc, sendMessage } from "./common";
const payer = await loadSigner("tokenization-demo");
// Removes the wallet from the allowlist. The same transaction freezes the
// wallet's associated token account when it exists and is thawed.
await sendMessage(
await createRemoveFromAllowlistTransaction(
rpc,
address(env("MINT")),
address(arg(1, "the wallet to remove")),
payer,
),
);
Removing the outsider from the allowlist
Output
Signature: 5WTkD37Yu8oYUJFsaK9sfTqK2XSxv1vwFtcL8USRQXsJ6HnDq4h464GuSZEvko68GBULQzDgWqT6hrjr5rJxHfuY
Kit
// npx tsx allowlist-remove.ts <wallet>
import { address, type Instruction } from "@solana/kit";
import {
AccountState,
fetchMaybeToken,
findAssociatedTokenPda,
TOKEN_2022_PROGRAM_ADDRESS,
} from "@solana-program/token-2022";
import { findMintConfigPda, getFreezeInstruction } from "@solana/token-acl-sdk";
import {
findListConfigPda,
findWalletEntryPda,
getRemoveWalletInstruction,
} from "@solana/token-acl-gate-sdk";
import { arg, env, loadSigner, rpc, send } from "./common";
const payer = await loadSigner("tokenization-demo");
const mint = address(env("MINT"));
const wallet = address(arg(1, "the wallet to remove"));
const [listConfig] = await findListConfigPda({
authority: payer.address,
seed: mint,
});
const [walletEntry] = await findWalletEntryPda({ listConfig, wallet });
const instructions: Instruction[] = [
getRemoveWalletInstruction({ authority: payer, listConfig, walletEntry }),
];
// Removing the entry stops future thaws but does not touch an account that is
// already open, so freeze the wallet's token account in the same transaction.
const [tokenAccount] = await findAssociatedTokenPda({
mint,
owner: wallet,
tokenProgram: TOKEN_2022_PROGRAM_ADDRESS,
});
const account = await fetchMaybeToken(rpc, tokenAccount);
if (account.exists && account.data.state !== AccountState.Frozen) {
const [mintConfig] = await findMintConfigPda({ mint });
instructions.push(
getFreezeInstruction({ authority: payer, mint, tokenAccount, mintConfig }),
);
}
await send(payer, instructions);
Removing the outsider from the allowlist
Output
Signature: 2fbGNrrvmvyM5Aqwf7rZjQ5pn4CcbucuwJVCPSm7qM5a3FoABnH81cKCVfxkVja5phtJa4yAwxPpJtvwC2xmhwrr
Web3.js v3
// npx tsx allowlist-remove.ts <wallet>
import type { Instruction } from "@solana/kit";
import { PublicKey } from "@solana/web3.js";
import {
AccountState,
findAssociatedTokenPda,
getTokenDecoder,
TOKEN_2022_PROGRAM_ADDRESS,
} from "@solana-program/token-2022";
import { findMintConfigPda, getFreezeInstruction } from "@solana/token-acl-sdk";
import {
findListConfigPda,
findWalletEntryPda,
getRemoveWalletInstruction,
} from "@solana/token-acl-gate-sdk";
import { addressOf, arg, connection, env, loadKeypair, send } from "./common";
const payer = await loadKeypair("tokenization-demo");
const mint = addressOf(env("MINT"));
const wallet = addressOf(arg(1, "the wallet to remove"));
const [listConfig] = await findListConfigPda({
authority: payer.publicKey.toBase58(),
seed: mint,
});
const [walletEntry] = await findWalletEntryPda({ listConfig, wallet });
const instructions: Instruction[] = [
getRemoveWalletInstruction({ authority: payer, listConfig, walletEntry }),
];
// Removing the entry stops future thaws but does not touch an account that is
// already open, so freeze the wallet's token account in the same transaction.
const [tokenAccount] = await findAssociatedTokenPda({
mint,
owner: wallet,
tokenProgram: TOKEN_2022_PROGRAM_ADDRESS,
});
const account = await connection.getAccountInfo(new PublicKey(tokenAccount));
if (
account &&
getTokenDecoder().decode(account.data).state !== AccountState.Frozen
) {
const [mintConfig] = await findMintConfigPda({ mint });
instructions.push(
getFreezeInstruction({ authority: payer, mint, tokenAccount, mintConfig }),
);
}
await send([payer], instructions);
Removing the outsider from the allowlist
Output
Signature: 3BUecvfsB2ueju5NSe7jHNhLfPxVXHX22WiwdEt4uC65PRSZuumrAfYALWarcbsABJ3ZNt7SWAd42eopBTLTy58e
Rust
// cargo run --release --bin allowlist-remove -- <wallet>
use anyhow::Result;
use gated_token::{acl, arg_pubkey, ata, env, load_keypair, rpc, send, token_account_state};
use solana_sdk::signature::Signer;
use spl_token_2022_interface::state::AccountState;
#[tokio::main]
async fn main() -> Result<()> {
let rpc = rpc();
let payer = load_keypair("tokenization-demo")?;
let mint = env("MINT")?;
let wallet = arg_pubkey(1, "the wallet to remove")?;
let list = acl::list_config(&payer.pubkey(), &mint);
let mut instructions = vec![acl::remove_wallet(&payer.pubkey(), &list, &wallet)];
// Removing the entry stops future thaws but does not touch an account
// that is already open, so freeze the wallet's token account in the same
// transaction.
let token_account = ata(&mint, &wallet);
if let Some(state) = token_account_state(&rpc, &token_account).await? {
if state != AccountState::Frozen {
instructions.push(acl::freeze(&payer.pubkey(), &mint, &token_account));
}
}
send(&rpc, &[&payer], &instructions).await
}
Removing the outsider from the allowlist
Output
Signature: 3FPeAWoNGcZHN6SGZWgUdx7Tq33bQTMfXjoLxaPmrZ5x9CzQFY8NNiD26pRHByucafug5wG4etV2eg8PsyaP6KSJ
spl-token
spl-token address --token $MINT --owner $OUTSIDER --verbose \
--url ${RPC_URL:-devnet}
Deriving the outsider’s token account
Output
Wallet address: 3oCWNf9LRfrzsW55H8sAP7td9oUUfiXkJAEpyRprjQDt
Associated token address: GdNxAwnJFigxHcThqezum7E8gREaba41aXUhw3JatioN
spl-token address --verbose prints two lines. Export the address on the
Associated token address line as OUTSIDER_ATA:Terminal
export OUTSIDER_ATA=<the associated token address>
spl-token, or with a read-account script. The scripts
need the Token-2022 client, so they run in the Kit, Web3.js v3, or Rust
project; with the Mosaic SDK, use spl-token. Save this as read-account.ts
(in Rust, src/bin/read-account.rs) and run it with $OUTSIDER_ATA. The
custodian tutorial’s
derive-ata script derives the same address from code.- spl-token
- Kit
- Web3.js v3
- Rust
spl-token
spl-token display $OUTSIDER_ATA --url ${RPC_URL:-devnet}
Reading the outsider’s token account after offboarding
Output
SPL Token Account
Address: GdNxAwnJFigxHcThqezum7E8gREaba41aXUhw3JatioN
Program: TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb
Balance: 10
Decimals: 6
Mint: 8ComqBcog3Aig4hYN9PcCQHcK4rCCUhv7QoxUfrVVB66
Owner: 3oCWNf9LRfrzsW55H8sAP7td9oUUfiXkJAEpyRprjQDt
State: Frozen
Delegation: (not set)
Close authority: (not set)
Extensions:
Immutable owner
* This token has a permanent delegate!
This means the mint may withdraw all funds from this account at any time.
If this was not adequately disclosed to you, you may be dealing with a malicious mint.
Kit
// npx tsx read-account.ts <token account> [commitment]
import { address, type Commitment } from "@solana/kit";
import { AccountState, fetchToken } from "@solana-program/token-2022";
import { arg, rpc } from "./common";
const tokenAccount = address(arg(1, "the token account"));
// Read at a stated commitment level. Use "finalized" for anything that feeds
// a book of record; "confirmed" is enough for a display.
const commitment = (process.argv[3] ?? "confirmed") as Commitment;
const { data } = await fetchToken(rpc, tokenAccount, { commitment });
console.log("Mint:", data.mint);
console.log("Owner:", data.owner);
console.log("Balance (base units):", data.amount.toString());
console.log("State:", AccountState[data.state]);
Reading the outsider’s token account after offboarding
Output
Mint: 8ComqBcog3Aig4hYN9PcCQHcK4rCCUhv7QoxUfrVVB66
Owner: 3oCWNf9LRfrzsW55H8sAP7td9oUUfiXkJAEpyRprjQDt
Balance (base units): 10000000
State: Frozen
Web3.js v3
// npx tsx read-account.ts <token account> [commitment]
import { type Commitment, PublicKey } from "@solana/web3.js";
import { AccountState, getTokenDecoder } from "@solana-program/token-2022";
import { arg, connection } from "./common";
const tokenAccount = new PublicKey(arg(1, "the token account"));
// Read at a stated commitment level. Use "finalized" for anything that feeds
// a book of record; "confirmed" is enough for a display.
const commitment = (process.argv[3] ?? "confirmed") as Commitment;
const info = await connection.getAccountInfo(tokenAccount, commitment);
const data = getTokenDecoder().decode(info!.data);
console.log("Mint:", data.mint);
console.log("Owner:", data.owner);
console.log("Balance (base units):", data.amount.toString());
console.log("State:", AccountState[data.state]);
Reading the outsider’s token account after offboarding
Output
Mint: 8xDpQoKEXGrtCm5JwseD2v7KHCNnXv8kQmm61Cjozn7o
Owner: AgN4EhghtWRV7wDTMuZrzrCdLBBxfK2RQe47FUUejcjt
Balance (base units): 10000000
State: Frozen
Rust
// cargo run --release --bin read-account -- <token account> [commitment]
use anyhow::{anyhow, Result};
use gated_token::{arg, arg_pubkey, rpc_with};
use solana_commitment_config::CommitmentConfig;
use spl_token_2022_interface::{
extension::StateWithExtensions,
state::{Account, AccountState},
};
#[tokio::main]
async fn main() -> Result<()> {
let token_account = arg_pubkey(1, "the token account")?;
// Read at a stated commitment level. Use "finalized" for anything that
// feeds a book of record; "confirmed" is enough for a display.
let commitment = match arg(2, "the commitment").as_deref() {
Ok("finalized") => CommitmentConfig::finalized(),
_ => CommitmentConfig::confirmed(),
};
let rpc = rpc_with(commitment);
let account = rpc
.get_account_with_commitment(&token_account, commitment)
.await?
.value
.ok_or_else(|| anyhow!("{token_account} not found at {commitment:?}"))?;
let state = StateWithExtensions::<Account>::unpack(&account.data)?.base;
println!("Mint: {}", state.mint);
println!("Owner: {}", state.owner);
println!("Balance (base units): {}", state.amount);
let label = if state.state == AccountState::Frozen {
"Frozen"
} else {
"Initialized"
};
println!("State: {label}");
Ok(())
}
Reading the outsider’s token account after offboarding
Output
Mint: 3zsS4p5aDBiqLmCynUBayqCM9WWR35jr51tT4maAT1P1
Owner: 3ngxNivaNqsrFDH7AjYqUY23SXP5krudw18L7eWkmKca
Balance (base units): 10000000
State: Frozen
Frozen. The outsider received 1 and
then 10 tokens, and 1 was burned: spl-token shows Balance: 10, and the
scripts print the amount in base units, 10000000 at six decimals.Two limits to plan around. The scripts freeze the wallet’s associated token
account only; a wallet holding the token in other accounts needs each frozen
separately. Re-adding the wallet with the Mosaic SDK also thaws its account in
the same transaction; the Kit, Web3.js v3, and Rust scripts add the list entry
only, and the next gated operation on that account thaws it.A forced transfer to a recovery wallet and a forced burn both need the source
account thawed, so run them before the removal, or re-add the wallet for the
duration.Next steps
- Hold a gated token as a custodian: the counterparty side of the token you just built
- Settlement and finality: when a transfer is settled for your books