forked from Conflux-Chain/js-conflux-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path0_create_conflux.js
96 lines (88 loc) · 2.19 KB
/
0_create_conflux.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
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
/* eslint-disable */
const { Conflux } = require('../src'); // require('js-conflux-sdk');
// create conflux sdk instance and connect to remote node
const conflux = new Conflux({
// url: 'http://localhost:12537',
url: 'https://test.confluxrpc.com',
networkId: 1,
// logger: console, // use console to print log
});
function listConfluxPrototypes() {
console.log(Object.getOwnPropertyNames(conflux.constructor.prototype));
/*
[
'constructor',
'Contract',
'InternalContract',
'close',
'getClientVersion',
'getStatus',
'getGasPrice',
'getInterestRate',
'getAccumulateInterestRate',
'getAccount',
'getBalance',
'getStakingBalance',
'getNextNonce',
'getAdmin',
'getEpochNumber',
'getBlockByEpochNumber',
'getBlocksByEpochNumber',
'getBlockRewardInfo',
'getBestBlockHash',
'getBlockByHash',
'getBlockByHashWithPivotAssumption',
'getConfirmationRiskByHash',
'getTransactionByHash',
'getTransactionReceipt',
'sendRawTransaction',
'sendTransaction',
'getCode',
'getStorageAt',
'getStorageRoot',
'getSponsorInfo',
'getCollateralForStorage',
'call',
'estimateGasAndCollateral',
'getLogs',
'subscribe',
'subscribeEpochs',
'subscribeNewHeads',
'subscribeLogs',
'unsubscribe'
]
*/
}
async function getStatus() {
// call RPC and get connected node status
console.log(await conflux.getStatus());
/*
{
chainId: 1,
epochNumber: 779841,
blockNumber: 1455488,
pendingTxNumber: 2,
bestHash: '0x3e5816431723620a40876454f6cccbd8d62188dc07ce9ce2cb38563a22c26cdb'
}
*/
}
async function getStatusByProvider() {
// call RPC and get status by provider directly
console.log(await conflux.provider.call('cfx_getStatus'));
/*
{
bestHash: '0xbec9b9318a5473416b5bdf95d7f378c966ea0356aa98e2d96c8cad48aff32ebe',
blockNumber: '0x163aaa',
chainId: '0x1',
epochNumber: '0xbe939',
pendingTxNumber: '0x2'
}
*/
}
// ----------------------------------------------------------------------------
async function main() {
listConfluxPrototypes();
await getStatus();
await getStatusByProvider();
}
main().finally(() => conflux.close());