-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbasic-usage.ts
More file actions
69 lines (59 loc) · 2.33 KB
/
basic-usage.ts
File metadata and controls
69 lines (59 loc) · 2.33 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
/**
* Basic usage example
*/
import { KodeChainClient } from '../src';
async function main() {
// Create client
const client = new KodeChainClient({
nodeUrl: 'http://34.28.74.25:8084',
defaultConsensus: 'DPOS',
timeout: 30000,
});
try {
// Connect to node
console.log('Connecting to KodeChain node...');
await client.connect();
console.log('Connected');
// Get node info
const nodeInfo = await client.getNodeInfo();
console.log('\nNode Info:');
console.log('- Version:', nodeInfo.version);
console.log('- Chain ID:', nodeInfo.chainId);
console.log('- Node Type:', nodeInfo.nodeType);
console.log('- Peers:', nodeInfo.peers);
// Get health status
const health = await client.getHealth();
console.log('\nHealth Status:', health.status);
console.log('- API:', health.checks.api ? 'OK' : 'Failed');
console.log('- DPOS:', health.checks.dpos ? 'OK' : 'Failed');
console.log('- PBFT:', health.checks.pbft ? 'OK' : 'Failed');
console.log('- Database:', health.checks.database ? 'OK' : 'Failed');
// Get block heights
const dposHeight = await client.getBlockHeight('DPOS');
const pbftHeight = await client.getBlockHeight('PBFT');
console.log('\nBlock Heights:');
console.log('- DPOS:', dposHeight);
console.log('- PBFT:', pbftHeight);
// Get latest blocks
const dposBlock = await client.getLatestBlock('DPOS');
const pbftBlock = await client.getLatestBlock('PBFT');
console.log('\nLatest Blocks:');
console.log('- DPOS:', dposBlock.number, '-', dposBlock.hash);
console.log('- PBFT:', pbftBlock.number, '-', pbftBlock.hash);
// Get balance example
const exampleAddress = '0x1234567890123456789012345678901234567890';
try {
const balance = await client.getBalance(exampleAddress);
console.log(`\nBalance for ${exampleAddress}:`, balance);
} catch (error) {
console.log('\nBalance query failed (expected if address does not exist)');
}
// Disconnect
client.disconnect();
console.log('\nDisconnected');
} catch (error) {
console.error('Error:', error);
process.exit(1);
}
}
main();