Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[163,191,238,222,165,10,196,219,229,157,128,66,219,37,37,137,230,137,252,234,163,154,232,213,75,96,189,118,2,192,220,227,168,226,27,159,122,121,34,241,0,179,208,143,53,28,173,200,205,132,163,204,167,203,73,5,177,44,177,96,24,90,78,249]
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[246,254,110,193,43,97,213,126,71,247,230,76,57,115,124,27,82,141,189,212,168,21,70,220,222,53,134,19,135,83,195,130,175,79,45,216,48,217,128,189,145,148,243,172,30,134,15,162,92,232,55,141,228,72,21,124,80,108,183,3,218,195,74,183]
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[198,123,251,189,215,99,58,111,17,19,25,26,121,152,53,110,133,101,9,49,17,19,255,94,177,194,181,46,118,100,141,129,6,196,130,166,155,106,83,52,123,142,240,222,51,94,141,240,236,134,47,251,115,163,210,99,94,236,228,125,144,213,0,104]
61 changes: 61 additions & 0 deletions compressed-nfts/createTree.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import { createCreateTreeInstruction, PROGRAM_ID as BUBBLEGUM_PROGRAM_ID } from "@metaplex-foundation/mpl-bubblegum";
import { loadWalletKey, sendVersionedTx } from "./utils";
import { Connection, Keypair, PublicKey, SystemProgram, Transaction, VersionedMessage } from "@solana/web3.js";
import { SPL_ACCOUNT_COMPRESSION_PROGRAM_ID, SPL_NOOP_PROGRAM_ID, ValidDepthSizePair, getConcurrentMerkleTreeAccountSize } from "@solana/spl-account-compression";
import { SYSTEM_PROGRAM_ID } from "@raydium-io/raydium-sdk";

async function createTree() {
// Load the wallet key for the user who will create the merkle tree
const keypair = loadWalletKey("CNFTvZm6BPd5ZH2Lbn3mMnSsUYWirqjvRWo9wbcbfAB2.json");

// Create a connection to the network
const connection = new Connection("https://api.devnet.solana.com");

// Load the wallet key for the merkle tree account
const merkleTree = loadWalletKey("TREyXNrxJSgrsWoYKU5xo8XYNCBNoZnSBdP5PkC1W2B.json");

// Find the tree authority public key and bump seed
const [treeAuthority, _bump] = PublicKey.findProgramAddressSync(
[merkleTree.publicKey.toBuffer()],
BUBBLEGUM_PROGRAM_ID,
);

// Define the depth and buffer size of the merkle tree
const depthSizePair: ValidDepthSizePair = {
maxDepth: 14,
maxBufferSize: 64,
};

// Calculate the required account space for the merkle tree
const space = getConcurrentMerkleTreeAccountSize(depthSizePair.maxDepth, depthSizePair.maxBufferSize);

// Create an account instruction to allocate space for the merkle tree
const createAccountIx = SystemProgram.createAccount({
newAccountPubkey: merkleTree.publicKey,
fromPubkey: keypair.publicKey,
space: space,
lamports: await connection.getMinimumBalanceForRentExemption(space),
programId: SPL_ACCOUNT_COMPRESSION_PROGRAM_ID,
});

// Create a merkle tree instruction
const createTreeIx = createCreateTreeInstruction({
merkleTree: merkleTree.publicKey,
treeAuthority: treeAuthority,
payer: keypair.publicKey,
treeCreator: keypair.publicKey,
compressionProgram: SPL_ACCOUNT_COMPRESSION_PROGRAM_ID,
logWrapper: SPL_NOOP_PROGRAM_ID,
systemProgram: SYSTEM_PROGRAM_ID,
}, {
maxDepth: depthSizePair.maxDepth,
maxBufferSize: depthSizePair.maxBufferSize,
public: false,
});

// Send the transaction with both instructions
const sx = await sendVersionedTx(connection, [createAccountIx, createTreeIx], keypair.publicKey, [keypair, merkleTree]);
console.log(sx);
}

createTree();
7 changes: 7 additions & 0 deletions compressed-nfts/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"dependencies": {
"@metaplex-foundation/mpl-bubblegum": "^0.6.2",
"@raydium-io/raydium-sdk": "^1.3.0-beta.17",
"@solana/spl-token": "^0.3.7"
}
}
24 changes: 24 additions & 0 deletions compressed-nfts/utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { Connection, Keypair, PublicKey, Signer, TransactionInstruction, TransactionMessage, VersionedTransaction } from "@solana/web3.js";

export function loadWalletKey(keypairFile:string): Keypair {
const fs = require ("fs")
return Keypair. fromSecretKey(
new Uint8Array(JSON.parse(fs.readFileSync(keypairFile).toString())),
);
}
export async function sendVersionedTx(
connection: Connection,
instructions: TransactionInstruction[],
payer: PublicKey,
signers: Signer[]){
let latestBlockhash = await connection.getLatestBlockhash()
const messageLegacy = new TransactionMessage({
payerKey: payer,
recentBlockhash: latestBlockhash.blockhash,
instructions,
}).compileToLegacyMessage();
const transation = new VersionedTransaction(messageLegacy)
transation.sign(signers);
const signature = await connection.sendTransaction(transation);
return signature;
}