cnft-burn.ts 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. import * as anchor from "@coral-xyz/anchor";
  2. import { Program } from "@coral-xyz/anchor";
  3. import { CnftBurn } from "../target/types/cnft_burn";
  4. import {
  5. MPL_BUBBLEGUM_PROGRAM_ID,
  6. SPL_ACCOUNT_COMPRESSION_PROGRAM_ID,
  7. SPL_NOOP_PROGRAM_ID,
  8. } from "@metaplex-foundation/mpl-bubblegum";
  9. import { decode, mapProof } from "./utils";
  10. import { getAsset, getAssetProof } from "./readApi";
  11. describe("cnft-burn", () => {
  12. // Configure the client to use the local cluster.
  13. anchor.setProvider(anchor.AnchorProvider.env());
  14. const program = anchor.workspace.CnftBurn as Program<CnftBurn>;
  15. const provider = anchor.AnchorProvider.env();
  16. const payerWallet = provider.wallet as anchor.Wallet;
  17. // this should be your tree address
  18. const tree = new anchor.web3.PublicKey(
  19. "23A8kctVQi9uQxYqzSZ3dhKiL2hSRGfmFYJd2Qfcyupp"
  20. );
  21. const MPL_BUBBLEGUM_PROGRAM_ID_KEY = new anchor.web3.PublicKey(
  22. MPL_BUBBLEGUM_PROGRAM_ID
  23. );
  24. const [treeAuthority, _bump2] = anchor.web3.PublicKey.findProgramAddressSync(
  25. [tree.toBuffer()],
  26. MPL_BUBBLEGUM_PROGRAM_ID_KEY
  27. );
  28. console.log("Tree Authority", treeAuthority.toString());
  29. console.log(
  30. "Computed tree authority",
  31. "2zhktLCwGLFg6bqGxgdN5BEKT7PVsQ81XyfQ33gKVtxU"
  32. );
  33. // this is the assetId of the cNft you want to burn
  34. const assetId = "CkWeh2TW91VtfrDy4pGBKwDJwNXwzZFQWNiHbsgHzXyY";
  35. it("Burn cNft!", async () => {
  36. const asset = await getAsset(assetId);
  37. const proof = await getAssetProof(assetId);
  38. const proofPathAsAccounts = mapProof(proof);
  39. const root = decode(proof.root);
  40. const dataHash = decode(asset.compression.data_hash);
  41. const creatorHash = decode(asset.compression.creator_hash);
  42. const nonce = new anchor.BN(asset.compression.leaf_id);
  43. const index = asset.compression.leaf_id;
  44. const tx = await program.methods
  45. .burnCnft(root, dataHash, creatorHash, nonce, index)
  46. .accounts({
  47. merkleTree: tree,
  48. leafOwner: payerWallet.publicKey,
  49. treeAuthority: treeAuthority,
  50. bubblegumProgram: MPL_BUBBLEGUM_PROGRAM_ID,
  51. compressionProgram: SPL_ACCOUNT_COMPRESSION_PROGRAM_ID,
  52. logWrapper: SPL_NOOP_PROGRAM_ID,
  53. systemProgram: anchor.web3.SystemProgram.programId,
  54. })
  55. .remainingAccounts(proofPathAsAccounts)
  56. .rpc({
  57. skipPreflight: true,
  58. });
  59. console.log("Your transaction signature", tx);
  60. // here is a sample transaction signature on devnet
  61. // https://explorer.solana.com/tx/2MpeHi64pbWNY7BKBuhAp4yND5HdfQqNqkd8pu6F6meoSNUYRvxQgV5TC4w8BM8hUihB8G8TwBAaPRqS7pnN8Nu1?cluster=devnet
  62. });
  63. });