> ## Documentation Index
> Fetch the complete documentation index at: https://solana.com/llms.txt
> Use this file to discover all available pages before exploring further.

> ## Agent Instructions
> This page is part of the Solana developer documentation at https://solana.com/developers/docs. Append `.md` to any docs URL, or send `Accept: text/markdown`, to get the page as Markdown.
> Index of all pages: https://solana.com/llms.txt. Per-section indexes such as https://solana.com/developers/docs/payments/llms.txt are smaller; prefer them when working on one task.
> Coding agents: install the official Solana skill for current APIs and conventions with `npx skills add https://github.com/solana-foundation/solana-dev-skill` (also served at https://solana.com/SKILL.md).
> Code in the cookbook and task pages comes from tested example files. Prefer it over writing API calls from memory.

# Set Authority

> Change or revoke authority roles on a mint or token account, including mint, freeze, owner, and close authority.

## What Does Setting Authority Do?

Setting authority changes or revokes specific authority roles on a mint or token
account.

Mint accounts can store a mint authority and a freeze authority. Token accounts
store an owner and can optionally store a close authority. Each role controls a
specific permission set, and setting an authority to `None` permanently
removes the selected authority role.

The Token Extension Program also defines additional authority types for specific
extensions.

## How to Set Authority

Changing an authority uses the Token Program's `SetAuthority` instruction.

Each call updates one authority type on one mint or token account. The current
authority signs the change, and the new authority may be another address or
`None` to revoke the selected authority permanently.

### Source Reference

| Item                    | Description                                                                      | Token Program                                                                                                  | Token Extension Program                                                                                                |
| ----------------------- | -------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------- |
| `Mint`                  | The mint state stores `mint_authority` and `freeze_authority`.                   | [Source](https://github.com/solana-program/token/blob/program%40v9.0.0/interface/src/state.rs#L13-L30)         | [Source](https://github.com/solana-program/token-2022/blob/program%40v10.0.0/interface/src/state.rs#L25-L42)           |
| `Account`               | The token account state stores `owner` and `close_authority`.                    | [Source](https://github.com/solana-program/token/blob/program%40v9.0.0/interface/src/state.rs#L84-L108)        | [Source](https://github.com/solana-program/token-2022/blob/program%40v10.0.0/interface/src/state.rs#L99-L123)          |
| `AuthorityType`         | The authority roles that `SetAuthority` can update.                              | [Source](https://github.com/solana-program/token/blob/program%40v9.0.0/interface/src/instruction.rs#L739-L751) | [Source](https://github.com/solana-program/token-2022/blob/program%40v10.0.0/interface/src/instruction.rs#L1116-L1157) |
| `SetAuthority`          | An instruction that changes or revokes one authority on a mint or token account. | [Source](https://github.com/solana-program/token/blob/program%40v9.0.0/interface/src/instruction.rs#L141-L158) | [Source](https://github.com/solana-program/token-2022/blob/program%40v10.0.0/interface/src/instruction.rs#L183-L200)   |
| `process_set_authority` | Shared processor logic for authority updates.                                    | [Source](https://github.com/solana-program/token/blob/program%40v9.0.0/program/src/processor.rs#L423-L518)     | [Source](https://github.com/solana-program/token-2022/blob/program%40v10.0.0/program/src/processor.rs#L677-L978)       |

### Kit

These examples use `@solana/kit`.

<CodeGroup>

```ts Plugin highlight={16,32-43} expandable
import { createClient, generateKeyPairSigner, lamports } from "@solana/kit";
import { solanaRpc, rpcAirdrop } from "@solana/kit-plugin-rpc";
import { generatedPayer, airdropPayer } from "@solana/kit-plugin-signer";
import { AuthorityType, tokenProgram } from "@solana-program/token";

const client = await createClient()
  .use(generatedPayer())
  .use(
    solanaRpc({
      rpcUrl: "http://localhost:8899",
      rpcSubscriptionsUrl: "ws://localhost:8900"
    })
  )
  .use(rpcAirdrop())
  .use(airdropPayer(lamports(1_000_000_000n)))
  .use(tokenProgram());

const mint = await generateKeyPairSigner();
const newAuthority = await generateKeyPairSigner();

// Setup: create a mint before changing its authorities.
await client.token.instructions
  .createMint({
    newMint: mint,
    decimals: 2,
    mintAuthority: client.payer.address,
    freezeAuthority: client.payer.address
  })
  .sendTransaction();

const result = await client.sendTransaction([
  client.token.instructions.setAuthority({
    owned: mint.address, // Mint whose authority changes.
    owner: client.payer, // Current authority approving this change.
    authorityType: AuthorityType.MintTokens, // Authority role to update on the mint.
    newAuthority: newAuthority.address // New authority to assign to this role.
  }),
  client.token.instructions.setAuthority({
    owned: mint.address, // Mint whose authority changes.
    owner: client.payer, // Current authority approving this change.
    authorityType: AuthorityType.FreezeAccount, // Authority role to update on the mint.
    newAuthority: newAuthority.address // New authority to assign to this role.
  })
]);

const mintAccount = await client.token.accounts.mint.fetch(mint.address);

console.log("Mint Address:", mint.address);
console.log("Mint Account:", mintAccount.data);
console.log("\nNew Authority Address:", newAuthority.address);
console.log("\nTransaction Signature:", result.context.signature);
```

```ts Instructions highlight={37-48} expandable
import { createClient, generateKeyPairSigner, lamports } from "@solana/kit";
import { solanaRpc, rpcAirdrop } from "@solana/kit-plugin-rpc";
import { generatedPayer, airdropPayer } from "@solana/kit-plugin-signer";
import {
  AuthorityType,
  fetchMint,
  getCreateMintInstructionPlan,
  getSetAuthorityInstruction
} from "@solana-program/token";

const client = await createClient()
  .use(generatedPayer())
  .use(
    solanaRpc({
      rpcUrl: "http://localhost:8899",
      rpcSubscriptionsUrl: "ws://localhost:8900"
    })
  )
  .use(rpcAirdrop())
  .use(airdropPayer(lamports(1_000_000_000n)));

const mint = await generateKeyPairSigner();
const newAuthority = await generateKeyPairSigner();

// Setup: create a mint before changing its authorities.
await client.sendTransaction(
  await getCreateMintInstructionPlan(client, {
    payer: client.payer,
    newMint: mint,
    decimals: 2,
    mintAuthority: client.payer.address,
    freezeAuthority: client.payer.address
  })
);

const result = await client.sendTransaction([
  getSetAuthorityInstruction({
    owned: mint.address, // Mint whose authority changes.
    owner: client.payer, // Current authority approving this change.
    authorityType: AuthorityType.MintTokens, // Authority role to update on the mint.
    newAuthority: newAuthority.address // New authority to assign to this role.
  }),
  getSetAuthorityInstruction({
    owned: mint.address, // Mint whose authority changes.
    owner: client.payer, // Current authority approving this change.
    authorityType: AuthorityType.FreezeAccount, // Authority role to update on the mint.
    newAuthority: newAuthority.address // New authority to assign to this role.
  })
]);

const mintAccount = await fetchMint(client.rpc, mint.address);

console.log("Mint Address:", mint.address);
console.log("Mint Account:", mintAccount.data);
console.log("\nNew Authority Address:", newAuthority.address);
console.log("\nTransaction Signature:", result.context.signature);
```

</CodeGroup>

### Web3.js v3

These examples use the class-based `@solana/web3.js` v3 API with
`@solana-program` instruction builders.

```ts Instructions highlight={67-78} expandable
import {
  Connection,
  Keypair,
  sendAndConfirmTransaction,
  Transaction,
  LAMPORTS_PER_SOL
} from "@solana/web3.js";
import {
  AuthorityType,
  getCreateMintInstructionPlan,
  getMintDecoder,
  getSetAuthorityInstruction
} from "@solana-program/token";

// Setup: create a mint before changing its authorities.
const connection = new Connection("http://localhost:8899", "confirmed");
const latestBlockhash = await connection.getLatestBlockhash();

const feePayer = await Keypair.generate();
const newAuthority = await Keypair.generate();

const airdropSignature = await connection.requestAirdrop(
  feePayer.publicKey,
  LAMPORTS_PER_SOL
);
await connection.confirmTransaction({
  blockhash: latestBlockhash.blockhash,
  lastValidBlockHeight: latestBlockhash.lastValidBlockHeight,
  signature: airdropSignature
});

const mint = await Keypair.generate();

await sendAndConfirmTransaction(
  connection,
  new Transaction({
    feePayer: feePayer.publicKey,
    blockhash: latestBlockhash.blockhash,
    lastValidBlockHeight: latestBlockhash.lastValidBlockHeight
  }).add(
    await getCreateMintInstructionPlan(
      {
        getMinimumBalance: (space: number) =>
          connection.getMinimumBalanceForRentExemption(space)
      },
      {
        payer: feePayer,
        newMint: mint,
        decimals: 2,
        mintAuthority: feePayer.publicKey.toBase58(),
        freezeAuthority: feePayer.publicKey.toBase58()
      }
    )
  ),
  [feePayer, mint]
);

const authorityBlockhash = await connection.getLatestBlockhash();

const result = await sendAndConfirmTransaction(
  connection,
  new Transaction({
    feePayer: feePayer.publicKey,
    blockhash: authorityBlockhash.blockhash,
    lastValidBlockHeight: authorityBlockhash.lastValidBlockHeight
  }).add(
    getSetAuthorityInstruction({
      owned: mint.publicKey, // Mint whose authority changes.
      owner: feePayer, // Current authority approving this change.
      authorityType: AuthorityType.MintTokens, // Authority role to update on the mint.
      newAuthority: newAuthority.publicKey.toBase58() // New authority to assign to this role.
    }),
    getSetAuthorityInstruction({
      owned: mint.publicKey, // Mint whose authority changes.
      owner: feePayer, // Current authority approving this change.
      authorityType: AuthorityType.FreezeAccount, // Authority role to update on the mint.
      newAuthority: newAuthority.publicKey.toBase58() // New authority to assign to this role.
    })
  ),
  [feePayer]
);

const mintAccountInfo = await connection.getAccountInfo(mint.publicKey);
const mintAccount = getMintDecoder().decode(mintAccountInfo!.data);

console.log("Mint Address:", mint.publicKey.toBase58());
console.log("Mint Account:", mintAccount);
console.log("\nNew Authority Address:", newAuthority.publicKey.toBase58());
console.log("\nTransaction Signature:", result);
```

### Rust

Add these dependencies to `Cargo.toml` (tested with Rust 1.89 and 1.98):

```toml Cargo.toml
[dependencies]
anyhow = "1"
tokio = { version = "1", features = ["full"] }
solana-client = "2"
solana-commitment-config = "2"
solana-sdk = "2"
solana-system-interface = "1"
spl-token-interface = "1"
```

```rust Rust highlight={69-84} expandable
use anyhow::Result;
use solana_client::nonblocking::rpc_client::RpcClient;
use solana_commitment_config::CommitmentConfig;
use solana_sdk::{
    program_pack::Pack,
    signature::{Keypair, Signer},
    transaction::Transaction,
};
use solana_system_interface::instruction::create_account;
use spl_token_interface::{
    id as token_program_id,
    instruction::{initialize_mint, set_authority, AuthorityType},
    state::Mint,
};

#[tokio::main]
async fn main() -> Result<()> {
    let client = RpcClient::new_with_commitment(
        String::from("http://localhost:8899"),
        CommitmentConfig::confirmed(),
    );
    let new_authority = Keypair::new();

    // Setup: create a mint before changing its authorities.
    let fee_payer = Keypair::new();

    let airdrop_signature = client
        .request_airdrop(&fee_payer.pubkey(), 1_000_000_000)
        .await?;
    loop {
        let confirmed = client.confirm_transaction(&airdrop_signature).await?;
        if confirmed {
            break;
        }
    }

    let mint = Keypair::new();
    let mint_rent = client
        .get_minimum_balance_for_rent_exemption(Mint::LEN)
        .await?;
    let latest_blockhash = client.get_latest_blockhash().await?;
    let setup_transaction = Transaction::new_signed_with_payer(
        &[
            create_account(
                &fee_payer.pubkey(),
                &mint.pubkey(),
                mint_rent,
                Mint::LEN as u64,
                &token_program_id(),
            ),
            initialize_mint(
                &token_program_id(),
                &mint.pubkey(),
                &fee_payer.pubkey(),
                Some(&fee_payer.pubkey()),
                2,
            )?,
        ],
        Some(&fee_payer.pubkey()),
        &[&fee_payer, &mint],
        latest_blockhash,
    );
    client
        .send_and_confirm_transaction(&setup_transaction)
        .await?;

    let transaction = Transaction::new_signed_with_payer(
        &[
            set_authority(
                &token_program_id(), // Token program to invoke.
                &mint.pubkey(), // Mint whose authority changes.
                Some(&new_authority.pubkey()), // New authority to assign to this role.
                AuthorityType::MintTokens, // Authority role to update on the mint.
                &fee_payer.pubkey(), // Current authority approving this change.
                &[], // Additional multisig signers.
            )?,
            set_authority(
                &token_program_id(), // Token program to invoke.
                &mint.pubkey(), // Mint whose authority changes.
                Some(&new_authority.pubkey()), // New authority to assign to this role.
                AuthorityType::FreezeAccount, // Authority role to update on the mint.
                &fee_payer.pubkey(), // Current authority approving this change.
                &[], // Additional multisig signers.
            )?,
        ],
        Some(&fee_payer.pubkey()),
        &[&fee_payer],
        latest_blockhash,
    );

    let transaction_signature = client.send_and_confirm_transaction(&transaction).await?;
    let mint_account = client.get_account(&mint.pubkey()).await?;
    let mint_data = Mint::unpack(&mint_account.data)?;

    println!("Mint Address: {}", mint.pubkey());
    println!("Mint Account: {:#?}", mint_data);
    println!("\nNew Authority Address: {}", new_authority.pubkey());
    println!("\nTransaction Signature: {}", transaction_signature);

    Ok(())
}
```

### Python

This example uses `solana` (solana-py) 0.41 and `solders`:

```bash Terminal
pip install solana==0.41.0 solders==0.29.0
```

```py Python highlight={47-55} expandable
#!/usr/bin/env python3

import asyncio
import json
from solana.rpc.async_api import AsyncClient
from solders.keypair import Keypair
from solders.message import Message
from solders.system_program import create_account, CreateAccountParams
from solders.transaction import Transaction
from solders.token.state import Mint
from spl.token.instructions import AuthorityType, initialize_mint, set_authority
from spl.token.models import InitializeMintParams, SetAuthorityParams
from spl.token.constants import MINT_LEN, TOKEN_PROGRAM_ID

def mint_to_dict(mint_account: Mint) -> dict:
    return {
        "mint_authority": None if mint_account.mint_authority is None else str(mint_account.mint_authority),
        "supply": mint_account.supply,
        "decimals": mint_account.decimals,
        "is_initialized": mint_account.is_initialized,
        "freeze_authority": None if mint_account.freeze_authority is None else str(mint_account.freeze_authority),
    }

async def main():
    rpc = AsyncClient("http://localhost:8899")

    new_authority = Keypair()

    async with rpc:
        # Setup: create a mint before changing the mint authority.
        fee_payer = Keypair()
        airdrop_signature = (await rpc.request_airdrop(fee_payer.pubkey(), 1_000_000_000)).value
        await rpc.confirm_transaction(airdrop_signature)
        mint = Keypair()
        mint_rent = (await rpc.get_minimum_balance_for_rent_exemption(MINT_LEN)).value
        setup_instructions = [
            create_account(CreateAccountParams(from_pubkey=fee_payer.pubkey(), to_pubkey=mint.pubkey(), lamports=mint_rent, space=MINT_LEN, owner=TOKEN_PROGRAM_ID)),
            initialize_mint(InitializeMintParams(decimals=2, program_id=TOKEN_PROGRAM_ID, mint=mint.pubkey(), mint_authority=fee_payer.pubkey())),
        ]
        setup_blockhash = await rpc.get_latest_blockhash()
        setup_transaction = Transaction(
            [fee_payer, mint],
            Message(setup_instructions, fee_payer.pubkey()),
            setup_blockhash.value.blockhash,
        )
        await rpc.send_transaction(setup_transaction)
        set_authority_instruction = set_authority(
            SetAuthorityParams(
                program_id=TOKEN_PROGRAM_ID,  # Token program to invoke.
                account=mint.pubkey(),  # Mint whose authority changes.
                authority=AuthorityType.MINT_TOKENS,  # Authority role to update.
                current_authority=fee_payer.pubkey(),  # Current authority approving the authority update.
                new_authority=new_authority.pubkey(),  # New authority for the selected role.
            )
        )
        latest_blockhash = await rpc.get_latest_blockhash()
        transaction = Transaction(
            [fee_payer],
            Message([set_authority_instruction], fee_payer.pubkey()),
            latest_blockhash.value.blockhash,
        )
        result = await rpc.send_transaction(transaction)

        mint_info = Mint.from_bytes((await rpc.get_account_info(mint.pubkey())).value.data)
        mint_account = mint_to_dict(mint_info)

        print("Mint Address:", mint.pubkey())
        print("Mint Account:")
        print(json.dumps(mint_account, indent=2))
        print("\nNew Authority Address:", new_authority.pubkey())
        print("\nTransaction Signature:", result.value)

if __name__ == "__main__":
    asyncio.run(main())
```

### Web3.js (legacy)

These examples use legacy `@solana/web3.js` 1.x with `@solana/spl-token`.

<Warning>
  **`@solana/web3.js` 1.x is no longer actively maintained**

  It receives critical fixes only. Use [Kit](/developers/docs/clients/official/javascript#solana-kit) for new code. To migrate existing code, follow the [Kit upgrade guide](https://www.solanakit.com/docs/upgrade-guide), or the [web3.js v3 migration guide](https://github.com/solana-foundation/solana-web3.js/blob/main/docs/web3js-v1-to-v3-migration.md) to keep the class-based API.

  To run this code, install 1.x with `npm install @solana/web3.js@1`. A plain `npm install @solana/web3.js` installs v3, which this code doesn't run on.
</Warning>

<CodeGroup>

```ts title="Helper Function" highlight={47-72} expandable
import {
  Connection,
  Keypair,
  sendAndConfirmTransaction,
  Transaction,
  LAMPORTS_PER_SOL
} from "@solana/web3.js";
import {
  createMint,
  AuthorityType,
  createSetAuthorityInstruction,
  getMint,
  TOKEN_PROGRAM_ID
} from "@solana/spl-token";

// Setup: create a mint before changing its authorities.
const connection = new Connection("http://localhost:8899", "confirmed");
const latestBlockhash = await connection.getLatestBlockhash();

const feePayer = Keypair.generate();
const newAuthority = Keypair.generate();

const airdropSignature = await connection.requestAirdrop(
  feePayer.publicKey,
  LAMPORTS_PER_SOL
);
await connection.confirmTransaction({
  blockhash: latestBlockhash.blockhash,
  lastValidBlockHeight: latestBlockhash.lastValidBlockHeight,
  signature: airdropSignature
});

const mintPubkey = await createMint(
  connection,
  feePayer,
  feePayer.publicKey,
  feePayer.publicKey,
  2,
  Keypair.generate(),
  {
    commitment: "confirmed"
  },
  TOKEN_PROGRAM_ID
);

const authorityBlockhash = await connection.getLatestBlockhash();
const result = await sendAndConfirmTransaction(
  connection,
  new Transaction({
    feePayer: feePayer.publicKey,
    blockhash: authorityBlockhash.blockhash,
    lastValidBlockHeight: authorityBlockhash.lastValidBlockHeight
  }).add(
    createSetAuthorityInstruction(
      mintPubkey, // Mint whose authority changes.
      feePayer.publicKey, // Current authority approving this change.
      AuthorityType.MintTokens, // Authority role to update on the mint.
      newAuthority.publicKey, // New authority to assign to this role.
      [], // Additional multisig signers.
      TOKEN_PROGRAM_ID // Token program to invoke.
    ),
    createSetAuthorityInstruction(
      mintPubkey, // Mint whose authority changes.
      feePayer.publicKey, // Current authority approving this change.
      AuthorityType.FreezeAccount, // Authority role to update on the mint.
      newAuthority.publicKey, // New authority to assign to this role.
      [], // Additional multisig signers.
      TOKEN_PROGRAM_ID // Token program to invoke.
    )
  ),
  [feePayer]
);

const mintAccount = await getMint(
  connection,
  mintPubkey,
  "confirmed",
  TOKEN_PROGRAM_ID
);

console.log("Mint Address:", mintPubkey.toBase58());
console.log("Mint Account:", mintAccount);
console.log("\nNew Authority Address:", newAuthority.publicKey.toBase58());
console.log("\nTransaction Signature:", result);
```

```ts Instructions highlight={72-87} expandable
import {
  Connection,
  Keypair,
  sendAndConfirmTransaction,
  SystemProgram,
  Transaction,
  LAMPORTS_PER_SOL
} from "@solana/web3.js";
import {
  createSetAuthorityInstruction,
  createInitializeMintInstruction,
  AuthorityType,
  getMinimumBalanceForRentExemptMint,
  getMint,
  MINT_SIZE,
  TOKEN_PROGRAM_ID
} from "@solana/spl-token";

// Setup: create a mint before changing its authorities.
const connection = new Connection("http://localhost:8899", "confirmed");
const latestBlockhash = await connection.getLatestBlockhash();

const feePayer = Keypair.generate();
const newAuthority = Keypair.generate();

const airdropSignature = await connection.requestAirdrop(
  feePayer.publicKey,
  LAMPORTS_PER_SOL
);
await connection.confirmTransaction({
  blockhash: latestBlockhash.blockhash,
  lastValidBlockHeight: latestBlockhash.lastValidBlockHeight,
  signature: airdropSignature
});

const mint = Keypair.generate();
const mintRent = await getMinimumBalanceForRentExemptMint(connection);
await sendAndConfirmTransaction(
  connection,
  new Transaction({
    feePayer: feePayer.publicKey,
    blockhash: latestBlockhash.blockhash,
    lastValidBlockHeight: latestBlockhash.lastValidBlockHeight
  }).add(
    SystemProgram.createAccount({
      fromPubkey: feePayer.publicKey,
      newAccountPubkey: mint.publicKey,
      space: MINT_SIZE,
      lamports: mintRent,
      programId: TOKEN_PROGRAM_ID
    }),
    createInitializeMintInstruction(
      mint.publicKey,
      2,
      feePayer.publicKey,
      feePayer.publicKey,
      TOKEN_PROGRAM_ID
    )
  ),
  [feePayer, mint]
);

const authorityBlockhash = await connection.getLatestBlockhash();

const result = await sendAndConfirmTransaction(
  connection,
  new Transaction({
    feePayer: feePayer.publicKey,
    blockhash: authorityBlockhash.blockhash,
    lastValidBlockHeight: authorityBlockhash.lastValidBlockHeight
  }).add(
    createSetAuthorityInstruction(
      mint.publicKey, // Mint whose authority changes.
      feePayer.publicKey, // Current authority approving this change.
      AuthorityType.MintTokens, // Authority role to update on the mint.
      newAuthority.publicKey, // New authority to assign to this role.
      [], // Additional multisig signers.
      TOKEN_PROGRAM_ID // Token program to invoke.
    ),
    createSetAuthorityInstruction(
      mint.publicKey, // Mint whose authority changes.
      feePayer.publicKey, // Current authority approving this change.
      AuthorityType.FreezeAccount, // Authority role to update on the mint.
      newAuthority.publicKey, // New authority to assign to this role.
      [], // Additional multisig signers.
      TOKEN_PROGRAM_ID // Token program to invoke.
    )
  ),
  [feePayer]
);

const mintAccount = await getMint(
  connection,
  mint.publicKey,
  "confirmed",
  TOKEN_PROGRAM_ID
);

console.log("Mint Address:", mint.publicKey.toBase58());
console.log("Mint Account:", mintAccount);
console.log("\nNew Authority Address:", newAuthority.publicKey.toBase58());
console.log("\nTransaction Signature:", result);
```

</CodeGroup>
