Skip to content

Instantly share code, notes, and snippets.

@astraube
Last active August 29, 2024 19:43
Show Gist options
  • Save astraube/b054a8239b41715596a7633bf49a7348 to your computer and use it in GitHub Desktop.
Save astraube/b054a8239b41715596a7633bf49a7348 to your computer and use it in GitHub Desktop.
Solana SPL Token Authority Instruction
import { createSetAuthorityInstruction, AuthorityType } from '@solana/spl-token';
import { Transaction } from '@solana/web3.js';
const instruction = createSetAuthorityInstruction(
token.publicKey,
closeAuthority.publicKey,
AuthorityType.CloseAccount, // AuthorityType.MintTokens | AuthorityType.FreezeAccount | ...
null
);
const transaction = new Transaction().add(instruction);
const { blockhash } = await connection.getLatestBlockhash();
transaction.recentBlockhash = blockhash;
transaction.feePayer = payer.publicKey;
const signature = await connection.sendTransaction(tx, [payer, closeAuthority]);
await connection.confirmTransaction(signature);
import { setAuthority, AuthorityType } from '@metaplex-foundation/mpl-essentials';
import { none } from '@metaplex-foundation/umi';
await setAuthority(umi, {
owned: token.publicKey,
owner: closeAuthority,
authorityType: AuthorityType.CloseAccount, // AuthorityType.MintTokens | AuthorityType.FreezeAccount | ...
newAuthority: none(),
}).sendAndConfirm(umi);
// See a working example in the following test:
// https://github.com/metaplex-foundation/mpl-essentials/blob/0650eeda9d7b25bc78f80387859c166ce2232103/clients/js/test/setAuthority.test.ts#L33-L59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment