forked from SkyzohKey/node-nano-rpc
-
-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathexamples.js
39 lines (31 loc) · 950 Bytes
/
examples.js
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
const NanoClient = require("./lib");
// with your own node
const client = new NanoClient({
url: 'http://localhost:7076'
});
// with https://mynano.ninja/api
/*
const client = new NanoClient({
apiKey: 'yourapikey'
});
*/
async function queryDemo() {
try {
// query the account balance
var account = await client.account_balance('nano_1ninja7rh37ehfp9utkor5ixmxyg8kme8fnzc4zty145ibch8kf5jwpnzr3r');
// query the current block count
var count = await client.block_count();
// custom RPC command (e.g. block_info)
var block_info = await client._send('block_info', {
"json_block": true,
"hash": "87434F8041869A01C8F6F263B87972D7BA443A72E0A97D7A3FD0CCC2358FD6F9"
});
} catch (error) {
console.error("\nError: " + error.message);
return
}
console.log("Account balance:", account);
console.log("Block count:", count);
console.log("Block info:", block_info.block_account);
}
queryDemo();