-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproper-tree-init.mjs
More file actions
131 lines (105 loc) Β· 4.68 KB
/
proper-tree-init.mjs
File metadata and controls
131 lines (105 loc) Β· 4.68 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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
import { Connection, Keypair, PublicKey, Transaction, SystemProgram } from '@solana/web3.js';
import { createCreateTreeInstruction } from '@metaplex-foundation/mpl-bubblegum';
import fs from 'fs';
const connection = new Connection('https://api.devnet.solana.com', 'confirmed');
async function initializeTreeCorrectly() {
try {
console.log('π³ Initializing tree with official Metaplex SDK...');
// Load payer
const payerKeypair = Keypair.fromSecretKey(
new Uint8Array(JSON.parse(fs.readFileSync('/Users/krewdev/.config/solana/id.json')))
);
// Load existing tree keypair
const merkleTreeKeypair = Keypair.fromSecretKey(
new Uint8Array(JSON.parse(fs.readFileSync('merkle-tree-keypair.json')))
);
console.log('Tree Account:', merkleTreeKeypair.publicKey.toString());
console.log('Payer:', payerKeypair.publicKey.toString());
// Program IDs
const BUBBLEGUM_PROGRAM_ID = new PublicKey('BGUMAp9Gq7iTEuizy4pqaxsTyUCBK68MDfK752saRPUY');
const COMPRESSION_PROGRAM_ID = new PublicKey('cmtDvXumGCrqC1Age74AVPhSRVXJMd8PJS91L8KbNCK');
const LOG_WRAPPER_ID = new PublicKey('noopb9bkMVfRPU8AsbpTUg8AQkHtKwMYZiFUjNRtMmV');
// Tree configuration
const maxDepth = 14; // 2^14 = 16,384 leaves
const maxBufferSize = 64; // Concurrent transactions
// Calculate tree authority PDA
const [treeAuthority] = PublicKey.findProgramAddressSync(
[merkleTreeKeypair.publicKey.toBuffer()],
BUBBLEGUM_PROGRAM_ID
);
console.log('Tree Authority:', treeAuthority.toString());
// Create instruction with correct parameters
const createTreeIx = createCreateTreeInstruction(
{
merkleTree: merkleTreeKeypair.publicKey,
treeAuthority,
treeCreator: payerKeypair.publicKey,
payer: payerKeypair.publicKey,
logWrapper: LOG_WRAPPER_ID,
compressionProgram: COMPRESSION_PROGRAM_ID,
systemProgram: SystemProgram.programId,
},
{
maxDepth,
maxBufferSize,
public: true, // This was missing!
}
);
const transaction = new Transaction().add(createTreeIx);
console.log('Sending initialization transaction...');
const signature = await connection.sendTransaction(
transaction,
[payerKeypair, merkleTreeKeypair],
{ skipPreflight: false, preflightCommitment: 'confirmed' }
);
console.log('Transaction signature:', signature);
// Wait for confirmation
const confirmation = await connection.confirmTransaction(signature, 'confirmed');
if (confirmation.value.err) {
console.error('Transaction failed:', confirmation.value.err);
throw new Error(`Transaction failed: ${JSON.stringify(confirmation.value.err)}`);
}
console.log('β
Tree initialization transaction confirmed!');
// Wait and verify
console.log('Waiting 5 seconds for account updates...');
await new Promise(resolve => setTimeout(resolve, 5000));
const updatedAccountInfo = await connection.getAccountInfo(merkleTreeKeypair.publicKey);
const stillZero = updatedAccountInfo?.data.every(byte => byte === 0) || false;
if (stillZero) {
console.log('β οΈ Account still contains zeros after initialization');
} else {
console.log('π SUCCESS! Account now contains proper Bubblegum tree data!');
console.log('First 64 bytes:', Array.from(updatedAccountInfo?.data.slice(0, 64) || []).map(b => b.toString(16).padStart(2, '0')).join(' '));
}
// Check tree authority
const treeAuthorityInfo = await connection.getAccountInfo(treeAuthority);
if (treeAuthorityInfo) {
console.log('β
Tree Authority PDA created successfully');
console.log('Authority data size:', treeAuthorityInfo.data.length);
} else {
console.log('β Tree Authority PDA not found');
}
// Save updated configuration
const config = {
merkleTree: merkleTreeKeypair.publicKey.toString(),
treeAuthority: treeAuthority.toString(),
maxDepth,
maxBufferSize,
signature,
status: 'initialized',
timestamp: new Date().toISOString(),
transactionUrl: `https://solscan.io/tx/${signature}?cluster=devnet`
};
fs.writeFileSync('final-merkle-tree.json', JSON.stringify(config, null, 2));
console.log('β
Configuration saved to final-merkle-tree.json');
console.log('π View transaction:', config.transactionUrl);
console.log('\nπ TREE SUCCESSFULLY INITIALIZED!');
console.log('Your compressed NFT minting should now work!');
} catch (error) {
console.error('β Failed to initialize tree:', error);
if (error.logs) {
console.error('Transaction logs:', error.logs);
}
}
}
initializeTreeCorrectly();