Here's the different ways to do this.
You have to set the new authority as null
. This also applies when you want to revoke the mint authority as well.
Using @solana/spl-token
import { AuthorityType, createSetAuthorityInstruction } from "@solana/spl-token";
import {
clusterApiUrl,
Connection,
PublicKey,
sendAndConfirmTransaction,
Transaction,
} from "@solana/web3.js";
const DEVNET_ENDPOINT = clusterApiUrl("devnet");
const conn = new Connection(DEVNET_ENDPOINT);
async function revokeFreezeAuth() {
let signer = Keypair.fromSecretKey(Uint8Array.from([])) // update with correct 8-bit array
let mint = new PublicKey("UPDATE WITH MINT ADDRESS");
let currentAuthority = signer.publicKey;
let freezeAuthIx = createSetAuthorityInstruction(
mint,
currentAuthority,
AuthorityType.FreezeAccount,
null
);
const tx = await new Transaction().add(freezeAuthIx);
let txHash = await sendAndConfirmTransaction(conn, tx, [signer]);
console.log(txHash);
}
revokeFreezeAuth().then().catch(console.error);
Rust Anchor
To revoke the mint authority we set the mint authority as None which disables all future mintin. This action is irreversible.
use anchor_lang::prelude::*;
use anchor_spl::token::{
set_authority, spl_token::instruction::AuthorityType, Mint, SetAuthority, Token,
};
#[derive(Accounts)]
pub struct RevokeFreezeAuth<'info> {
#[account(mut)]
pub payer: Signer<'info>,
#[account(mut)]
pub mint: Account<'info, Mint>,
pub token_program: Program<'info, Token>,
pub system_program: Program<'info, System>,
}
pub fn revoke_freeze_auth(ctx: Context<RevokeMintAuth>) -> Result<()> {
let cpi_program = ctx.accounts.token_program.to_account_info();
let cpi_accounts = SetAuthority {
account_or_mint: ctx.accounts.mint.to_account_info(),
current_authority: ctx.accounts.payer.to_account_info(),
};
let cpi_ctx = CpiContext::new(cpi_program, cpi_accounts);
set_authority(cpi_ctx, AuthorityType::FreezeAccount, None)?;
Ok(())
}
CLI
spl-token authorize {token_address} freeeze --disable
UMI
required dependencies
npm install \
@metaplex-foundation/umi \
@metaplex-foundation/umi-bundle-defaults \
@solana/web3.js \
@metaplex-foundation/mpl-token-metadata \
@metaplex-foundation/mpl-toolbox \
@solana/web3.js \
import {
mplTokenMetadata,
} from "@metaplex-foundation/mpl-token-metadata";
import { AuthorityType, setAuthority } from "@metaplex-foundation/mpl-toolbox";
import {
keypairIdentity,
publicKey,
signTransaction,
} from "@metaplex-foundation/umi";
import { createUmi } from "@metaplex-foundation/umi-bundle-defaults";
import { toWeb3JsTransaction } from "@metaplex-foundation/umi-web3js-adapters";
import { clusterApiUrl, Connection } from "@solana/web3.js";
const DEVNET_ENDPOINT = clusterApiUrl("devnet");
const conn = new Connection(DEVNET_ENDPOINT);
const umi = createUmi(DEVNET_ENDPOINT);
const keypair = umi.eddsa.createKeypairFromSecretKey(Uint8Array.from([])); // update with correct 8-bit array of signer secret key
umi.use(keypairIdentity(keypair)).use(mplTokenMetadata());
async function revokeFreezeAuth() {
let setAuthTx = await setAuthority(umi, {
owner: umi.identity,
owned: publicKey("YOUR MINT ADDRESS"),
authorityType: AuthorityType.FreezeAccount,
newAuthority: null,
}).buildWithLatestBlockhash(umi);
// sign with the umi transaction
let signedTX = await signTransaction(setAuthTx, [umi.identity]);
//convert to web3 js TX
const web3TX = toWeb3JsTransaction(signedTX);
let txHash = await conn.sendTransaction(web3TX, { skipPreflight: true });
console.log(txHash);
}
revokeFreezeAuth().then().catch(console.error);