@human-protocol/sdk 1.1.13 → 1.1.15

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/src/kvstore.ts CHANGED
@@ -18,6 +18,75 @@ import {
18
18
  } from './error';
19
19
  import { NetworkData } from './types';
20
20
 
21
+ /**
22
+ * ## Introduction
23
+ *
24
+ * This client enables to perform actions on KVStore contract and obtain information from both the contracts and subgraph.
25
+ *
26
+ * Internally, the SDK will use one network or another according to the network ID of the `signerOrProvider`.
27
+ * To use this client, it is recommended to initialize it using the static `build` method.
28
+ *
29
+ * ```ts
30
+ * static async build(signerOrProvider: Signer | Provider);
31
+ * ```
32
+ *
33
+ * A `Signer` or a `Provider` should be passed depending on the use case of this module:
34
+ *
35
+ * - **Signer**: when the user wants to use this model in order to send transactions caling the contract functions.
36
+ * - **Provider**: when the user wants to use this model in order to get information from the contracts or subgraph.
37
+ *
38
+ * ## Installation
39
+ *
40
+ * ### npm
41
+ * ```bash
42
+ * npm install @human-protocol/sdk
43
+ * ```
44
+ *
45
+ * ### yarn
46
+ * ```bash
47
+ * yarn install @human-protocol/sdk
48
+ * ```
49
+ *
50
+ * ## Code example
51
+ *
52
+ * ### Signer
53
+ *
54
+ * **Using private key(backend)**
55
+ *
56
+ * ```ts
57
+ * import { KVStoreClient } from '@human-protocol/sdk';
58
+ * import { Wallet, providers } from 'ethers';
59
+ *
60
+ * const rpcUrl = 'YOUR_RPC_URL';
61
+ * const privateKey = 'YOUR_PRIVATE_KEY'
62
+ *
63
+ * const provider = new providers.JsonRpcProvider(rpcUrl);
64
+ * const signer = new Wallet(privateKey, provider);
65
+ * const kvstoreClient = await KVStoreClient.build(signer);
66
+ * ```
67
+ *
68
+ * **Using Wagmi(frontend)**
69
+ *
70
+ * ```ts
71
+ * import { useSigner, useChainId } from 'wagmi';
72
+ * import { KVStoreClient } from '@human-protocol/sdk';
73
+ *
74
+ * const { data: signer } = useSigner();
75
+ * const kvstoreClient = await KVStoreClient.build(signer);
76
+ * ```
77
+ *
78
+ * ### Provider
79
+ *
80
+ * ```ts
81
+ * import { KVStoreClient } from '@human-protocol/sdk';
82
+ * import { providers } from 'ethers';
83
+ *
84
+ * const rpcUrl = 'YOUR_RPC_URL';
85
+ *
86
+ * const provider = new providers.JsonRpcProvider(rpcUrl);
87
+ * const kvstoreClient = await KVStoreClient.build(signer);
88
+ * ```
89
+ */
21
90
  export class KVStoreClient {
22
91
  private contract: KVStore;
23
92
  private signerOrProvider: Signer | Provider;
@@ -67,12 +136,30 @@ export class KVStoreClient {
67
136
  }
68
137
 
69
138
  /**
70
- * Sets a key-value pair in the contract
139
+ * This function sets a key-value pair associated with the address that submits the transaction.
71
140
  *
72
- * @param {string} key - The key of the key-value pair to set
73
- * @param {string} value - The value of the key-value pair to set
74
- * @returns {Promise<void>}
75
- * @throws {Error} - An error object if an error occurred
141
+ * @param {string} key Key of the key-value pair
142
+ * @param {string} value Value of the key-value pair
143
+ * @returns Returns void if successful. Throws error if any.
144
+ *
145
+ *
146
+ * **Code example**
147
+ *
148
+ * > Need to have available stake.
149
+ *
150
+ * ```ts
151
+ * import { Wallet, providers } from 'ethers';
152
+ * import { KVStoreClient } from '@human-protocol/sdk';
153
+ *
154
+ * const rpcUrl = 'YOUR_RPC_URL';
155
+ * const privateKey = 'YOUR_PRIVATE_KEY'
156
+ *
157
+ * const provider = new providers.JsonRpcProvider(rpcUrl);
158
+ * const signer = new Wallet(privateKey, provider);
159
+ * const kvstoreClient = await KVStoreClient.build(signer);
160
+ *
161
+ * await kvstoreClient.set('Role', 'RecordingOracle');
162
+ * ```
76
163
  */
77
164
  @requiresSigner
78
165
  public async set(key: string, value: string): Promise<void> {
@@ -86,12 +173,32 @@ export class KVStoreClient {
86
173
  }
87
174
 
88
175
  /**
89
- * Sets multiple key-value pairs in the contract
176
+ * This function sets key-value pairs in bulk associated with the address that submits the transaction.
177
+ *
178
+ * @param {string[]} keys Array of keys (keys and value must have the same order)
179
+ * @param {string[]} values Array of values
180
+ * @returns Returns void if successful. Throws error if any.
181
+ *
182
+ *
183
+ * **Code example**
184
+ *
185
+ * > Need to have available stake.
90
186
  *
91
- * @param {string[]} keys - An array of keys to set
92
- * @param {string[]} values - An array of values to set
93
- * @returns {Promise<void>}
94
- * @throws {Error} - An error object if an error occurred
187
+ * ```ts
188
+ * import { Wallet, providers } from 'ethers';
189
+ * import { KVStoreClient } from '@human-protocol/sdk';
190
+ *
191
+ * const rpcUrl = 'YOUR_RPC_URL';
192
+ * const privateKey = 'YOUR_PRIVATE_KEY'
193
+ *
194
+ * const provider = new providers.JsonRpcProvider(rpcUrl);
195
+ * const signer = new Wallet(privateKey, provider);
196
+ * const kvstoreClient = await KVStoreClient.build(signer);
197
+ *
198
+ * const keys = ['Role', 'Webhook_url'];
199
+ * const values = ['RecordingOracle', 'http://localhost'];
200
+ * await kvstoreClient.set(keys, values);
201
+ * ```
95
202
  */
96
203
  @requiresSigner
97
204
  public async setBulk(keys: string[], values: string[]): Promise<void> {
@@ -108,12 +215,28 @@ export class KVStoreClient {
108
215
  }
109
216
 
110
217
  /**
111
- * Gets the value of a key-value pair in the contract
218
+ * This function returns the value for a specified key and address.
219
+ *
220
+ * @param {string} address Address from which to get the key value.
221
+ * @param {string} key Key to obtain the value.
222
+ * @returns {string} Value of the key.
223
+ *
224
+ *
225
+ * **Code example**
226
+ *
227
+ * > Need to have available stake.
228
+ *
229
+ * ```ts
230
+ * import { providers } from 'ethers';
231
+ * import { KVStoreClient } from '@human-protocol/sdk';
232
+ *
233
+ * const rpcUrl = 'YOUR_RPC_URL';
234
+ *
235
+ * const provider = new providers.JsonRpcProvider(rpcUrl);
236
+ * const kvstoreClient = await KVStoreClient.build(provider);
112
237
  *
113
- * @param {string} address - The Ethereum address associated with the key-value pair
114
- * @param {string} key - The key of the key-value pair to get
115
- * @returns {Promise<string>} - The value of the key-value pair if it exists
116
- * @throws {Error} - An error object if an error occurred
238
+ * const value = await kvstoreClient.get('0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266', 'Role');
239
+ * ```
117
240
  */
118
241
  public async get(address: string, key: string): Promise<string> {
119
242
  if (key === '') throw ErrorKVStoreEmptyKey;
package/src/staking.ts CHANGED
@@ -33,6 +33,75 @@ import { GET_REWARD_ADDED_EVENTS_QUERY } from './graphql/queries/reward';
33
33
  import { RewardAddedEventData } from './graphql';
34
34
  import { GET_LEADER_QUERY, GET_LEADERS_QUERY } from './graphql/queries/staking';
35
35
 
36
+ /**
37
+ * ## Introduction
38
+ *
39
+ * This client enables to perform actions on staking contracts and obtain staking information from both the contracts and subgraph.
40
+ *
41
+ * Internally, the SDK will use one network or another according to the network ID of the `signerOrProvider`.
42
+ * To use this client, it is recommended to initialize it using the static `build` method.
43
+ *
44
+ * ```ts
45
+ * static async build(signerOrProvider: Signer | Provider);
46
+ * ```
47
+ *
48
+ * A `Signer` or a `Provider` should be passed depending on the use case of this module:
49
+ *
50
+ * - **Signer**: when the user wants to use this model in order to send transactions caling the contract functions.
51
+ * - **Provider**: when the user wants to use this model in order to get information from the contracts or subgraph.
52
+ *
53
+ * ## Installation
54
+ *
55
+ * ### npm
56
+ * ```bash
57
+ * npm install @human-protocol/sdk
58
+ * ```
59
+ *
60
+ * ### yarn
61
+ * ```bash
62
+ * yarn install @human-protocol/sdk
63
+ * ```
64
+ *
65
+ * ## Code example
66
+ *
67
+ * ### Signer
68
+ *
69
+ * **Using private key(backend)**
70
+ *
71
+ * ```ts
72
+ * import { StakingClient } from '@human-protocol/sdk';
73
+ * import { Wallet, providers } from 'ethers';
74
+ *
75
+ * const rpcUrl = 'YOUR_RPC_URL';
76
+ * const privateKey = 'YOUR_PRIVATE_KEY'
77
+ *
78
+ * const provider = new providers.JsonRpcProvider(rpcUrl);
79
+ * const signer = new Wallet(privateKey, provider);
80
+ * const stakingClient = await StakingClient.build(signer);
81
+ * ```
82
+ *
83
+ * **Using Wagmi(frontend)**
84
+ *
85
+ * ```ts
86
+ * import { useSigner, useChainId } from 'wagmi';
87
+ * import { StakingClient } from '@human-protocol/sdk';
88
+ *
89
+ * const { data: signer } = useSigner();
90
+ * const stakingClient = await StakingClient.build(signer);
91
+ * ```
92
+ *
93
+ * ### Provider
94
+ *
95
+ * ```ts
96
+ * import { StakingClient } from '@human-protocol/sdk';
97
+ * import { providers } from 'ethers';
98
+ *
99
+ * const rpcUrl = 'YOUR_RPC_URL';
100
+ *
101
+ * const provider = new providers.JsonRpcProvider(rpcUrl);
102
+ * const stakingClient = await StakingClient.build(provider);
103
+ * ```
104
+ */
36
105
  export class StakingClient {
37
106
  public signerOrProvider: Signer | Provider;
38
107
  public network: NetworkData;
@@ -97,12 +166,28 @@ export class StakingClient {
97
166
  }
98
167
 
99
168
  /**
100
- * **Approves the staking contract to transfer a specified amount of tokens when the user stakes.
101
- * **It increases the allowance for the staking contract.*
169
+ * This function approves the staking contract to transfer a specified amount of tokens when the user stakes. It increases the allowance for the staking contract.
102
170
  *
103
- * @param {BigNumber} amount - Amount of tokens to approve for stake
104
- * @returns {Promise<void>}
105
- * @throws {Error} - An error object if an error occurred, void otherwise
171
+ * @param {BigNumber} amount Amount in WEI of tokens to approve for stake.
172
+ * @returns Returns void if successful. Throws error if any.
173
+ *
174
+ *
175
+ * **Code example**
176
+ *
177
+ * ```ts
178
+ * import { ethers, Wallet, providers } from 'ethers';
179
+ * import { StakingClient } from '@human-protocol/sdk';
180
+ *
181
+ * const rpcUrl = 'YOUR_RPC_URL';
182
+ * const privateKey = 'YOUR_PRIVATE_KEY'
183
+ *
184
+ * const provider = new providers.JsonRpcProvider(rpcUrl);
185
+ * const signer = new Wallet(privateKey, provider);
186
+ * const stakingClient = await StakingClient.build(signer);
187
+ *
188
+ * const amount = ethers.utils.parseUnits(5, 'ether'); //convert from ETH to WEI
189
+ * await stakingClient.approveStake(amount);
190
+ * ```
106
191
  */
107
192
  @requiresSigner
108
193
  public async approveStake(amount: BigNumber): Promise<void> {
@@ -123,11 +208,31 @@ export class StakingClient {
123
208
  }
124
209
 
125
210
  /**
126
- * **Stakes a specified amount of tokens on a specific network.*
211
+ * This function stakes a specified amount of tokens on a specific network.
212
+ *
213
+ * > `approveStake` must be called before
214
+ *
215
+ * @param {BigNumber} amount Amount in WEI of tokens to stake.
216
+ * @returns Returns void if successful. Throws error if any.
217
+ *
218
+ *
219
+ * **Code example**
127
220
  *
128
- * @param {BigNumber} amount - Amount of tokens to stake
129
- * @returns {Promise<void>}
130
- * @throws {Error} - An error object if an error occurred, void otherwise
221
+ * ```ts
222
+ * import { ethers, Wallet, providers } from 'ethers';
223
+ * import { StakingClient } from '@human-protocol/sdk';
224
+ *
225
+ * const rpcUrl = 'YOUR_RPC_URL';
226
+ * const privateKey = 'YOUR_PRIVATE_KEY'
227
+ *
228
+ * const provider = new providers.JsonRpcProvider(rpcUrl);
229
+ * const signer = new Wallet(privateKey, provider);
230
+ * const stakingClient = await StakingClient.build(signer);
231
+ *
232
+ * const amount = ethers.utils.parseUnits(5, 'ether'); //convert from ETH to WEI
233
+ * await stakingClient.approveStake(amount); // if it was already approved before, this is not necessary
234
+ * await stakingClient.approveStake(amount);
235
+ * ```
131
236
  */
132
237
  @requiresSigner
133
238
  public async stake(amount: BigNumber): Promise<void> {
@@ -148,12 +253,30 @@ export class StakingClient {
148
253
  }
149
254
 
150
255
  /**
151
- * **Unstakes tokens from staking contract.
152
- * **The unstaked tokens stay locked for a period of time.*
256
+ * This function unstakes tokens from staking contract. The unstaked tokens stay locked for a period of time.
257
+ *
258
+ * > Must have tokens available to unstake
259
+ *
260
+ * @param {BigNumber} amount Amount in WEI of tokens to unstake.
261
+ * @returns Returns void if successful. Throws error if any.
262
+ *
263
+ *
264
+ * **Code example**
265
+ *
266
+ * ```ts
267
+ * import { ethers, Wallet, providers } from 'ethers';
268
+ * import { StakingClient } from '@human-protocol/sdk';
269
+ *
270
+ * const rpcUrl = 'YOUR_RPC_URL';
271
+ * const privateKey = 'YOUR_PRIVATE_KEY'
272
+ *
273
+ * const provider = new providers.JsonRpcProvider(rpcUrl);
274
+ * const signer = new Wallet(privateKey, provider);
275
+ * const stakingClient = await StakingClient.build(signer);
153
276
  *
154
- * @param {BigNumber} amount - Amount of tokens to unstake
155
- * @returns {Promise<void>}
156
- * @throws {Error} - An error object if an error occurred, void otherwise
277
+ * const amount = ethers.utils.parseUnits(5, 'ether'); //convert from ETH to WEI
278
+ * await stakingClient.unstake(amount);
279
+ * ```
157
280
  */
158
281
  @requiresSigner
159
282
  public async unstake(amount: BigNumber): Promise<void> {
@@ -174,10 +297,28 @@ export class StakingClient {
174
297
  }
175
298
 
176
299
  /**
177
- * **Withdraws unstaked and non locked tokens form staking contract to the user wallet.*
300
+ * This function withdraws unstaked and non locked tokens form staking contract to the user wallet.
178
301
  *
179
- * @returns {Promise<void>}
180
- * @throws {Error} - An error object if an error occurred, void otherwise
302
+ * > Must have tokens available to withdraw
303
+ *
304
+ * @returns Returns void if successful. Throws error if any.
305
+ *
306
+ *
307
+ * **Code example**
308
+ *
309
+ * ```ts
310
+ * import { Wallet, providers } from 'ethers';
311
+ * import { StakingClient } from '@human-protocol/sdk';
312
+ *
313
+ * const rpcUrl = 'YOUR_RPC_URL';
314
+ * const privateKey = 'YOUR_PRIVATE_KEY'
315
+ *
316
+ * const provider = new providers.JsonRpcProvider(rpcUrl);
317
+ * const signer = new Wallet(privateKey, provider);
318
+ * const stakingClient = await StakingClient.build(signer);
319
+ *
320
+ * await stakingClient.withdraw();
321
+ * ```
181
322
  */
182
323
  @requiresSigner
183
324
  public async withdraw(): Promise<void> {
@@ -190,15 +331,31 @@ export class StakingClient {
190
331
  }
191
332
 
192
333
  /**
193
- * **Slash the allocated amount by an staker in an escrow and transfers those tokens to the reward pool.
194
- * **This allows the slasher to claim them later.*
195
- *
196
- * @param {string} slasher - Wallet address from who requested the slash
197
- * @param {string} staker - Wallet address from who is going to be slashed
198
- * @param {string} escrowAddress - Address of the escrow which allocation will be slashed
199
- * @param {BigNumber} amount - Amount of tokens to slash
200
- * @returns {Promise<void>}
201
- * @throws {Error} - An error object if an error occurred, void otherwise
334
+ * This function reduces the allocated amount by an staker in an escrow and transfers those tokens to the reward pool. This allows the slasher to claim them later.
335
+ *
336
+ * @param {string} slasher Wallet address from who requested the slash
337
+ * @param {string} staker Wallet address from who is going to be slashed
338
+ * @param {string} escrowAddress Address of the escrow which allocation will be slashed
339
+ * @param {BigNumber} amount Amount in WEI of tokens to unstake.
340
+ * @returns Returns void if successful. Throws error if any.
341
+ *
342
+ *
343
+ * **Code example**
344
+ *
345
+ * ```ts
346
+ * import { ethers, Wallet, providers } from 'ethers';
347
+ * import { StakingClient } from '@human-protocol/sdk';
348
+ *
349
+ * const rpcUrl = 'YOUR_RPC_URL';
350
+ * const privateKey = 'YOUR_PRIVATE_KEY'
351
+ *
352
+ * const provider = new providers.JsonRpcProvider(rpcUrl);
353
+ * const signer = new Wallet(privateKey, provider);
354
+ * const stakingClient = await StakingClient.build(signer);
355
+ *
356
+ * const amount = ethers.utils.parseUnits(5, 'ether'); //convert from ETH to WEI
357
+ * await stakingClient.slash('0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266', '0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266', '0x62dD51230A30401C455c8398d06F85e4EaB6309f', amount);
358
+ * ```
202
359
  */
203
360
  @requiresSigner
204
361
  public async slash(
@@ -241,12 +398,31 @@ export class StakingClient {
241
398
  }
242
399
 
243
400
  /**
244
- * **Allocates a portion of the staked tokens to a specific escrow.*
401
+ * This function allocates a portion of the staked tokens to a specific escrow.
402
+ *
403
+ * > Must have tokens staked
404
+ *
405
+ * @param {string} escrowAddress Address of the escrow contract to allocate in.
406
+ * @param {BigNumber} amount Amount in WEI of tokens to allocate.
407
+ * @returns Returns void if successful. Throws error if any.
408
+ *
409
+ *
410
+ * **Code example**
411
+ *
412
+ * ```ts
413
+ * import { ethers, Wallet, providers } from 'ethers';
414
+ * import { StakingClient } from '@human-protocol/sdk';
415
+ *
416
+ * const rpcUrl = 'YOUR_RPC_URL';
417
+ * const privateKey = 'YOUR_PRIVATE_KEY'
245
418
  *
246
- * @param {string} escrowAddress - Address of the escrow contract
247
- * @param {BigNumber} amount - Amount of tokens to allocate
248
- * @returns {Promise<void>}
249
- * @throws {Error} - An error object if an error occurred, void otherwise
419
+ * const provider = new providers.JsonRpcProvider(rpcUrl);
420
+ * const signer = new Wallet(privateKey, provider);
421
+ * const stakingClient = await StakingClient.build(signer);
422
+ *
423
+ * const amount = ethers.utils.parseUnits(5, 'ether'); //convert from ETH to WEI
424
+ * await stakingClient.allocate('0x62dD51230A30401C455c8398d06F85e4EaB6309f', amount);
425
+ * ```
250
426
  */
251
427
  @requiresSigner
252
428
  public async allocate(
@@ -278,11 +454,30 @@ export class StakingClient {
278
454
  }
279
455
 
280
456
  /**
281
- * **Drops the allocation from a specific escrow.*
457
+ * This function drops the allocation from a specific escrow.
458
+ *
459
+ * > The escrow must have allocation
460
+ * > The escrow must be cancelled or completed.
461
+ *
462
+ * @param {string} escrowAddress Address of the escrow contract to close allocation from.
463
+ * @returns Returns void if successful. Throws error if any.
464
+ *
465
+ *
466
+ * **Code example**
282
467
  *
283
- * @param {string} escrowAddress - Address of the escrow contract.
284
- * @returns {Promise<void>}
285
- * @throws {Error} - An error object if an error occurred, void otherwise
468
+ * ```ts
469
+ * import { Wallet, providers } from 'ethers';
470
+ * import { StakingClient } from '@human-protocol/sdk';
471
+ *
472
+ * const rpcUrl = 'YOUR_RPC_URL';
473
+ * const privateKey = 'YOUR_PRIVATE_KEY'
474
+ *
475
+ * const provider = new providers.JsonRpcProvider(rpcUrl);
476
+ * const signer = new Wallet(privateKey, provider);
477
+ * const stakingClient = await StakingClient.build(signer);
478
+ *
479
+ * await stakingClient.closeAllocation('0x62dD51230A30401C455c8398d06F85e4EaB6309f');
480
+ * ```
286
481
  */
287
482
  @requiresSigner
288
483
  public async closeAllocation(escrowAddress: string): Promise<void> {
@@ -303,11 +498,29 @@ export class StakingClient {
303
498
  }
304
499
 
305
500
  /**
306
- * **Pays out rewards to the slashers for the specified escrow address.*
501
+ * This function drops the allocation from a specific escrow.
502
+ *
503
+ * > The escrow must have rewards added
504
+ *
505
+ * @param {string} escrowAddress Escrow address from which rewards are distributed.
506
+ * @returns Returns void if successful. Throws error if any.
307
507
  *
308
- * @param {string} escrowAddress - Escrow address from which rewards are distributed.
309
- * @returns {Promise<void>}
310
- * @throws {Error} - An error object if an error occurred, void otherwise
508
+ *
509
+ * **Code example**
510
+ *
511
+ * ```ts
512
+ * import { Wallet, providers } from 'ethers';
513
+ * import { StakingClient } from '@human-protocol/sdk';
514
+ *
515
+ * const rpcUrl = 'YOUR_RPC_URL';
516
+ * const privateKey = 'YOUR_PRIVATE_KEY'
517
+ *
518
+ * const provider = new providers.JsonRpcProvider(rpcUrl);
519
+ * const signer = new Wallet(privateKey, provider);
520
+ * const stakingClient = await StakingClient.build(signer);
521
+ *
522
+ * await stakingClient.distributeRewards('0x62dD51230A30401C455c8398d06F85e4EaB6309f');
523
+ * ```
311
524
  */
312
525
  @requiresSigner
313
526
  public async distributeRewards(escrowAddress: string): Promise<void> {
@@ -333,11 +546,25 @@ export class StakingClient {
333
546
  }
334
547
 
335
548
  /**
336
- * **Returns the leader details for a given address**
549
+ * This function returns all the leader details of the protocol.
550
+ *
551
+ * @param {ILeadersFilter} filter Filter for the leaders.
552
+ * @returns {ILeader[]} Returns an array with all the leader details.
553
+ *
554
+ *
555
+ * **Code example**
556
+ *
557
+ * ```ts
558
+ * import { StakingClient } from '@human-protocol/sdk';
559
+ * import { providers } from 'ethers';
560
+ *
561
+ * const rpcUrl = 'YOUR_RPC_URL';
337
562
  *
338
- * @param {string} address - Leader address
339
- * @returns {Promise<ILeader>} - Return leader details
340
- * @throws {Error} - An error object if an error occurred, result otherwise
563
+ * const provider = new providers.JsonRpcProvider(rpcUrl);
564
+ * const stakingClient = await StakingClient.build(provider);
565
+ *
566
+ * const leaders = await stakingClient.getLeaders();
567
+ * ```
341
568
  */
342
569
  public async getLeader(address: string): Promise<ILeader> {
343
570
  if (!ethers.utils.isAddress(address)) {
@@ -358,10 +585,25 @@ export class StakingClient {
358
585
  }
359
586
 
360
587
  /**
361
- * **Returns the leaders data **
588
+ * This function returns the leader data for the given address.
589
+ *
590
+ * @param {string} address Leader address.
591
+ * @returns {ILeader} Returns the leader details.
592
+ *
593
+ *
594
+ * **Code example**
595
+ *
596
+ * ```ts
597
+ * import { StakingClient } from '@human-protocol/sdk';
598
+ * import { providers } from 'ethers';
362
599
  *
363
- * @returns {Promise<ILeader[]>} - Return an array with leaders data
364
- * @throws {Error} - An error object if an error occurred, results otherwise
600
+ * const rpcUrl = 'YOUR_RPC_URL';
601
+ *
602
+ * const provider = new providers.JsonRpcProvider(rpcUrl);
603
+ * const stakingClient = await StakingClient.build(provider);
604
+ *
605
+ * const leader = await stakingClient.getLeader('0x62dD51230A30401C455c8398d06F85e4EaB6309f');
606
+ * ```
365
607
  */
366
608
  public async getLeaders(filter: ILeadersFilter = {}): Promise<ILeader[]> {
367
609
  try {
@@ -378,11 +620,25 @@ export class StakingClient {
378
620
  }
379
621
 
380
622
  /**
381
- * **Returns information about the allocation of the specified escrow.*
623
+ * This function returns information about the allocation of the specified escrow.
624
+ *
625
+ * @param {string} escrowAddress Escrow address from which we want to get allocation information.
626
+ * @returns {IAllocation} Returns allocation info if exists.
627
+ *
628
+ *
629
+ * **Code example**
382
630
  *
383
- * @param {string} escrowAddress - The escrow address for the received allocation data
384
- * @returns {Promise<IAllocation>} - Returns allocation info if exists
385
- * @throws {Error} - An error object if an error occurred, result otherwise
631
+ * ```ts
632
+ * import { StakingClient } from '@human-protocol/sdk';
633
+ * import { providers } from 'ethers';
634
+ *
635
+ * const rpcUrl = 'YOUR_RPC_URL';
636
+ *
637
+ * const provider = new providers.JsonRpcProvider(rpcUrl);
638
+ * const stakingClient = await StakingClient.build(provider);
639
+ *
640
+ * const allocationInfo = await stakingClient.getAllocation('0x62dD51230A30401C455c8398d06F85e4EaB6309f');
641
+ * ```
386
642
  */
387
643
  public async getAllocation(escrowAddress: string): Promise<IAllocation> {
388
644
  if (!ethers.utils.isAddress(escrowAddress)) {
@@ -402,11 +658,25 @@ export class StakingClient {
402
658
  }
403
659
 
404
660
  /**
405
- * **Returns information about the rewards for a given escrow address.*
661
+ * This function returns information about the rewards for a given slasher address.
662
+ *
663
+ * @param {string} slasherAddress Slasher address.
664
+ * @returns {IReward[]} Returns an array of Reward objects that contain the rewards earned by the user through slashing other users.
665
+ *
666
+ *
667
+ * **Code example**
668
+ *
669
+ * ```ts
670
+ * import { StakingClient } from '@human-protocol/sdk';
671
+ * import { providers } from 'ethers';
672
+ *
673
+ * const rpcUrl = 'YOUR_RPC_URL';
674
+ *
675
+ * const provider = new providers.JsonRpcProvider(rpcUrl);
676
+ * const stakingClient = await StakingClient.build(provider);
406
677
  *
407
- * @param {string} slasherAddress - Address of the slasher
408
- * @returns {Promise<IReward[]>} - Returns rewards info if exists
409
- * @throws {Error} - An error object if an error occurred, results otherwise
678
+ * const rewards = await stakingClient.getRewards('0x62dD51230A30401C455c8398d06F85e4EaB6309f');
679
+ * ```
410
680
  */
411
681
  public async getRewards(slasherAddress: string): Promise<IReward[]> {
412
682
  if (!ethers.utils.isAddress(slasherAddress)) {