@@ -11,7 +11,8 @@ This section illustrates the methodology for monitoring the production of a new
11
11
import {
12
12
HttpClient ,
13
13
Poll ,
14
- ThorestClient
14
+ ThorestClient ,
15
+ ThorClient
15
16
} from ' @vechainfoundation/vechain-sdk-network' ;
16
17
import { expect } from ' expect' ;
17
18
@@ -20,10 +21,11 @@ import { expect } from 'expect';
20
21
const _testnetUrl = ' https://testnet.vechain.org' ;
21
22
const testNetwork = new HttpClient (_testnetUrl );
22
23
const thorestClient = new ThorestClient (testNetwork );
24
+ const thorClient = new ThorClient (thorestClient );
23
25
24
26
// 2 - Get current block
25
27
26
- const currentBlock = await thorestClient .blocks .getBestBlock ();
28
+ const currentBlock = await thorClient .blocks .getBestBlock ();
27
29
28
30
console .log (' Current block:' , currentBlock );
29
31
@@ -32,7 +34,7 @@ console.log('Current block:', currentBlock);
32
34
// Wait until a new block is created with polling interval of 3 seconds
33
35
const newBlock = await Poll .SyncPoll (
34
36
// Get the latest block as polling target function
35
- async () => await thorestClient .blocks .getBlock (' best' ),
37
+ async () => await thorClient .blocks .getBlock (' best' ),
36
38
// Polling interval is 3 seconds
37
39
{ requestIntervalInMilliseconds: 3000 }
38
40
).waitUntil ((newBlockData ) => {
@@ -54,7 +56,8 @@ Here, we explore the approach to monitor balance changes subsequent to a transfe
54
56
import {
55
57
HttpClient ,
56
58
Poll ,
57
- ThorestClient
59
+ ThorestClient ,
60
+ ThorClient
58
61
} from ' @vechainfoundation/vechain-sdk-network' ;
59
62
import {
60
63
dataUtils ,
@@ -69,11 +72,12 @@ import { expect } from 'expect';
69
72
const _soloUrl = ' http://localhost:8669' ;
70
73
const soloNetwork = new HttpClient (_soloUrl );
71
74
const thorestSoloClient = new ThorestClient (soloNetwork );
75
+ const thorSoloClient = new ThorClient (thorestSoloClient );
72
76
73
77
// 2- Init transaction
74
78
75
79
// 2.1 - Get latest block
76
- const latestBlock = await thorestSoloClient .blocks .getBestBlock ();
80
+ const latestBlock = await thorSoloClient .blocks .getBestBlock ();
77
81
78
82
// 2.2 - Transaction sender and receiver
79
83
const sender = {
@@ -126,11 +130,11 @@ const raw = `0x${encoded.toString('hex')}`;
126
130
// 3 - Get the sender and receiver balance before the transaction
127
131
128
132
const senderBalanceBefore = (
129
- await thorestSoloClient .accounts .getAccount (sender .address )
133
+ await thorSoloClient .accounts .getAccount (sender .address )
130
134
).balance ;
131
135
132
136
const receiverBalanceBefore = (
133
- await thorestSoloClient .accounts .getAccount (receiver .address )
137
+ await thorSoloClient .accounts .getAccount (receiver .address )
134
138
).balance ;
135
139
136
140
console .log (' Sender balance before:' , senderBalanceBefore );
@@ -151,15 +155,15 @@ expect(dataUtils.isHexString(sentedTransaction.id)).toBe(true);
151
155
// New balance of sender (wait until the balance is updated)
152
156
const newBalanceSender = await Poll .SyncPoll (
153
157
async () =>
154
- (await thorestSoloClient .accounts .getAccount (sender .address )).balance
158
+ (await thorSoloClient .accounts .getAccount (sender .address )).balance
155
159
).waitUntil ((newBalance ) => {
156
160
return newBalance !== senderBalanceBefore ;
157
161
});
158
162
159
163
// New balance of receiver (wait until the balance is updated)
160
164
const newBalanceReceiver = await Poll .SyncPoll (
161
165
async () =>
162
- (await thorestSoloClient .accounts .getAccount (receiver .address )).balance
166
+ (await thorSoloClient .accounts .getAccount (receiver .address )).balance
163
167
).waitUntil ((newBalance ) => {
164
168
return newBalance !== receiverBalanceBefore ;
165
169
});
@@ -186,14 +190,16 @@ This example demonstrates the application of an asynchronous poll for tracking t
186
190
import {
187
191
HttpClient ,
188
192
Poll ,
189
- ThorestClient
193
+ ThorestClient ,
194
+ ThorClient
190
195
} from ' @vechainfoundation/vechain-sdk-network' ;
191
196
192
197
// 1 - Create client for testnet
193
198
194
199
const _testnetUrl = ' https://testnet.vechain.org' ;
195
200
const testNetwork = new HttpClient (_testnetUrl );
196
201
const thorestClient = new ThorestClient (testNetwork );
202
+ const thorClient = new ThorClient (thorestClient );
197
203
198
204
// 2 - Init accounts
199
205
@@ -206,7 +212,7 @@ const accounts = [
206
212
207
213
for (const account of accounts ) {
208
214
const monitoringPoll = Poll .createEventPoll (
209
- async () => await thorestClient .accounts .getAccount (account ),
215
+ async () => await thorClient .accounts .getAccount (account ),
210
216
1000
211
217
)
212
218
// Add listeners for start event
0 commit comments