-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathdebug-script.js
More file actions
144 lines (124 loc) Β· 4.83 KB
/
Copy pathdebug-script.js
File metadata and controls
144 lines (124 loc) Β· 4.83 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
132
133
134
135
136
137
138
139
140
141
142
143
// debug-setup.js
// Basic script to help debug environment issues
const { Connection, Keypair, PublicKey, LAMPORTS_PER_SOL } = require('@solana/web3.js');
// Use the default export from bs58
const bs58 = require('bs58').default;
const fs = require('fs');
const { Buffer } = require('buffer');
require('dotenv').config({ path: '.env.local' });
// For debugging unhandled rejections
process.on('unhandledRejection', (reason, promise) => {
console.error('Unhandled Rejection at:', promise, 'reason:', reason);
});
async function debugSetup() {
try {
console.log('π Starting debug script...');
// Check environment variables
console.log('Checking environment variables...');
const rpcUrl = process.env.NEXT_PUBLIC_RPC_URL;
if (!rpcUrl) {
throw new Error('NEXT_PUBLIC_RPC_URL is not set in .env.local');
}
console.log(`β
RPC URL: ${rpcUrl}`);
// Test connection to Solana
console.log('Testing connection to Solana...');
const connection = new Connection(rpcUrl, 'confirmed');
const version = await connection.getVersion();
console.log(`β
Connected to Solana! Version: ${JSON.stringify(version)}`);
// Check admin keypair
console.log('Checking admin keypair...');
const adminPrivateKey = process.env.SOLANA_PRIVATE_KEY;
if (!adminPrivateKey) {
throw new Error('SOLANA_PRIVATE_KEY not found in environment');
}
// Test decoding the private key
let secretKey;
try {
if (adminPrivateKey.length > 88) {
console.log('Detected Base64 encoded key');
secretKey = Buffer.from(adminPrivateKey, 'base64');
} else {
console.log('Attempting to decode as Base58');
secretKey = bs58.decode(adminPrivateKey);
}
console.log(`Secret key length: ${secretKey.length} bytes`);
if (secretKey.length !== 64) {
throw new Error(`Invalid private key length: ${secretKey.length}. Expected 64 bytes.`);
}
const adminKeypair = Keypair.fromSecretKey(secretKey);
console.log(`β
Admin Public Key: ${adminKeypair.publicKey.toBase58()}`);
// Check balance
const balance = await connection.getBalance(adminKeypair.publicKey);
console.log(`β
Admin balance: ${balance / LAMPORTS_PER_SOL} SOL`);
} catch (error) {
console.error('β Error processing private key:', error);
throw error;
}
// Check token details
console.log('Checking token details file...');
try {
const tokenDetails = JSON.parse(fs.readFileSync('token-details.json', 'utf8'));
console.log('β
Token details loaded:');
console.log(` - Name: ${tokenDetails.name}`);
console.log(` - Symbol: ${tokenDetails.symbol}`);
console.log(` - Mint: ${tokenDetails.mintAddress}`);
console.log(` - Decimals: ${tokenDetails.decimals}`);
// Verify mint exists on chain
const mintPubkey = new PublicKey(tokenDetails.mintAddress);
const mintInfo = await connection.getAccountInfo(mintPubkey);
if (!mintInfo) {
console.warn('β οΈ Token mint account not found on chain!');
} else {
console.log('β
Token mint account exists on chain.');
}
} catch (error) {
console.error('β Error checking token details:', error);
throw error;
}
// Check required node modules
console.log('Checking required node modules...');
let modulesOk = true;
try {
require('@solana/web3.js');
console.log('β
@solana/web3.js is installed');
} catch (e) {
console.error('β @solana/web3.js is missing');
modulesOk = false;
}
try {
require('@solana/spl-token');
console.log('β
@solana/spl-token is installed');
} catch (e) {
console.error('β @solana/spl-token is missing');
modulesOk = false;
}
try {
require('@solana/buffer-layout');
console.log('β
@solana/buffer-layout is installed');
} catch (e) {
console.error('β @solana/buffer-layout is missing');
modulesOk = false;
}
try {
// Try to access TokenSwapProgram public key
const tokenSwapProgramId = new PublicKey('SwaPpA9LAaLfeLi3a68M4DjnLqgtticKg6CnyNwgAC8');
const programInfo = await connection.getAccountInfo(tokenSwapProgramId);
if (!programInfo) {
console.warn('β οΈ TokenSwap program not found on chain! Make sure you are on the right network.');
} else {
console.log('β
TokenSwap program exists on chain.');
}
} catch (error) {
console.error('β Error checking TokenSwap program:', error);
}
console.log('π― Debug completed successfully!');
} catch (error) {
console.error('β Debug failed with error:', error);
process.exit(1);
}
}
// Run the debug function
debugSetup().catch(err => {
console.error('β Final Error:', err);
process.exit(1);
});