Freeze and Thaw Instructions
Freeze prevents all token operations on an account until it's thawed. Only the mint's freeze authority can perform this operation.
Completely disables transfers, approvals, and burns and it only affects the specific frozen account
Thaw re-enables token operations on a previously frozen account. Only the mint's freeze authority can thaw accounts.
Restores full functionality to a frozen account and can only be performed by the mint's freeze authority
Before we can mint any token, we'll need to already have:
- Initialized a
Mint
account which we hold thefreezeAuthority
- Initialized a
Token
account orAssociated Token
account that we want to freeze or thaw
Raw Instruction
By using just "raw" instruction without any abstraction, this is how freezing a token would look like:
const tokenAccount = Keypair.generate();
const tokenAccount = await getAssociatedTokenAddress(
mint.publicKey,
tokenAccount.publicKey,
);
// Create ATA creation instruction
const createAtaInstruction = createAssociatedTokenAccountIdempotentInstruction(
keypair.publicKey, // payer
tokenAccount, // associated token account address
destination.publicKey, // owner
mint.publicKey, // mint
);
// Freeze an ATA
const freezeInstruction = createFreezeAccountInstruction(
tokenAccount // account
mint // mint
keypair.publickey // authority
);
const transaction = new Transaction().add(
createAtaInstruction,
freezeInstruction,
);
const signature = await sendAndConfirmTransaction(connection, transaction, [keypair]);
console.log(`Token accounts created and frozen! Check out your TX here: https://explorer.solana.com/tx/${signature}?cluster=devnet`);
By using just "raw" instruction without any abstraction, this is how revoke a token would look like:
// Thaw an ATA
const thawInstruction = createThawAccountInstruction(
tokenAccount // account
mint // mint
keypair.publickey // authority
);
const transaction = new Transaction().add(thawInstruction);
const signature = await sendAndConfirmTransaction(connection, transaction, [keypair]);
console.log(`Token account thawed! Check out your TX here: https://explorer.solana.com/tx/${signature}?cluster=devnet`);
Abstracted Instruction
This is how the same instructions would look like abstracted away with the freezeAccount()
instruction:
const tokenAccount = Keypair.generate();
const ata = await getOrCreateAssociatedTokenAccount(
connection,
keypair,
mint,
tokenAccount.publicKey
);
console.log(`This is your ATA: ${ata.address}!`)
let tx = await freezeAccount(
connection,
keypair,
tokenAccount // account
mint // mint
keypair.publickey // authority
);
console.log(`Token Account succesfully Frozen!. Transaction Here: https://explorer.solana.com/tx/${tx}?cluster=devnet`)
This is how the same instructions would look like abstracted away with the thawAccount()
instruction:
let tx = await thawAccount(
connection,
keypair,
tokenAccount // account
mint // mint
keypair.publickey // authority
);
console.log(`Token Account succesfully Thawed!. Transaction Here: https://explorer.solana.com/tx/${tx}?cluster=devnet`)