lumberjack.ts 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. import * as anchor from '@coral-xyz/anchor';
  2. import type { Program } from '@coral-xyz/anchor';
  3. import { ASSOCIATED_PROGRAM_ID } from '@coral-xyz/anchor/dist/cjs/utils/token';
  4. import { ASSOCIATED_TOKEN_PROGRAM_ID, TOKEN_2022_PROGRAM_ID, getAssociatedTokenAddressSync } from '@solana/spl-token';
  5. import { Keypair, PublicKey } from '@solana/web3.js';
  6. import type { ExtensionNft } from '../target/types/extension_nft';
  7. describe('extension_nft', () => {
  8. const provider = anchor.AnchorProvider.env();
  9. anchor.setProvider(provider);
  10. const program = anchor.workspace.ExtensionNft as Program<ExtensionNft>;
  11. const payer = provider.wallet as anchor.Wallet;
  12. it('Mint nft!', async () => {
  13. const balance = await anchor.getProvider().connection.getBalance(payer.publicKey);
  14. if (balance < 1e8) {
  15. const res = await anchor.getProvider().connection.requestAirdrop(payer.publicKey, 1e9);
  16. await anchor.getProvider().connection.confirmTransaction(res, 'confirmed');
  17. }
  18. const mint = new Keypair();
  19. console.log('Mint public key', mint.publicKey.toBase58());
  20. const destinationTokenAccount = getAssociatedTokenAddressSync(
  21. mint.publicKey,
  22. payer.publicKey,
  23. false,
  24. TOKEN_2022_PROGRAM_ID,
  25. ASSOCIATED_TOKEN_PROGRAM_ID,
  26. );
  27. const nft_authority = await PublicKey.findProgramAddress([Buffer.from('nft_authority')], program.programId);
  28. const tx = await program.methods
  29. .mintNft()
  30. .accounts({
  31. signer: payer.publicKey,
  32. systemProgram: anchor.web3.SystemProgram.programId,
  33. tokenProgram: TOKEN_2022_PROGRAM_ID,
  34. associatedTokenProgram: ASSOCIATED_PROGRAM_ID,
  35. tokenAccount: destinationTokenAccount,
  36. mint: mint.publicKey,
  37. nftAuthority: nft_authority[0],
  38. rent: anchor.web3.SYSVAR_RENT_PUBKEY,
  39. })
  40. .signers([mint])
  41. .rpc({ skipPreflight: true });
  42. console.log('Mint nft tx', tx);
  43. await anchor.getProvider().connection.confirmTransaction(tx, 'confirmed');
  44. });
  45. });