-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtest-endpoint.mjs
More file actions
56 lines (47 loc) Β· 1.8 KB
/
test-endpoint.mjs
File metadata and controls
56 lines (47 loc) Β· 1.8 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
import { V1Client } from '@titanexchange/sdk-ts';
const WS_URL = 'wss://titan-solanam-2284.mainnet.rpcpool.com/806a2750-f53c-4263-b3fd-c4a0cbe54151/titan/api/v1/ws';
const JWT = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCIsImtpZCI6IjJkNmE5MmI1LTZiMDgtNDVlNC05NjNmLTZiYmM5YmVkNjczZSJ9.eyJpYXQiOjE3NjMzOTQxNTIsImV4cCI6MTc5NDkzMDE1MiwiYXVkIjoiYXBpLnRpdGFuLmFnIiwiaXNzIjoidGl0YW5fZGV2XzIiLCJzdWIiOiJkZXY6YWJoaW5hd19yYXRhbiJ9.Gj_Rso-b3QvZlXkJHDzHC1RlTN-M6NYriIfPx7T1wG4';
// Helper to serialize data with BigInt support
function stringify(data) {
return JSON.stringify(data, (key, value) => {
if (typeof value === 'bigint') {
return value.toString() + 'n';
}
if (value instanceof Uint8Array) {
return `<Uint8Array: ${value.length} bytes>`;
}
return value;
}, 2);
}
async function testConnection() {
console.log('π Testing WebSocket connection...');
console.log('π Endpoint:', WS_URL);
console.log('');
try {
// Add JWT to URL
const urlWithAuth = `${WS_URL}?auth=${encodeURIComponent(JWT)}`;
console.log('β³ Connecting...');
const client = await V1Client.connect(urlWithAuth);
console.log('β
Connected successfully!');
console.log('');
// Get server info
console.log('π Fetching server info...');
const info = await client.getInfo();
console.log('β
Server info received:');
console.log('');
console.log(stringify(info));
console.log('');
// Close connection
console.log('π Closing connection...');
await client.close();
console.log('β
Connection closed successfully');
console.log('');
console.log('π Test completed successfully!');
} catch (error) {
console.error('β Error:', error.message);
console.error('');
console.error('Full error:', error);
process.exit(1);
}
}
testConnection();