forked from thisisjoshford/tutorials
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
52 lines (41 loc) · 1.7 KB
/
main.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
40
41
42
43
44
45
46
47
48
49
50
51
52
// Load environment variables
require("dotenv").config();
// Load Near SDK components
const near = require("near-api-js");
// Setup default client options
const options = {
networkId: process.env.NEAR_NETWORK,
nodeUrl: process.env.NEAR_NODE_URL,
walletUrl: `https://wallet.${process.env.NEAR_NETWORK}.near.org`,
helperUrl: `https://helper.${process.env.NEAR_NETWORK}.near.org`,
explorerUrl: `https://explorer.${process.env.NEAR_NETWORK}.near.org`,
accountId: process.env.NEAR_ACCOUNT,
keyStore: {}
}
async function main() {
// Configure the client with options and our local key store
const client = await near.connect(options);
const provider = client.connection.provider;
// Get network status
const status = await provider.status();
console.log("network status:", status);
// Get the latest block
let block = await provider.block({ finality: "final" });
console.log("current block:", block);
// Get the block by number
block = await provider.block({ blockId: status.sync_info.latest_block_height });
console.log("block by height:", block);
// Get current network validators
const validators = await provider.validators(block.header.height);
console.log("network validators:", validators);
// Get account details
const account = await client.account(options.accountId);
console.log("account state:", await account.state());
// Get current gas price
gasPrice = await provider.sendJsonRpc("gas_price", [null]);
console.log("gas price:", gasPrice);
// Get current gas price from the block header
const anotherBlock = await provider.sendJsonRpc("block", { finality: "final" });
console.log("gas price from header:", anotherBlock.header.gas_price);
}
main()