lumberjack.ts 2.0 KB

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