setup.ts 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. import type { CreateMetadataAccountArgsV3 } from '@metaplex-foundation/mpl-token-metadata';
  2. import type { ValidDepthSizePair } from '@solana/spl-account-compression';
  3. import { Connection, Keypair } from '@solana/web3.js';
  4. import { createCollection, createTree } from './utils/compression';
  5. import { loadOrGenerateKeypair, savePublicKeyToFile } from './utils/helpers';
  6. async function setup() {
  7. const rpc = 'https://api.devnet.solana.com';
  8. const connection = new Connection(rpc, 'confirmed');
  9. // Collection auth and treeCreator
  10. const payer = loadOrGenerateKeypair('payer');
  11. // Airdrop
  12. await connection.requestAirdrop(payer.publicKey, 1 * 10 ** 9);
  13. console.log('Payer address:', payer.publicKey.toBase58());
  14. const treeKeypair = Keypair.generate();
  15. const maxDepthSizePair: ValidDepthSizePair = {
  16. maxDepth: 14,
  17. maxBufferSize: 64,
  18. };
  19. const canopyDepth = maxDepthSizePair.maxDepth - 5;
  20. const tree = await createTree(connection, payer, treeKeypair, maxDepthSizePair, canopyDepth);
  21. // locally save the addresses for demo
  22. savePublicKeyToFile('treeAddress', tree.treeAddress);
  23. const collectionMetadataV3: CreateMetadataAccountArgsV3 = {
  24. data: {
  25. name: 'Super Sweet NFT Collection',
  26. symbol: 'SSNC',
  27. // specific json metadata for the collection
  28. uri: 'https://supersweetcollection.notarealurl/collection.json',
  29. sellerFeeBasisPoints: 100,
  30. creators: [
  31. {
  32. address: payer.publicKey,
  33. verified: false,
  34. share: 100,
  35. },
  36. ],
  37. collection: null,
  38. uses: null,
  39. },
  40. isMutable: false,
  41. collectionDetails: null,
  42. };
  43. // create a full token mint and initialize the collection (with the `payer` as the authority)
  44. const collection = await createCollection(connection, payer, collectionMetadataV3);
  45. // locally save the addresses for the demo
  46. savePublicKeyToFile('collectionMint', collection.mint);
  47. }
  48. // setup()