starknet 4.17.0 → 4.18.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 (150) hide show
  1. package/CHANGELOG.md +20 -0
  2. package/README.md +2 -10
  3. package/dist/index.d.ts +27 -9
  4. package/dist/index.global.js +30 -13
  5. package/dist/index.global.js.map +1 -1
  6. package/dist/index.js +30 -13
  7. package/dist/index.js.map +1 -1
  8. package/dist/index.mjs +30 -13
  9. package/dist/index.mjs.map +1 -1
  10. package/package.json +5 -1
  11. package/.babelrc +0 -6
  12. package/.commitlintrc +0 -22
  13. package/.eslintignore +0 -2
  14. package/.eslintrc +0 -28
  15. package/.prettierrc +0 -6
  16. package/.releaserc +0 -28
  17. package/CODE_OF_CONDUCT.md +0 -128
  18. package/CONTRIBUTING.md +0 -52
  19. package/__mocks__/Account.json +0 -25486
  20. package/__mocks__/ERC20.json +0 -40027
  21. package/__mocks__/TestDapp.json +0 -12962
  22. package/__mocks__/contract.json +0 -33191
  23. package/__mocks__/l1l2_compiled.json +0 -10107
  24. package/__mocks__/multicall.json +0 -8139
  25. package/__mocks__/naming_compiled.json +0 -53283
  26. package/__mocks__/starknetId_compiled.json +0 -44703
  27. package/__mocks__/typedDataExample.json +0 -35
  28. package/__mocks__/typedDataSessionExample.json +0 -42
  29. package/__mocks__/typedDataStructArrayExample.json +0 -44
  30. package/__tests__/account.test.ts +0 -345
  31. package/__tests__/contract.test.ts +0 -249
  32. package/__tests__/defaultProvider.test.ts +0 -177
  33. package/__tests__/fixtures.ts +0 -84
  34. package/__tests__/jest.setup.ts +0 -30
  35. package/__tests__/rpcProvider.test.ts +0 -132
  36. package/__tests__/sequencerProvider.test.ts +0 -123
  37. package/__tests__/utils/__snapshots__/ellipticalCurve.test.ts.snap +0 -5
  38. package/__tests__/utils/__snapshots__/utils.browser.test.ts.snap +0 -5
  39. package/__tests__/utils/__snapshots__/utils.test.ts.snap +0 -5
  40. package/__tests__/utils/address.test.ts +0 -45
  41. package/__tests__/utils/ellipticalCurve.test.ts +0 -91
  42. package/__tests__/utils/merkle.test.ts +0 -256
  43. package/__tests__/utils/shortString.test.ts +0 -22
  44. package/__tests__/utils/starknetId.test.ts +0 -53
  45. package/__tests__/utils/transactionHash.test.ts +0 -17
  46. package/__tests__/utils/typedData.test.ts +0 -223
  47. package/__tests__/utils/uint256.test.ts +0 -32
  48. package/__tests__/utils/utils.browser.test.ts +0 -29
  49. package/__tests__/utils/utils.test.ts +0 -141
  50. package/img/logo.svg +0 -17
  51. package/index.d.ts +0 -2683
  52. package/index.global.js +0 -23192
  53. package/index.global.js.map +0 -1
  54. package/index.js +0 -4910
  55. package/index.js.map +0 -1
  56. package/index.mjs +0 -4852
  57. package/index.mjs.map +0 -1
  58. package/src/account/default.ts +0 -501
  59. package/src/account/index.ts +0 -2
  60. package/src/account/interface.ts +0 -309
  61. package/src/constants.ts +0 -2065
  62. package/src/contract/contractFactory.ts +0 -88
  63. package/src/contract/default.ts +0 -425
  64. package/src/contract/index.ts +0 -3
  65. package/src/contract/interface.ts +0 -106
  66. package/src/index.ts +0 -26
  67. package/src/provider/default.ts +0 -187
  68. package/src/provider/errors.ts +0 -14
  69. package/src/provider/index.ts +0 -9
  70. package/src/provider/interface.ts +0 -281
  71. package/src/provider/rpc.ts +0 -482
  72. package/src/provider/sequencer.ts +0 -523
  73. package/src/provider/utils.ts +0 -100
  74. package/src/signer/default.ts +0 -99
  75. package/src/signer/index.ts +0 -2
  76. package/src/signer/interface.ts +0 -77
  77. package/src/types/account.ts +0 -43
  78. package/src/types/api/index.ts +0 -10
  79. package/src/types/api/openrpc.ts +0 -607
  80. package/src/types/api/rpc.ts +0 -45
  81. package/src/types/api/sequencer.ts +0 -369
  82. package/src/types/contract.ts +0 -5
  83. package/src/types/index.ts +0 -8
  84. package/src/types/lib.ts +0 -143
  85. package/src/types/provider.ts +0 -134
  86. package/src/types/signer.ts +0 -24
  87. package/src/utils/address.ts +0 -44
  88. package/src/utils/calldata.ts +0 -250
  89. package/src/utils/ellipticCurve.ts +0 -120
  90. package/src/utils/encode.ts +0 -66
  91. package/src/utils/events.ts +0 -32
  92. package/src/utils/fetchPonyfill.ts +0 -5
  93. package/src/utils/hash.ts +0 -235
  94. package/src/utils/json.ts +0 -15
  95. package/src/utils/merkle.ts +0 -69
  96. package/src/utils/number.ts +0 -98
  97. package/src/utils/provider.ts +0 -28
  98. package/src/utils/responseParser/index.ts +0 -28
  99. package/src/utils/responseParser/rpc.ts +0 -70
  100. package/src/utils/responseParser/sequencer.ts +0 -135
  101. package/src/utils/shortString.ts +0 -21
  102. package/src/utils/stark.ts +0 -57
  103. package/src/utils/starknetId.ts +0 -116
  104. package/src/utils/transaction.ts +0 -56
  105. package/src/utils/typedData/index.ts +0 -247
  106. package/src/utils/typedData/types.ts +0 -37
  107. package/src/utils/typedData/utils.ts +0 -16
  108. package/src/utils/uint256.ts +0 -32
  109. package/src/utils/url.ts +0 -53
  110. package/tsconfig.eslint.json +0 -4
  111. package/tsup.config.ts +0 -9
  112. package/www/README.md +0 -41
  113. package/www/babel.config.js +0 -3
  114. package/www/code-examples/account.js +0 -65
  115. package/www/code-examples/amm.js +0 -44
  116. package/www/code-examples/erc20.js +0 -13
  117. package/www/code-examples/package-lock.json +0 -336
  118. package/www/code-examples/package.json +0 -15
  119. package/www/docs/API/_category_.json +0 -5
  120. package/www/docs/API/account.md +0 -463
  121. package/www/docs/API/changelog.md +0 -15
  122. package/www/docs/API/contract.md +0 -135
  123. package/www/docs/API/contractFactory.md +0 -45
  124. package/www/docs/API/index.md +0 -3
  125. package/www/docs/API/provider.md +0 -725
  126. package/www/docs/API/signer.md +0 -105
  127. package/www/docs/API/utils.md +0 -374
  128. package/www/docusaurus.config.js +0 -130
  129. package/www/guides/account.md +0 -140
  130. package/www/guides/cra.md +0 -3
  131. package/www/guides/erc20.md +0 -163
  132. package/www/guides/intro.md +0 -63
  133. package/www/package-lock.json +0 -20405
  134. package/www/package.json +0 -43
  135. package/www/sidebars.js +0 -31
  136. package/www/src/components/HomepageFeatures/index.tsx +0 -67
  137. package/www/src/components/HomepageFeatures/styles.module.css +0 -10
  138. package/www/src/css/custom.css +0 -39
  139. package/www/src/pages/index.module.css +0 -23
  140. package/www/src/pages/index.tsx +0 -40
  141. package/www/src/pages/markdown-page.md +0 -7
  142. package/www/static/.nojekyll +0 -0
  143. package/www/static/img/docusaurus.png +0 -0
  144. package/www/static/img/favicon.ico +0 -0
  145. package/www/static/img/logo.svg +0 -17
  146. package/www/static/img/starknet-1.png +0 -0
  147. package/www/static/img/starknet-2.png +0 -0
  148. package/www/static/img/starknet-3.png +0 -0
  149. package/www/static/img/tutorial/docsVersionDropdown.png +0 -0
  150. package/www/static/img/tutorial/localeDropdown.png +0 -0
@@ -1,482 +0,0 @@
1
- import { StarknetChainId } from '../constants';
2
- import {
3
- Call,
4
- CallContractResponse,
5
- DeclareContractResponse,
6
- DeclareContractTransaction,
7
- DeployAccountContractTransaction,
8
- DeployContractResponse,
9
- EstimateFeeResponse,
10
- GetBlockResponse,
11
- GetCodeResponse,
12
- GetTransactionResponse,
13
- Invocation,
14
- InvocationsDetailsWithNonce,
15
- InvokeFunctionResponse,
16
- RPC,
17
- } from '../types';
18
- import fetch from '../utils/fetchPonyfill';
19
- import { getSelectorFromName } from '../utils/hash';
20
- import { stringify } from '../utils/json';
21
- import {
22
- BigNumberish,
23
- bigNumberishArrayToHexadecimalStringArray,
24
- toBN,
25
- toHex,
26
- } from '../utils/number';
27
- import { parseCalldata, wait } from '../utils/provider';
28
- import { RPCResponseParser } from '../utils/responseParser/rpc';
29
- import { ProviderInterface } from './interface';
30
- import { Block, BlockIdentifier } from './utils';
31
-
32
- export type RpcProviderOptions = {
33
- nodeUrl: string;
34
- retries?: number;
35
- headers?: object;
36
- blockIdentifier?: BlockIdentifier;
37
- };
38
-
39
- // Default Pathfinder disabled pending block https://github.com/eqlabs/pathfinder/blob/main/README.md
40
- // Note that pending support is disabled by default and must be enabled by setting poll-pending=true in the configuration options.
41
- const defaultOptions = {
42
- headers: { 'Content-Type': 'application/json' },
43
- blockIdentifier: 'latest',
44
- retries: 200,
45
- };
46
-
47
- export class RpcProvider implements ProviderInterface {
48
- public nodeUrl: string;
49
-
50
- public chainId!: StarknetChainId;
51
-
52
- public headers: object;
53
-
54
- private responseParser = new RPCResponseParser();
55
-
56
- private retries: number;
57
-
58
- private blockIdentifier: BlockIdentifier;
59
-
60
- constructor(optionsOrProvider: RpcProviderOptions) {
61
- const { nodeUrl, retries, headers, blockIdentifier } = optionsOrProvider;
62
- this.nodeUrl = nodeUrl;
63
- this.retries = retries || defaultOptions.retries;
64
- this.headers = { ...defaultOptions.headers, ...headers };
65
- this.blockIdentifier = blockIdentifier || defaultOptions.blockIdentifier;
66
-
67
- this.getChainId().then((chainId) => {
68
- this.chainId = chainId;
69
- });
70
- }
71
-
72
- public fetch(method: any, params: any): Promise<any> {
73
- return fetch(this.nodeUrl, {
74
- method: 'POST',
75
- body: stringify({ method, jsonrpc: '2.0', params, id: 0 }),
76
- headers: this.headers as Record<string, string>,
77
- });
78
- }
79
-
80
- protected errorHandler(error: any) {
81
- if (error) {
82
- const { code, message } = error;
83
- throw new Error(`${code}: ${message}`);
84
- }
85
- }
86
-
87
- protected async fetchEndpoint<T extends keyof RPC.Methods>(
88
- method: T,
89
- params?: RPC.Methods[T]['params']
90
- ): Promise<RPC.Methods[T]['result']> {
91
- try {
92
- const rawResult = await this.fetch(method, params);
93
- const { error, result } = await rawResult.json();
94
- this.errorHandler(error);
95
- return result as RPC.Methods[T]['result'];
96
- } catch (error: any) {
97
- this.errorHandler(error?.response?.data);
98
- throw error;
99
- }
100
- }
101
-
102
- // Methods from Interface
103
- public async getChainId(): Promise<any> {
104
- return this.fetchEndpoint('starknet_chainId');
105
- }
106
-
107
- // Methods from Interface
108
- public async getBlock(
109
- blockIdentifier: BlockIdentifier = this.blockIdentifier
110
- ): Promise<GetBlockResponse> {
111
- return this.getBlockWithTxHashes(blockIdentifier).then(
112
- this.responseParser.parseGetBlockResponse
113
- );
114
- }
115
-
116
- public async getBlockHashAndNumber(): Promise<RPC.BlockHashAndNumber> {
117
- return this.fetchEndpoint('starknet_blockHashAndNumber');
118
- }
119
-
120
- public async getBlockWithTxHashes(
121
- blockIdentifier: BlockIdentifier = this.blockIdentifier
122
- ): Promise<RPC.GetBlockWithTxHashesResponse> {
123
- const block_id = new Block(blockIdentifier).identifier;
124
- return this.fetchEndpoint('starknet_getBlockWithTxHashes', { block_id });
125
- }
126
-
127
- public async getBlockWithTxs(
128
- blockIdentifier: BlockIdentifier = this.blockIdentifier
129
- ): Promise<RPC.GetBlockWithTxs> {
130
- const block_id = new Block(blockIdentifier).identifier;
131
- return this.fetchEndpoint('starknet_getBlockWithTxs', { block_id });
132
- }
133
-
134
- public async getClassHashAt(
135
- contractAddress: RPC.ContractAddress,
136
- blockIdentifier: BlockIdentifier = this.blockIdentifier
137
- ): Promise<RPC.Felt> {
138
- const block_id = new Block(blockIdentifier).identifier;
139
- return this.fetchEndpoint('starknet_getClassHashAt', {
140
- block_id,
141
- contract_address: contractAddress,
142
- });
143
- }
144
-
145
- public async getNonceForAddress(
146
- contractAddress: string,
147
- blockIdentifier: BlockIdentifier = this.blockIdentifier
148
- ): Promise<RPC.Nonce> {
149
- const block_id = new Block(blockIdentifier).identifier;
150
- return this.fetchEndpoint('starknet_getNonce', {
151
- contract_address: contractAddress,
152
- block_id,
153
- });
154
- }
155
-
156
- public async getPendingTransactions(): Promise<RPC.PendingTransactions> {
157
- return this.fetchEndpoint('starknet_pendingTransactions');
158
- }
159
-
160
- public async getProtocolVersion(): Promise<Error> {
161
- throw new Error('Pathfinder does not implement this rpc 0.1.0 method');
162
- }
163
-
164
- public async getStateUpdate(
165
- blockIdentifier: BlockIdentifier = this.blockIdentifier
166
- ): Promise<RPC.StateUpdate> {
167
- const block_id = new Block(blockIdentifier).identifier;
168
- return this.fetchEndpoint('starknet_getStateUpdate', { block_id });
169
- }
170
-
171
- public async getStorageAt(
172
- contractAddress: string,
173
- key: BigNumberish,
174
- blockIdentifier: BlockIdentifier = this.blockIdentifier
175
- ): Promise<BigNumberish> {
176
- const parsedKey = toHex(toBN(key));
177
- const block_id = new Block(blockIdentifier).identifier;
178
- return this.fetchEndpoint('starknet_getStorageAt', {
179
- contract_address: contractAddress,
180
- key: parsedKey,
181
- block_id,
182
- });
183
- }
184
-
185
- // Methods from Interface
186
- public async getTransaction(txHash: string): Promise<GetTransactionResponse> {
187
- return this.getTransactionByHash(txHash).then(this.responseParser.parseGetTransactionResponse);
188
- }
189
-
190
- public async getTransactionByHash(txHash: string): Promise<RPC.GetTransactionByHashResponse> {
191
- return this.fetchEndpoint('starknet_getTransactionByHash', { transaction_hash: txHash });
192
- }
193
-
194
- public async getTransactionByBlockIdAndIndex(
195
- blockIdentifier: BlockIdentifier,
196
- index: number
197
- ): Promise<RPC.GetTransactionByBlockIdAndIndex> {
198
- const block_id = new Block(blockIdentifier).identifier;
199
- return this.fetchEndpoint('starknet_getTransactionByBlockIdAndIndex', { block_id, index });
200
- }
201
-
202
- public async getTransactionReceipt(txHash: string): Promise<RPC.TransactionReceipt> {
203
- return this.fetchEndpoint('starknet_getTransactionReceipt', { transaction_hash: txHash });
204
- }
205
-
206
- public async getClassByHash(classHash: RPC.Felt): Promise<RPC.ContractClass> {
207
- return this.getClass(classHash);
208
- }
209
-
210
- public async getClass(
211
- classHash: RPC.Felt,
212
- blockIdentifier: BlockIdentifier = this.blockIdentifier
213
- ): Promise<RPC.ContractClass> {
214
- const block_id = new Block(blockIdentifier).identifier;
215
- return this.fetchEndpoint('starknet_getClass', { class_hash: classHash, block_id });
216
- }
217
-
218
- public async getClassAt(
219
- contractAddress: string,
220
- blockIdentifier: BlockIdentifier = this.blockIdentifier
221
- ): Promise<RPC.ContractClass> {
222
- const block_id = new Block(blockIdentifier).identifier;
223
- return this.fetchEndpoint('starknet_getClassAt', {
224
- block_id,
225
- contract_address: contractAddress,
226
- });
227
- }
228
-
229
- public async getCode(
230
- _contractAddress: string,
231
- _blockIdentifier?: BlockIdentifier
232
- ): Promise<GetCodeResponse> {
233
- throw new Error('RPC does not implement getCode function');
234
- }
235
-
236
- public async getEstimateFee(
237
- invocation: Invocation,
238
- invocationDetails: InvocationsDetailsWithNonce,
239
- blockIdentifier: BlockIdentifier = this.blockIdentifier
240
- ): Promise<EstimateFeeResponse> {
241
- return this.getInvokeEstimateFee(invocation, invocationDetails, blockIdentifier);
242
- }
243
-
244
- public async getInvokeEstimateFee(
245
- invocation: Invocation,
246
- invocationDetails: InvocationsDetailsWithNonce,
247
- blockIdentifier: BlockIdentifier = this.blockIdentifier
248
- ): Promise<EstimateFeeResponse> {
249
- const block_id = new Block(blockIdentifier).identifier;
250
- return this.fetchEndpoint('starknet_estimateFee', {
251
- request: {
252
- type: 'INVOKE',
253
- sender_address: invocation.contractAddress,
254
- calldata: parseCalldata(invocation.calldata),
255
- signature: bigNumberishArrayToHexadecimalStringArray(invocation.signature || []),
256
- version: toHex(toBN(invocationDetails?.version || 0)),
257
- nonce: toHex(toBN(invocationDetails.nonce)),
258
- max_fee: toHex(toBN(invocationDetails?.maxFee || 0)),
259
- },
260
- block_id,
261
- }).then(this.responseParser.parseFeeEstimateResponse);
262
- }
263
-
264
- // TODO: Revisit after Pathfinder release with JSON-RPC v0.2.1 RPC Spec
265
-
266
- public async getDeclareEstimateFee(
267
- { senderAddress, contractDefinition, signature }: DeclareContractTransaction,
268
- details: InvocationsDetailsWithNonce,
269
- blockIdentifier: BlockIdentifier = this.blockIdentifier
270
- ): Promise<EstimateFeeResponse> {
271
- const block_id = new Block(blockIdentifier).identifier;
272
- return this.fetchEndpoint('starknet_estimateFee', {
273
- request: {
274
- type: 'DECLARE',
275
- contract_class: {
276
- program: contractDefinition.program,
277
- entry_points_by_type: contractDefinition.entry_points_by_type,
278
- abi: contractDefinition.abi, // rpc 2.0
279
- },
280
- sender_address: senderAddress,
281
- signature: bigNumberishArrayToHexadecimalStringArray(signature || []),
282
- version: toHex(toBN(details?.version || 0)),
283
- nonce: toHex(toBN(details.nonce)),
284
- max_fee: toHex(toBN(details?.maxFee || 0)),
285
- },
286
- block_id,
287
- }).then(this.responseParser.parseFeeEstimateResponse);
288
- }
289
-
290
- public async getDeployAccountEstimateFee(
291
- { classHash, constructorCalldata, addressSalt, signature }: DeployAccountContractTransaction,
292
- details: InvocationsDetailsWithNonce,
293
- blockIdentifier: BlockIdentifier = this.blockIdentifier
294
- ): Promise<EstimateFeeResponse> {
295
- const block_id = new Block(blockIdentifier).identifier;
296
- return this.fetchEndpoint('starknet_estimateFee', {
297
- request: {
298
- type: 'DEPLOY_ACCOUNT',
299
- constructor_calldata: bigNumberishArrayToHexadecimalStringArray(constructorCalldata || []),
300
- class_hash: toHex(toBN(classHash)),
301
- contract_address_salt: toHex(toBN(addressSalt || 0)),
302
- signature: bigNumberishArrayToHexadecimalStringArray(signature || []),
303
- version: toHex(toBN(details?.version || 0)),
304
- nonce: toHex(toBN(details.nonce)),
305
- max_fee: toHex(toBN(details?.maxFee || 0)),
306
- },
307
- block_id,
308
- }).then(this.responseParser.parseFeeEstimateResponse);
309
- }
310
-
311
- // TODO: Revisit after Pathfinder release with JSON-RPC v0.2.1 RPC Spec
312
- public async declareContract(
313
- { contractDefinition, signature, senderAddress }: DeclareContractTransaction,
314
- details: InvocationsDetailsWithNonce
315
- ): Promise<DeclareContractResponse> {
316
- return this.fetchEndpoint('starknet_addDeclareTransaction', {
317
- declare_transaction: {
318
- contract_class: {
319
- program: contractDefinition.program,
320
- entry_points_by_type: contractDefinition.entry_points_by_type,
321
- abi: contractDefinition.abi, // rpc 2.0
322
- },
323
- type: 'DECLARE',
324
- version: toHex(toBN(details.version || 0)),
325
- max_fee: toHex(toBN(details.maxFee || 0)),
326
- signature: bigNumberishArrayToHexadecimalStringArray(signature || []),
327
- sender_address: senderAddress,
328
- nonce: toHex(toBN(details.nonce)),
329
- },
330
- });
331
- }
332
-
333
- public async deployAccountContract(
334
- { classHash, constructorCalldata, addressSalt, signature }: DeployAccountContractTransaction,
335
- details: InvocationsDetailsWithNonce
336
- ): Promise<DeployContractResponse> {
337
- return this.fetchEndpoint('starknet_addDeployAccountTransaction', {
338
- constructor_calldata: bigNumberishArrayToHexadecimalStringArray(constructorCalldata || []),
339
- class_hash: toHex(toBN(classHash)),
340
- contract_address_salt: toHex(toBN(addressSalt || 0)),
341
- type: 'DEPLOY',
342
- max_fee: toHex(toBN(details.maxFee || 0)),
343
- version: toHex(toBN(details.version || 0)),
344
- signature: bigNumberishArrayToHexadecimalStringArray(signature || []),
345
- nonce: toHex(toBN(details.nonce)),
346
- });
347
- }
348
-
349
- public async invokeFunction(
350
- functionInvocation: Invocation,
351
- details: InvocationsDetailsWithNonce
352
- ): Promise<InvokeFunctionResponse> {
353
- return this.fetchEndpoint('starknet_addInvokeTransaction', {
354
- invoke_transaction: {
355
- sender_address: functionInvocation.contractAddress,
356
- calldata: parseCalldata(functionInvocation.calldata),
357
- type: 'INVOKE',
358
- max_fee: toHex(toBN(details.maxFee || 0)),
359
- version: toHex(toBN(details.version || 0)),
360
- signature: bigNumberishArrayToHexadecimalStringArray(functionInvocation.signature || []),
361
- nonce: toHex(toBN(details.nonce)),
362
- },
363
- });
364
- }
365
-
366
- // Methods from Interface
367
- public async callContract(
368
- call: Call,
369
- blockIdentifier: BlockIdentifier = this.blockIdentifier
370
- ): Promise<CallContractResponse> {
371
- const block_id = new Block(blockIdentifier).identifier;
372
- const result = await this.fetchEndpoint('starknet_call', {
373
- request: {
374
- contract_address: call.contractAddress,
375
- entry_point_selector: getSelectorFromName(call.entrypoint),
376
- calldata: parseCalldata(call.calldata),
377
- },
378
- block_id,
379
- });
380
-
381
- return this.responseParser.parseCallContractResponse(result);
382
- }
383
-
384
- public async traceTransaction(transactionHash: RPC.TransactionHash): Promise<RPC.Trace> {
385
- return this.fetchEndpoint('starknet_traceTransaction', { transaction_hash: transactionHash });
386
- }
387
-
388
- public async traceBlockTransactions(blockHash: RPC.BlockHash): Promise<RPC.Traces> {
389
- return this.fetchEndpoint('starknet_traceBlockTransactions', { block_hash: blockHash });
390
- }
391
-
392
- public async waitForTransaction(
393
- txHash: string,
394
- retryInterval: number = 8000,
395
- successStates = ['ACCEPTED_ON_L1', 'ACCEPTED_ON_L2', 'PENDING']
396
- ) {
397
- const errorStates = ['REJECTED', 'NOT_RECEIVED'];
398
- let { retries } = this;
399
- let onchain = false;
400
- let txReceipt: any = {};
401
-
402
- while (!onchain) {
403
- // eslint-disable-next-line no-await-in-loop
404
- await wait(retryInterval);
405
- try {
406
- // eslint-disable-next-line no-await-in-loop
407
- txReceipt = await this.getTransactionReceipt(txHash);
408
-
409
- if (!('status' in txReceipt)) {
410
- const error = new Error('pending transaction');
411
- throw error;
412
- }
413
-
414
- if (txReceipt.status && successStates.includes(txReceipt.status)) {
415
- onchain = true;
416
- } else if (txReceipt.status && errorStates.includes(txReceipt.status)) {
417
- const message = txReceipt.status;
418
- const error = new Error(message) as Error & { response: any };
419
- error.response = txReceipt;
420
- throw error;
421
- }
422
- } catch (error: unknown) {
423
- if (error instanceof Error && errorStates.includes(error.message)) {
424
- throw error;
425
- }
426
-
427
- if (retries === 0) {
428
- throw new Error(`waitForTransaction timed-out with retries ${this.retries}`);
429
- }
430
- }
431
-
432
- retries -= 1;
433
- }
434
-
435
- await wait(retryInterval);
436
- return txReceipt;
437
- }
438
-
439
- /**
440
- * Gets the transaction count from a block.
441
- *
442
- *
443
- * @param blockIdentifier
444
- * @returns Number of transactions
445
- */
446
- public async getTransactionCount(
447
- blockIdentifier: BlockIdentifier = this.blockIdentifier
448
- ): Promise<RPC.GetTransactionCountResponse> {
449
- const block_id = new Block(blockIdentifier).identifier;
450
- return this.fetchEndpoint('starknet_getBlockTransactionCount', { block_id });
451
- }
452
-
453
- /**
454
- * Gets the latest block number
455
- *
456
- *
457
- * @returns Number of the latest block
458
- */
459
- public async getBlockNumber(): Promise<RPC.GetBlockNumberResponse> {
460
- return this.fetchEndpoint('starknet_blockNumber');
461
- }
462
-
463
- /**
464
- * Gets syncing status of the node
465
- *
466
- *
467
- * @returns Object with the stats data
468
- */
469
- public async getSyncingStats(): Promise<RPC.GetSyncingStatsResponse> {
470
- return this.fetchEndpoint('starknet_syncing');
471
- }
472
-
473
- /**
474
- * Gets all the events filtered
475
- *
476
- *
477
- * @returns events and the pagination of the events
478
- */
479
- public async getEvents(eventFilter: RPC.EventFilter): Promise<RPC.GetEventsResponse> {
480
- return this.fetchEndpoint('starknet_getEvents', { filter: eventFilter });
481
- }
482
- }