current location:Home >> Blockchain knowledge >> how to revoke mint authority solana?

how to revoke mint authority solana?

admin Blockchain knowledge 723

Revoking the mint authority is one of the most important steps to finalize a token and make it immutable (non-inflatable). Once revoked, no new tokens can ever be minted.

how to revoke mint authority solana?

Here’s a comprehensive guide on how to do it, covering both the Solana CLI and popular JavaScript/Typescript methods.

The Core Concept

The mint authority is an account that holds the permission to mint new tokens. "Revoking" this authority means permanently removing that permission by setting the mint authority field on the token's mint account to null.

Key Point: This action is irreversible. Once the mint authority is set to null, it can never be set again, and no one can ever mint more of that token.


Prerequisites

  1. The Token's Mint Address: The public key of the token you created.

  2. The Current Mint Authority's Keypair: This is the wallet that currently has minting rights. You need its file (e.g., mint-authority.json) or it must be in your Phantom/Solflare wallet.

  3. A Small Amount of SOL: You need SOL in the mint authority wallet to pay for the transaction fees.


Method 1: Using the Solana CLI (Recommended for simplicity)

The Solana CLI Toolsuite is the most straightforward way to do this.

Step 1: Setup

First, ensure your CLI is configured to use the correct wallet as the mint authority.

bash
# Check your current configsolana config get# Set your keypair path as the default authority (if it isn't already)solana config set --keypair 
~/path/to/your/mint-authority-keypair.json# Set to the correct cluster (mainnet-beta is the default, but be sure)solana config set --url 
https://api.mainnet-beta.solana.com # For mainnet# or for devnetsolana config set --url https://api.devnet.solana.com

Step 2: Execute the Revoke Command

Use the spl-token authorize command with the --disable flag for the mint authority.

bash
spl-token authorize <TOKEN_MINT_ADDRESS> mint --disable
  • Replace <TOKEN_MINT_ADDRESS> with the actual public key of your token.

  • The mint argument specifies we are changing the mint authority.

  • The --disable flag is what sets the authority to null.

Example:

bash
spl-token authorize 7x2...Hu9 mint --disable

Step 3: Verify

Confirm the authority was successfully revoked.

bash
spl-token display <TOKEN_MINT_ADDRESS># orspl-token account-info <TOKEN_MINT_ADDRESS>

Look at the output. The Mint Authority field should now say None or null, indicating it has been successfully revoked.


Method 2: Using JavaScript/Typescript with @solana/spl-token

This is the method you would use if you are building a dApp or need to integrate this action into a script.

Step 1: Setup Your Environment

Install the necessary npm packages.

bash
npm install @solana/web3.js @solana/spl-token

Step 2: Write the Revocation Script

Here is a complete sample script.

javascript
const { Connection, clusterApiUrl, PublicKey, Keypair } = require('@solana/web3.js');const { splTokenProgram, authorize, AuthorityType } = require('@solana/spl-token');// 1. Connect to the networkconst connection = new Connection(clusterApiUrl('mainnet-beta')); // or 'devnet'// 2. Define the key playersconst mintAuthorityKeypair = Keypair.fromSecretKey(
  Uint8Array.from(JSON.parse(process.env.MINT_AUTHORITY_SECRET_KEY)) // Load from .env file
  // Alternatively, you can paste the array directly (UNSAFE for production));const tokenMintAddress = new PublicKey('YOUR_TOKEN_MINT_PUBKEY_HERE'); // Replace thisasync function revokeMintAuthority() {
  try {
    // 3. Create the transaction to set the mint authority to null
    const transaction = await authorize(
      connection,
      mintAuthorityKeypair.payer, // Payer of the fee (the mint authority)
      tokenMintAddress,           // The token's mint address
      mintAuthorityKeypair,       // The current mint authority (must sign)
      null,                       // The NEW authority (null to revoke)
      AuthorityType.MintTokens    // The type of authority we are revoking
    );

    console.log('Transaction signature:', transaction);
    console.log('✅ Mint Authority successfully revoked!');

  } catch (error) {
    console.error('❌ Error revoking mint authority:', error);
  }}revokeMintAuthority();

Explanation of the JS Code:

  1. Connection: Establishes a link to the Solana network.

  2. Keypair & PublicKey: Loads the sensitive mint authority keypair and defines the token's mint address.

  3. authorize() function: This is the crucial function from @solana/spl-token.

    • connection: The Solana network connection.

    • payer: The account paying for the transaction fee.

    • account: The token mint address.

    • currentAuthority: The keypair of the current mint authority (must sign the transaction).

    • newAuthority: The new authority. Passing null revokes the permission.

    • authorityType: Specifies which authority to change. AuthorityType.MintTokens is the correct type for the mint authority.


Important Considerations & Best Practices

  1. Security: The mint authority keypair is extremely powerful. Keep it secure until you are ready to revoke it. After revocation, you can and should discard it, as it no longer has any special power over the token supply.

  2. Finality: Be 100% certain you will never need to mint more tokens before you execute this command. There is no undo button.

  3. Freeze Authority: Revoking the mint authority does not affect the freeze authority. The freeze authority is a separate permission that can also be revoked (using a very similar CLI command: spl-token authorize <MINT_ADDRESS> freeze --disable).

  4. Testing: Always test this process on devnet first with a dummy token before doing it with a real token on mainnet.

By following these steps, you can successfully and permanently revoke the mint authority of your SPL token on the Solana blockchain.

If you have any questions or uncertainties, please join the official Telegram group: https://t.me/GToken_EN

GTokenTool

GTokenTool is the most comprehensive one click coin issuance tool, supporting multiple public chains such as TON, SOL, BSC, etc. Function: Create tokensmarket value managementbatch airdropstoken pre-sales IDO、 Lockpledge mining, etc. Provide a visual interface that allows users to quickly create, deploy, and manage their own cryptocurrencies without writing code.

Similar recommendations