koilib 5.7.0 → 7.0.0

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.
Files changed (45) hide show
  1. package/README.md +39 -40
  2. package/dist/koinos.js +1649 -83
  3. package/dist/koinos.min.js +1 -1
  4. package/lib/Contract.d.ts +12 -24
  5. package/lib/Contract.js +11 -23
  6. package/lib/Contract.js.map +1 -1
  7. package/lib/Provider.d.ts +257 -12
  8. package/lib/Provider.js +262 -9
  9. package/lib/Provider.js.map +1 -1
  10. package/lib/Signer.d.ts +75 -6
  11. package/lib/Signer.js +87 -6
  12. package/lib/Signer.js.map +1 -1
  13. package/lib/Transaction.d.ts +4 -3
  14. package/lib/Transaction.js +13 -10
  15. package/lib/Transaction.js.map +1 -1
  16. package/lib/browser/Contract.d.ts +12 -24
  17. package/lib/browser/Contract.js +11 -23
  18. package/lib/browser/Contract.js.map +1 -1
  19. package/lib/browser/Provider.d.ts +257 -12
  20. package/lib/browser/Provider.js +262 -9
  21. package/lib/browser/Provider.js.map +1 -1
  22. package/lib/browser/Signer.d.ts +75 -6
  23. package/lib/browser/Signer.js +87 -6
  24. package/lib/browser/Signer.js.map +1 -1
  25. package/lib/browser/Transaction.d.ts +4 -3
  26. package/lib/browser/Transaction.js +13 -10
  27. package/lib/browser/Transaction.js.map +1 -1
  28. package/lib/browser/interface.d.ts +33 -0
  29. package/lib/browser/utils.d.ts +39 -0
  30. package/lib/browser/utils.js +1276 -27
  31. package/lib/browser/utils.js.map +1 -1
  32. package/lib/interface.d.ts +33 -0
  33. package/lib/utils.d.ts +39 -0
  34. package/lib/utils.js +1276 -27
  35. package/lib/utils.js.map +1 -1
  36. package/package.json +1 -1
  37. package/src/Contract.ts +12 -24
  38. package/src/Provider.ts +271 -20
  39. package/src/Signer.ts +126 -7
  40. package/src/Transaction.ts +17 -16
  41. package/src/interface.ts +38 -0
  42. package/src/utils.ts +1283 -23
  43. package/lib/browser/jsonDescriptors/token-proto.json +0 -234
  44. package/lib/jsonDescriptors/token-proto.json +0 -234
  45. package/src/jsonDescriptors/token-proto.json +0 -234
@@ -1,4 +1,4 @@
1
- import { BlockJson, TransactionJson, CallContractOperationJson, TransactionReceipt, TransactionJsonWait, BlockTopology } from "./interface";
1
+ import { BlockJson, TransactionJson, CallContractOperationJson, TransactionReceipt, TransactionJsonWait, BlockTopology, GetBlockOptions } from "./interface";
2
2
  import { Serializer } from "./Serializer";
3
3
  /**
4
4
  * Class to connect with the RPC node
@@ -40,8 +40,8 @@ export declare class Provider {
40
40
  * @example
41
41
  * ```ts
42
42
  * const provider = new Provider([
43
- * "http://45.56.104.152:8080",
44
- * "http://159.203.119.0:8080"
43
+ * "https://api.koinos.io",
44
+ * "https://api.koinosblocks.com"
45
45
  * ]);
46
46
  * ```
47
47
  */
@@ -51,6 +51,151 @@ export declare class Provider {
51
51
  * @param method - jsonrpc method
52
52
  * @param params - jsonrpc params
53
53
  * @returns Result of jsonrpc response
54
+ *
55
+ * To know the full list of possible calls check the services
56
+ * listed in the [rpc folder of koinos-proto](https://github.com/koinos/koinos-proto/tree/master/koinos/rpc)
57
+ * and the corresponding proto files.
58
+ *
59
+ * @example
60
+ * Let's take "account_history" as an example. Go to [account_history_rpc.proto](https://github.com/koinos/koinos-proto/blob/master/koinos/rpc/account_history/account_history_rpc.proto).
61
+ * The `account_history_request` message has 1 single method: `get_account_history`.
62
+ *
63
+ * Now search the message `get_account_history_request`. This message is telling us
64
+ * the expected fields in the body of the call:
65
+ *
66
+ * ```ts
67
+ * message get_account_history_request {
68
+ * bytes address = 1 [(btype) = ADDRESS];
69
+ * optional uint64 seq_num = 2 [jstype = JS_STRING];
70
+ * uint64 limit = 3 [jstype = JS_STRING];
71
+ * bool ascending = 4;
72
+ * bool irreversible = 5;
73
+ * }
74
+ * ```
75
+ *
76
+ * And search the message `get_account_history_response` to see the format of the response:
77
+ * ```ts
78
+ * message get_account_history_response {
79
+ * repeated account_history_entry values = 1;
80
+ * }
81
+ * ```
82
+ *
83
+ * With this information we can now call the RPC node. It should be done in this way:
84
+ * ```ts
85
+ * const provider = new Provider(["https://api.koinos.io"]);
86
+ * const result = await provider.call(
87
+ * "account_history.get_account_history",
88
+ * {
89
+ * address: "1z629tURV9KAK6Q5yqFDozwSHeWshxXQe",
90
+ * limit: 2,
91
+ * ascending: true,
92
+ * irreversible: true,
93
+ * }
94
+ * );
95
+ * console.log(result);
96
+ *
97
+ * // {
98
+ * // "values": [
99
+ * // {
100
+ * // "trx": {
101
+ * // "transaction": {
102
+ * // "id": "0x12205b566701d6afcf1f5e45b5e9f5443def75728c219f7c1e897ed0ce1ef491223c",
103
+ * // "header": {
104
+ * // "chain_id": "EiBZK_GGVP0H_fXVAM3j6EAuz3-B-l3ejxRSewi7qIBfSA==",
105
+ * // "rc_limit": "961224079493",
106
+ * // "nonce": "KAE=",
107
+ * // "operation_merkle_root": "EiA32K_GrZ2VsvWSrM4QZhyEmvm8ID1P6aE4vP00RnY9hg==",
108
+ * // "payer": "1HyzBsd7nmyUp8dyCJqJZoQRUnzifVzP18"
109
+ * // },
110
+ * // "operations": [
111
+ * // {
112
+ * // "call_contract": {
113
+ * // "contract_id": "15DJN4a8SgrbGhhGksSBASiSYjGnMU8dGL",
114
+ * // "entry_point": 670398154,
115
+ * // "args": "ChkAukkLSXtxbRNRTBtDrdAwDI7I6Ot9GxFHEhkACsvmdCIUj89udQ1R5iLPLXzqJoHdliWrGIDC1y8="
116
+ * // }
117
+ * // }
118
+ * // ],
119
+ * // "signatures": [
120
+ * // "ICBdTcH6jzhDpl9ZB0ZqNcvSy8wiOokHFtkQ66Lc04K1LhXd77tqaQdMhJOAfYotg5npVmfSgyO9CwgLJmtMIjg="
121
+ * // ]
122
+ * // },
123
+ * // "receipt": {
124
+ * // "id": "0x12205b566701d6afcf1f5e45b5e9f5443def75728c219f7c1e897ed0ce1ef491223c",
125
+ * // "payer": "1HyzBsd7nmyUp8dyCJqJZoQRUnzifVzP18",
126
+ * // "max_payer_rc": "961224079493",
127
+ * // "rc_limit": "961224079493",
128
+ * // "rc_used": "3009833",
129
+ * // "disk_storage_used": "112",
130
+ * // "network_bandwidth_used": "313",
131
+ * // "compute_bandwidth_used": "561439",
132
+ * // "events": [
133
+ * // {
134
+ * // "sequence": 2,
135
+ * // "source": "15DJN4a8SgrbGhhGksSBASiSYjGnMU8dGL",
136
+ * // "name": "koinos.contracts.token.transfer_event",
137
+ * // "data": "ChkAukkLSXtxbRNRTBtDrdAwDI7I6Ot9GxFHEhkACsvmdCIUj89udQ1R5iLPLXzqJoHdliWrGIDC1y8=",
138
+ * // "impacted": [
139
+ * // "1z629tURV9KAK6Q5yqFDozwSHeWshxXQe",
140
+ * // "1HyzBsd7nmyUp8dyCJqJZoQRUnzifVzP18"
141
+ * // ]
142
+ * // }
143
+ * // ]
144
+ * // }
145
+ * // }
146
+ * // },
147
+ * // {
148
+ * // "seq_num": "1",
149
+ * // "trx": {
150
+ * // "transaction": {
151
+ * // "id": "0x1220a08183a5237e57a08e1ae539017c4253ddfbc23f9b7b6f5e263669aacd3fed47",
152
+ * // "header": {
153
+ * // "chain_id": "EiBZK_GGVP0H_fXVAM3j6EAuz3-B-l3ejxRSewi7qIBfSA==",
154
+ * // "rc_limit": "100000000",
155
+ * // "nonce": "KAE=",
156
+ * // "operation_merkle_root": "EiBAmutXQlPyAGctNBNhKEUUEUtwj2KQeNrdFBqpN9RWDg==",
157
+ * // "payer": "1z629tURV9KAK6Q5yqFDozwSHeWshxXQe"
158
+ * // },
159
+ * // "operations": [
160
+ * // {
161
+ * // "call_contract": {
162
+ * // "contract_id": "15DJN4a8SgrbGhhGksSBASiSYjGnMU8dGL",
163
+ * // "entry_point": 670398154,
164
+ * // "args": "ChkACsvmdCIUj89udQ1R5iLPLXzqJoHdliWrEhkAukkLSXtxbRNRTBtDrdAwDI7I6Ot9GxFHGJBO"
165
+ * // }
166
+ * // }
167
+ * // ],
168
+ * // "signatures": [
169
+ * // "IF5FBloKjEfnqlGJRL_aPy4L36On-Q8XXzpAQagK_X-xZ6DgioBhZOhKEnhKyhaoROAgGwRuy6BsdRqya8fCHU8="
170
+ * // ]
171
+ * // },
172
+ * // "receipt": {
173
+ * // "id": "0x1220a08183a5237e57a08e1ae539017c4253ddfbc23f9b7b6f5e263669aacd3fed47",
174
+ * // "payer": "1z629tURV9KAK6Q5yqFDozwSHeWshxXQe",
175
+ * // "max_payer_rc": "100000000",
176
+ * // "rc_limit": "100000000",
177
+ * // "rc_used": "2657385",
178
+ * // "disk_storage_used": "35",
179
+ * // "network_bandwidth_used": "309",
180
+ * // "compute_bandwidth_used": "566375",
181
+ * // "events": [
182
+ * // {
183
+ * // "sequence": 2,
184
+ * // "source": "15DJN4a8SgrbGhhGksSBASiSYjGnMU8dGL",
185
+ * // "name": "koinos.contracts.token.transfer_event",
186
+ * // "data": "ChkACsvmdCIUj89udQ1R5iLPLXzqJoHdliWrEhkAukkLSXtxbRNRTBtDrdAwDI7I6Ot9GxFHGJBO",
187
+ * // "impacted": [
188
+ * // "1HyzBsd7nmyUp8dyCJqJZoQRUnzifVzP18",
189
+ * // "1z629tURV9KAK6Q5yqFDozwSHeWshxXQe"
190
+ * // ]
191
+ * // }
192
+ * // ]
193
+ * // }
194
+ * // }
195
+ * // }
196
+ * // ]
197
+ * // }
198
+ * ```
54
199
  */
55
200
  call<T = unknown>(method: string, params: unknown): Promise<T>;
56
201
  /**
@@ -83,10 +228,7 @@ export declare class Provider {
83
228
  containing_blocks: string[];
84
229
  }[];
85
230
  }>;
86
- getBlocksById(blockIds: string[], opts?: {
87
- returnBlock: boolean;
88
- returnReceipt: boolean;
89
- }): Promise<{
231
+ getBlocksById(blockIds: string[], opts?: GetBlockOptions): Promise<{
90
232
  block_items: {
91
233
  block_id: string;
92
234
  block_height: string;
@@ -95,6 +237,24 @@ export declare class Provider {
95
237
  }>;
96
238
  /**
97
239
  * Function to get info from the head block in the blockchain
240
+ *
241
+ * @example
242
+ * ```ts
243
+ * const provider = new Provider("https://api.koinos.io");
244
+ * const headInfo = await provider.getHeadInfo();
245
+ * console.log(headInfo);
246
+ *
247
+ * // {
248
+ * // head_topology: {
249
+ * // id: '0x12209f7c9b4d695eefd6f87465d490654e495fe25a3d7d2e1eb80658acdc49bad962',
250
+ * // height: '14957951',
251
+ * // previous: '0x1220bc3b94e3a2adc3ca09d61a4418df1f4acfa78a69686f592877c194ea50642cd2'
252
+ * // },
253
+ * // last_irreversible_block: '14957891',
254
+ * // head_state_merkle_root: 'EiCriqXooNUXBG23EUKLz2qq3h9ZAC8w1W7w185YQ9MzIA==',
255
+ * // head_block_time: '1713874497290'
256
+ * // }
257
+ * ```
98
258
  */
99
259
  getHeadInfo(): Promise<{
100
260
  head_block_time: string;
@@ -114,10 +274,7 @@ export declare class Provider {
114
274
  * This ID must be from a greater block height. By default it
115
275
  * gets the ID from the block head.
116
276
  */
117
- getBlocks(height: number, numBlocks?: number, idRef?: string, opts?: {
118
- returnBlock: boolean;
119
- returnReceipt: boolean;
120
- }): Promise<{
277
+ getBlocks(height: number, numBlocks?: number, idRef?: string, opts?: GetBlockOptions): Promise<{
121
278
  block_id: string;
122
279
  block_height: string;
123
280
  block: BlockJson;
@@ -127,8 +284,74 @@ export declare class Provider {
127
284
  }[]>;
128
285
  /**
129
286
  * Function to get a block by its height
287
+ *
288
+ * @example
289
+ * ```ts
290
+ * const provider = new Provider("https://api.koinos.io");
291
+ * const block = await provider.getBlock(14951433);
292
+ * console.log(block);
293
+ *
294
+ * // {
295
+ * // block_id: '0x1220d5e848eb0f69c590c24cbea4391f89a1055f540bc265c60f6b13c4cc0055ec36',
296
+ * // block_height: '14951433',
297
+ * // block: {
298
+ * // id: '0x1220d5e848eb0f69c590c24cbea4391f89a1055f540bc265c60f6b13c4cc0055ec36',
299
+ * // header: {
300
+ * // previous: '0x1220a3c4cbc57ccee4d02b4a1849a9e504122ee93b904deff711d926def2ea2cc878',
301
+ * // height: '14951433',
302
+ * // timestamp: '1713854518430',
303
+ * // previous_state_merkle_root: 'EiCPcnYosMvEBYeCcJrdIJJG0mp4TJ796UGxa0NY6EvzbQ==',
304
+ * // transaction_merkle_root: 'EiBGPKwttckB7c_BafwnHHmHTBa9S1vKBKauj_yLVNb0tg==',
305
+ * // signer: '1EPZaqve43k9Jq5mNeT2ydCjUiytTTU4U',
306
+ * // approved_proposals: [Array]
307
+ * // },
308
+ * // transactions: [ [Object] ],
309
+ * // signature: 'ClEDnHKX1F-pQVbFhmz2qnrwGfP-RbEfTdRFUrvmhmqMeoejtmm2Q0yIPbD5kN5xpIEb
310
+ * // 8vVwsIJ3lTrgFz2E8w0Paxkgv1E_gMaYNq5UUqtHnl0SIhIgAAbuPHmfMKh9R0Yi5y1D
311
+ * // TpjjdN0DYKaIUseXzLiLg_QaQR9jRinZf0g_qo2_4wOx9gDBunIij0r5CycHrNMsuT_V
312
+ * // _UvrJOYuwj7aUCA-qnF2tCBQoNQZ3ww7WvKHrMdChxxy'
313
+ * // },
314
+ * // receipt: {
315
+ * // id: '0x1220d5e848eb0f69c590c24cbea4391f89a1055f540bc265c60f6b13c4cc0055ec36',
316
+ * // height: '14951433',
317
+ * // disk_storage_used: '35',
318
+ * // network_bandwidth_used: '760',
319
+ * // compute_bandwidth_used: '5253506',
320
+ * // events: [ [Object], [Object] ],
321
+ * // transaction_receipts: [ [Object] ],
322
+ * // disk_storage_charged: '35',
323
+ * // network_bandwidth_charged: '760',
324
+ * // compute_bandwidth_charged: '5180427',
325
+ * // state_delta_entries: [
326
+ * // [Object], [Object],
327
+ * // [Object], [Object],
328
+ * // [Object], [Object],
329
+ * // [Object], [Object],
330
+ * // [Object], [Object]
331
+ * // ]
332
+ * // }
333
+ * // }
334
+ * ```
335
+ *
336
+ * Use the options to get less information. This helps to reduce
337
+ * the bandwidth of the call.
338
+ *
339
+ * @example
340
+ * ```ts
341
+ * const provider = new Provider("https://api.koinos.io");
342
+ * const block = await provider.getBlock(14951433, {
343
+ * returnReceipt: false,
344
+ * returnBlock: false
345
+ * });
346
+ * console.log(block);
347
+ *
348
+ * // {
349
+ * // block_id: '0x1220d5e848eb0f69c590c24cbea4391f89a1055f540bc265c60f6b13c4cc0055ec36',
350
+ * // block_height: '14951433'
351
+ * // }
352
+ * ```
130
353
  */
131
- getBlock(height: number): Promise<{
354
+ getBlock(height: number, opts?: GetBlockOptions): Promise<{
132
355
  block_id: string;
133
356
  block_height: string;
134
357
  block: BlockJson;
@@ -224,6 +447,28 @@ export declare class Provider {
224
447
  caller: string;
225
448
  caller_privilege: number;
226
449
  }): Promise<T>;
450
+ /**
451
+ * Function to get the contract metadata of a specific contract.
452
+ * @param contractId contract ID
453
+ *
454
+ * @example
455
+ * ```ts
456
+ * const provider = new Provider("https://api.koinos.io");
457
+ * const result = await provider.invokeGetContractMetadata("15DJN4a8SgrbGhhGksSBASiSYjGnMU8dGL");
458
+ * console.log(result);
459
+ *
460
+ * // {
461
+ * // value: {
462
+ * // hash: '0x1220c57e3573189868970a3a1662a667c366b15015d9b7900ffed415c5e944036e88',
463
+ * // system: true,
464
+ * // authorizes_call_contract: true,
465
+ * // authorizes_transaction_application: true,
466
+ * // authorizes_upload_contract: true
467
+ * // }
468
+ * // }
469
+ *
470
+ * ```
471
+ */
227
472
  invokeGetContractMetadata(contractId: string): Promise<Record<string, unknown>>;
228
473
  }
229
474
  export default Provider;
@@ -21,8 +21,8 @@ class Provider {
21
21
  * @example
22
22
  * ```ts
23
23
  * const provider = new Provider([
24
- * "http://45.56.104.152:8080",
25
- * "http://159.203.119.0:8080"
24
+ * "https://api.koinos.io",
25
+ * "https://api.koinosblocks.com"
26
26
  * ]);
27
27
  * ```
28
28
  */
@@ -39,6 +39,151 @@ class Provider {
39
39
  * @param method - jsonrpc method
40
40
  * @param params - jsonrpc params
41
41
  * @returns Result of jsonrpc response
42
+ *
43
+ * To know the full list of possible calls check the services
44
+ * listed in the [rpc folder of koinos-proto](https://github.com/koinos/koinos-proto/tree/master/koinos/rpc)
45
+ * and the corresponding proto files.
46
+ *
47
+ * @example
48
+ * Let's take "account_history" as an example. Go to [account_history_rpc.proto](https://github.com/koinos/koinos-proto/blob/master/koinos/rpc/account_history/account_history_rpc.proto).
49
+ * The `account_history_request` message has 1 single method: `get_account_history`.
50
+ *
51
+ * Now search the message `get_account_history_request`. This message is telling us
52
+ * the expected fields in the body of the call:
53
+ *
54
+ * ```ts
55
+ * message get_account_history_request {
56
+ * bytes address = 1 [(btype) = ADDRESS];
57
+ * optional uint64 seq_num = 2 [jstype = JS_STRING];
58
+ * uint64 limit = 3 [jstype = JS_STRING];
59
+ * bool ascending = 4;
60
+ * bool irreversible = 5;
61
+ * }
62
+ * ```
63
+ *
64
+ * And search the message `get_account_history_response` to see the format of the response:
65
+ * ```ts
66
+ * message get_account_history_response {
67
+ * repeated account_history_entry values = 1;
68
+ * }
69
+ * ```
70
+ *
71
+ * With this information we can now call the RPC node. It should be done in this way:
72
+ * ```ts
73
+ * const provider = new Provider(["https://api.koinos.io"]);
74
+ * const result = await provider.call(
75
+ * "account_history.get_account_history",
76
+ * {
77
+ * address: "1z629tURV9KAK6Q5yqFDozwSHeWshxXQe",
78
+ * limit: 2,
79
+ * ascending: true,
80
+ * irreversible: true,
81
+ * }
82
+ * );
83
+ * console.log(result);
84
+ *
85
+ * // {
86
+ * // "values": [
87
+ * // {
88
+ * // "trx": {
89
+ * // "transaction": {
90
+ * // "id": "0x12205b566701d6afcf1f5e45b5e9f5443def75728c219f7c1e897ed0ce1ef491223c",
91
+ * // "header": {
92
+ * // "chain_id": "EiBZK_GGVP0H_fXVAM3j6EAuz3-B-l3ejxRSewi7qIBfSA==",
93
+ * // "rc_limit": "961224079493",
94
+ * // "nonce": "KAE=",
95
+ * // "operation_merkle_root": "EiA32K_GrZ2VsvWSrM4QZhyEmvm8ID1P6aE4vP00RnY9hg==",
96
+ * // "payer": "1HyzBsd7nmyUp8dyCJqJZoQRUnzifVzP18"
97
+ * // },
98
+ * // "operations": [
99
+ * // {
100
+ * // "call_contract": {
101
+ * // "contract_id": "15DJN4a8SgrbGhhGksSBASiSYjGnMU8dGL",
102
+ * // "entry_point": 670398154,
103
+ * // "args": "ChkAukkLSXtxbRNRTBtDrdAwDI7I6Ot9GxFHEhkACsvmdCIUj89udQ1R5iLPLXzqJoHdliWrGIDC1y8="
104
+ * // }
105
+ * // }
106
+ * // ],
107
+ * // "signatures": [
108
+ * // "ICBdTcH6jzhDpl9ZB0ZqNcvSy8wiOokHFtkQ66Lc04K1LhXd77tqaQdMhJOAfYotg5npVmfSgyO9CwgLJmtMIjg="
109
+ * // ]
110
+ * // },
111
+ * // "receipt": {
112
+ * // "id": "0x12205b566701d6afcf1f5e45b5e9f5443def75728c219f7c1e897ed0ce1ef491223c",
113
+ * // "payer": "1HyzBsd7nmyUp8dyCJqJZoQRUnzifVzP18",
114
+ * // "max_payer_rc": "961224079493",
115
+ * // "rc_limit": "961224079493",
116
+ * // "rc_used": "3009833",
117
+ * // "disk_storage_used": "112",
118
+ * // "network_bandwidth_used": "313",
119
+ * // "compute_bandwidth_used": "561439",
120
+ * // "events": [
121
+ * // {
122
+ * // "sequence": 2,
123
+ * // "source": "15DJN4a8SgrbGhhGksSBASiSYjGnMU8dGL",
124
+ * // "name": "koinos.contracts.token.transfer_event",
125
+ * // "data": "ChkAukkLSXtxbRNRTBtDrdAwDI7I6Ot9GxFHEhkACsvmdCIUj89udQ1R5iLPLXzqJoHdliWrGIDC1y8=",
126
+ * // "impacted": [
127
+ * // "1z629tURV9KAK6Q5yqFDozwSHeWshxXQe",
128
+ * // "1HyzBsd7nmyUp8dyCJqJZoQRUnzifVzP18"
129
+ * // ]
130
+ * // }
131
+ * // ]
132
+ * // }
133
+ * // }
134
+ * // },
135
+ * // {
136
+ * // "seq_num": "1",
137
+ * // "trx": {
138
+ * // "transaction": {
139
+ * // "id": "0x1220a08183a5237e57a08e1ae539017c4253ddfbc23f9b7b6f5e263669aacd3fed47",
140
+ * // "header": {
141
+ * // "chain_id": "EiBZK_GGVP0H_fXVAM3j6EAuz3-B-l3ejxRSewi7qIBfSA==",
142
+ * // "rc_limit": "100000000",
143
+ * // "nonce": "KAE=",
144
+ * // "operation_merkle_root": "EiBAmutXQlPyAGctNBNhKEUUEUtwj2KQeNrdFBqpN9RWDg==",
145
+ * // "payer": "1z629tURV9KAK6Q5yqFDozwSHeWshxXQe"
146
+ * // },
147
+ * // "operations": [
148
+ * // {
149
+ * // "call_contract": {
150
+ * // "contract_id": "15DJN4a8SgrbGhhGksSBASiSYjGnMU8dGL",
151
+ * // "entry_point": 670398154,
152
+ * // "args": "ChkACsvmdCIUj89udQ1R5iLPLXzqJoHdliWrEhkAukkLSXtxbRNRTBtDrdAwDI7I6Ot9GxFHGJBO"
153
+ * // }
154
+ * // }
155
+ * // ],
156
+ * // "signatures": [
157
+ * // "IF5FBloKjEfnqlGJRL_aPy4L36On-Q8XXzpAQagK_X-xZ6DgioBhZOhKEnhKyhaoROAgGwRuy6BsdRqya8fCHU8="
158
+ * // ]
159
+ * // },
160
+ * // "receipt": {
161
+ * // "id": "0x1220a08183a5237e57a08e1ae539017c4253ddfbc23f9b7b6f5e263669aacd3fed47",
162
+ * // "payer": "1z629tURV9KAK6Q5yqFDozwSHeWshxXQe",
163
+ * // "max_payer_rc": "100000000",
164
+ * // "rc_limit": "100000000",
165
+ * // "rc_used": "2657385",
166
+ * // "disk_storage_used": "35",
167
+ * // "network_bandwidth_used": "309",
168
+ * // "compute_bandwidth_used": "566375",
169
+ * // "events": [
170
+ * // {
171
+ * // "sequence": 2,
172
+ * // "source": "15DJN4a8SgrbGhhGksSBASiSYjGnMU8dGL",
173
+ * // "name": "koinos.contracts.token.transfer_event",
174
+ * // "data": "ChkACsvmdCIUj89udQ1R5iLPLXzqJoHdliWrEhkAukkLSXtxbRNRTBtDrdAwDI7I6Ot9GxFHGJBO",
175
+ * // "impacted": [
176
+ * // "1HyzBsd7nmyUp8dyCJqJZoQRUnzifVzP18",
177
+ * // "1z629tURV9KAK6Q5yqFDozwSHeWshxXQe"
178
+ * // ]
179
+ * // }
180
+ * // ]
181
+ * // }
182
+ * // }
183
+ * // }
184
+ * // ]
185
+ * // }
186
+ * ```
42
187
  */
43
188
  async call(method, params) {
44
189
  /* eslint-disable no-await-in-loop */
@@ -149,11 +294,29 @@ class Provider {
149
294
  return this.call("block_store.get_blocks_by_id", {
150
295
  block_ids: blockIds,
151
296
  return_block: opts && opts.returnBlock !== undefined ? opts.returnBlock : true,
152
- return_receipt: opts && opts.returnReceipt !== undefined ? opts.returnReceipt : false,
297
+ return_receipt: opts && opts.returnReceipt !== undefined ? opts.returnReceipt : true,
153
298
  });
154
299
  }
155
300
  /**
156
301
  * Function to get info from the head block in the blockchain
302
+ *
303
+ * @example
304
+ * ```ts
305
+ * const provider = new Provider("https://api.koinos.io");
306
+ * const headInfo = await provider.getHeadInfo();
307
+ * console.log(headInfo);
308
+ *
309
+ * // {
310
+ * // head_topology: {
311
+ * // id: '0x12209f7c9b4d695eefd6f87465d490654e495fe25a3d7d2e1eb80658acdc49bad962',
312
+ * // height: '14957951',
313
+ * // previous: '0x1220bc3b94e3a2adc3ca09d61a4418df1f4acfa78a69686f592877c194ea50642cd2'
314
+ * // },
315
+ * // last_irreversible_block: '14957891',
316
+ * // head_state_merkle_root: 'EiCriqXooNUXBG23EUKLz2qq3h9ZAC8w1W7w185YQ9MzIA==',
317
+ * // head_block_time: '1713874497290'
318
+ * // }
319
+ * ```
157
320
  */
158
321
  async getHeadInfo() {
159
322
  return this.call("chain.get_head_info", {});
@@ -184,14 +347,80 @@ class Provider {
184
347
  ancestor_start_height: height,
185
348
  num_blocks: numBlocks,
186
349
  return_block: opts && opts.returnBlock !== undefined ? opts.returnBlock : true,
187
- return_receipt: opts && opts.returnReceipt !== undefined ? opts.returnReceipt : false,
350
+ return_receipt: opts && opts.returnReceipt !== undefined ? opts.returnReceipt : true,
188
351
  })).block_items;
189
352
  }
190
353
  /**
191
354
  * Function to get a block by its height
355
+ *
356
+ * @example
357
+ * ```ts
358
+ * const provider = new Provider("https://api.koinos.io");
359
+ * const block = await provider.getBlock(14951433);
360
+ * console.log(block);
361
+ *
362
+ * // {
363
+ * // block_id: '0x1220d5e848eb0f69c590c24cbea4391f89a1055f540bc265c60f6b13c4cc0055ec36',
364
+ * // block_height: '14951433',
365
+ * // block: {
366
+ * // id: '0x1220d5e848eb0f69c590c24cbea4391f89a1055f540bc265c60f6b13c4cc0055ec36',
367
+ * // header: {
368
+ * // previous: '0x1220a3c4cbc57ccee4d02b4a1849a9e504122ee93b904deff711d926def2ea2cc878',
369
+ * // height: '14951433',
370
+ * // timestamp: '1713854518430',
371
+ * // previous_state_merkle_root: 'EiCPcnYosMvEBYeCcJrdIJJG0mp4TJ796UGxa0NY6EvzbQ==',
372
+ * // transaction_merkle_root: 'EiBGPKwttckB7c_BafwnHHmHTBa9S1vKBKauj_yLVNb0tg==',
373
+ * // signer: '1EPZaqve43k9Jq5mNeT2ydCjUiytTTU4U',
374
+ * // approved_proposals: [Array]
375
+ * // },
376
+ * // transactions: [ [Object] ],
377
+ * // signature: 'ClEDnHKX1F-pQVbFhmz2qnrwGfP-RbEfTdRFUrvmhmqMeoejtmm2Q0yIPbD5kN5xpIEb
378
+ * // 8vVwsIJ3lTrgFz2E8w0Paxkgv1E_gMaYNq5UUqtHnl0SIhIgAAbuPHmfMKh9R0Yi5y1D
379
+ * // TpjjdN0DYKaIUseXzLiLg_QaQR9jRinZf0g_qo2_4wOx9gDBunIij0r5CycHrNMsuT_V
380
+ * // _UvrJOYuwj7aUCA-qnF2tCBQoNQZ3ww7WvKHrMdChxxy'
381
+ * // },
382
+ * // receipt: {
383
+ * // id: '0x1220d5e848eb0f69c590c24cbea4391f89a1055f540bc265c60f6b13c4cc0055ec36',
384
+ * // height: '14951433',
385
+ * // disk_storage_used: '35',
386
+ * // network_bandwidth_used: '760',
387
+ * // compute_bandwidth_used: '5253506',
388
+ * // events: [ [Object], [Object] ],
389
+ * // transaction_receipts: [ [Object] ],
390
+ * // disk_storage_charged: '35',
391
+ * // network_bandwidth_charged: '760',
392
+ * // compute_bandwidth_charged: '5180427',
393
+ * // state_delta_entries: [
394
+ * // [Object], [Object],
395
+ * // [Object], [Object],
396
+ * // [Object], [Object],
397
+ * // [Object], [Object],
398
+ * // [Object], [Object]
399
+ * // ]
400
+ * // }
401
+ * // }
402
+ * ```
403
+ *
404
+ * Use the options to get less information. This helps to reduce
405
+ * the bandwidth of the call.
406
+ *
407
+ * @example
408
+ * ```ts
409
+ * const provider = new Provider("https://api.koinos.io");
410
+ * const block = await provider.getBlock(14951433, {
411
+ * returnReceipt: false,
412
+ * returnBlock: false
413
+ * });
414
+ * console.log(block);
415
+ *
416
+ * // {
417
+ * // block_id: '0x1220d5e848eb0f69c590c24cbea4391f89a1055f540bc265c60f6b13c4cc0055ec36',
418
+ * // block_height: '14951433'
419
+ * // }
420
+ * ```
192
421
  */
193
- async getBlock(height) {
194
- return (await this.getBlocks(height, 1))[0];
422
+ async getBlock(height, opts) {
423
+ return (await this.getBlocks(height, 1, undefined, opts))[0];
195
424
  }
196
425
  /**
197
426
  * Function to wait for a transaction to be mined.
@@ -304,9 +533,11 @@ class Provider {
304
533
  */
305
534
  async sendTransaction(transaction, broadcast = true) {
306
535
  const response = await this.call("chain.submit_transaction", { transaction, broadcast });
307
- transaction.wait = async (type = "byBlock", timeout = 15000) => {
308
- return this.wait(transaction.id, type, timeout);
309
- };
536
+ if (broadcast) {
537
+ transaction.wait = async (type = "byBlock", timeout = 15000) => {
538
+ return this.wait(transaction.id, type, timeout);
539
+ };
540
+ }
310
541
  return { ...response, transaction: transaction };
311
542
  }
312
543
  /**
@@ -358,6 +589,28 @@ class Provider {
358
589
  const result = await serializer.deserialize(response.value, serializer.returnTypeName);
359
590
  return result;
360
591
  }
592
+ /**
593
+ * Function to get the contract metadata of a specific contract.
594
+ * @param contractId contract ID
595
+ *
596
+ * @example
597
+ * ```ts
598
+ * const provider = new Provider("https://api.koinos.io");
599
+ * const result = await provider.invokeGetContractMetadata("15DJN4a8SgrbGhhGksSBASiSYjGnMU8dGL");
600
+ * console.log(result);
601
+ *
602
+ * // {
603
+ * // value: {
604
+ * // hash: '0x1220c57e3573189868970a3a1662a667c366b15015d9b7900ffed415c5e944036e88',
605
+ * // system: true,
606
+ * // authorizes_call_contract: true,
607
+ * // authorizes_transaction_application: true,
608
+ * // authorizes_upload_contract: true
609
+ * // }
610
+ * // }
611
+ *
612
+ * ```
613
+ */
361
614
  async invokeGetContractMetadata(contractId) {
362
615
  const serializer = new Serializer_1.Serializer({
363
616
  nested: {