forked from Ac3B0x/libra-node-wrapper
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.js
executable file
·49 lines (42 loc) · 1.48 KB
/
test.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
const libra = require('..');
const client = new libra.Client('ac.testnet.libra.org:8000');
const test = async () => {
/** Get account state */
let params = {
address: Buffer.from('435fc8fc85510cf38a5b0cd6595cbb8fbb10aa7bb3fe9ad9820913ba867f79d4', 'hex'),
};
const accountState = await client.request('get_account_state', params);
console.log('Account state', accountState);
/** Get account transaction */
params = {
account: Buffer.from('435fc8fc85510cf38a5b0cd6595cbb8fbb10aa7bb3fe9ad9820913ba867f79d4', 'hex'),
sequence_number: 1,
fetch_events: true,
};
const transaction = await client.request('get_account_transaction_by_sequence_number', params);
console.log('Transaction', transaction);
/** Get events */
params = {
access_path: {
address: Buffer.from('435fc8fc85510cf38a5b0cd6595cbb8fbb10aa7bb3fe9ad9820913ba867f79d4', 'hex'),
},
start_event_seq_num: 2,
ascending: true,
limit: 10,
};
const events = await client.request('get_events_by_event_access_path', params);
console.log('Events', events);
/** Get transactions */
params = {
start_version: 1,
limit: 10,
fetch_events: true,
};
client.request('get_transactions', params).then(transactions => {
console.log('Transactions', transactions);
/** Deserialize raw txn bytes */
const rawTx = libra.utils.deserializeRawTxnBytes(transactions.txn_list_with_proof.transactions[0].raw_txn_bytes);
console.log('Raw transaction', rawTx);
});
};
test();