Skip to content

Instantly share code, notes, and snippets.

@lorisleiva
Created April 4, 2023 09:00
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save lorisleiva/d4a69d5fe7dcaf73d8f6855c0e0bfd1f to your computer and use it in GitHub Desktop.
Clear the closeAuthority on a token account
import { createSetAuthorityInstruction, AuthorityType } from '@solana/spl-token';
import { Transaction } from '@solana/web3.js';
const instruction = createSetAuthorityInstruction(
token.publicKey,
closeAuthority.publicKey,
AuthorityType.CloseAccount,
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,
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