Last active
August 29, 2024 19:43
-
-
Save astraube/b054a8239b41715596a7633bf49a7348 to your computer and use it in GitHub Desktop.
Solana SPL Token Authority Instruction
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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