-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinit-bubblegum-tree-v2.mjs
More file actions
83 lines (68 loc) · 2.72 KB
/
init-bubblegum-tree-v2.mjs
File metadata and controls
83 lines (68 loc) · 2.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
import { Connection, Keypair, PublicKey, SystemProgram, Transaction } from '@solana/web3.js';
import { createCreateTreeInstruction, PROGRAM_ID as BUBBLEGUM_PROGRAM_ID } from '@metaplex-foundation/mpl-bubblegum';
import { SPL_NOOP_PROGRAM_ID, SPL_ACCOUNT_COMPRESSION_PROGRAM_ID } from '@solana/spl-account-compression';
import fs from 'fs';
const connection = new Connection('https://api.devnet.solana.com');
// Load keypairs
const payerKeypair = Keypair.fromSecretKey(
new Uint8Array(JSON.parse(fs.readFileSync('/Users/krewdev/.config/solana/id.json')))
);
const merkleTreeKeypair = Keypair.fromSecretKey(
new Uint8Array(JSON.parse(fs.readFileSync('merkle-tree-keypair.json')))
);
// Tree configuration
const maxDepth = 14; // 2^14 = 16,384 leaves
const maxBufferSize = 64; // Concurrent transactions
// Find the tree authority PDA
const [treeAuthority] = PublicKey.findProgramAddressSync(
[merkleTreeKeypair.publicKey.toBuffer()],
BUBBLEGUM_PROGRAM_ID
);
console.log('Initializing Bubblegum tree...');
console.log('Tree:', merkleTreeKeypair.publicKey.toString());
console.log('Tree Authority:', treeAuthority.toString());
console.log('Payer:', payerKeypair.publicKey.toString());
try {
// Create the instruction to initialize the tree
const createTreeIx = createCreateTreeInstruction(
{
merkleTree: merkleTreeKeypair.publicKey,
treeAuthority: treeAuthority,
treeCreator: payerKeypair.publicKey,
payer: payerKeypair.publicKey,
logWrapper: SPL_NOOP_PROGRAM_ID,
compressionProgram: SPL_ACCOUNT_COMPRESSION_PROGRAM_ID,
systemProgram: SystemProgram.programId,
},
{
maxDepth,
maxBufferSize,
}
);
const transaction = new Transaction().add(createTreeIx);
// Sign with both payer and tree keypair
const signature = await connection.sendTransaction(transaction, [payerKeypair, merkleTreeKeypair]);
console.log('Tree initialization transaction:', signature);
// Wait for confirmation
const confirmation = await connection.confirmTransaction(signature, 'confirmed');
if (confirmation.value.err) {
console.error('Transaction failed:', confirmation.value.err);
} else {
console.log('✅ Bubblegum tree initialized successfully!');
// Save the configuration
const config = {
merkleTree: merkleTreeKeypair.publicKey.toString(),
treeAuthority: treeAuthority.toString(),
maxDepth,
maxBufferSize,
signature
};
fs.writeFileSync('bubblegum-tree-config.json', JSON.stringify(config, null, 2));
console.log('Configuration saved to bubblegum-tree-config.json');
}
} catch (error) {
console.error('Error initializing tree:', error);
if (error.logs) {
console.error('Transaction logs:', error.logs);
}
}