mint-close-authority.ts 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. import * as anchor from '@coral-xyz/anchor';
  2. import type { Program } from '@coral-xyz/anchor';
  3. import { TOKEN_2022_PROGRAM_ID, closeAccount } from '@solana/spl-token';
  4. import type { MintCloseAuthority } from '../target/types/mint_close_authority';
  5. describe('mint-close-authority', () => {
  6. // Configure the client to use the local cluster.
  7. const provider = anchor.AnchorProvider.env();
  8. const connection = provider.connection;
  9. const wallet = provider.wallet as anchor.Wallet;
  10. anchor.setProvider(provider);
  11. const program = anchor.workspace.MintCloseAuthority as Program<MintCloseAuthority>;
  12. const mintKeypair = new anchor.web3.Keypair();
  13. it('Create Mint with Close Authority', async () => {
  14. const transactionSignature = await program.methods
  15. .initialize()
  16. .accounts({ mintAccount: mintKeypair.publicKey })
  17. .signers([mintKeypair])
  18. .rpc({ skipPreflight: true });
  19. console.log('Your transaction signature', transactionSignature);
  20. });
  21. it('Close Mint with Anchor CPI', async () => {
  22. const transactionSignature = await program.methods.close().accounts({ mintAccount: mintKeypair.publicKey }).rpc({ skipPreflight: true });
  23. console.log('Your transaction signature', transactionSignature);
  24. });
  25. it('Create Mint with Close Authority again', async () => {
  26. const transactionSignature = await program.methods
  27. .initialize()
  28. .accounts({ mintAccount: mintKeypair.publicKey })
  29. .signers([mintKeypair])
  30. .rpc({ skipPreflight: true });
  31. console.log('Your transaction signature', transactionSignature);
  32. });
  33. it('Close Mint using @solana/spl-token', async () => {
  34. const transactionSignature = await closeAccount(
  35. connection,
  36. wallet.payer, // Transaction fee payer
  37. mintKeypair.publicKey, // Mint Account address
  38. wallet.publicKey, // Account to receive lamports from closed account
  39. wallet.publicKey, // Close Authority for Mint Account
  40. undefined, // Additional signers
  41. undefined, // Confirmation options
  42. TOKEN_2022_PROGRAM_ID, // Token Extension Program ID
  43. );
  44. console.log('Your transaction signature', transactionSignature);
  45. });
  46. });