starknet 2.3.1 → 2.7.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 (62) hide show
  1. package/CHANGELOG.md +43 -0
  2. package/__tests__/account.test.ts +3 -3
  3. package/__tests__/provider.test.ts +24 -13
  4. package/__tests__/signer.test.ts +17 -0
  5. package/__tests__/utils/ellipticalCurve.test.ts +1 -1
  6. package/__tests__/utils/typedData.test.ts +72 -0
  7. package/contract.d.ts +2 -2
  8. package/dist/contract.d.ts +2 -2
  9. package/dist/index.d.ts +1 -0
  10. package/dist/index.js +2 -1
  11. package/dist/provider/default.d.ts +26 -22
  12. package/dist/provider/default.js +64 -47
  13. package/dist/provider/interface.d.ts +25 -21
  14. package/dist/provider/utils.d.ts +27 -0
  15. package/dist/provider/utils.js +37 -0
  16. package/dist/signer/default.d.ts +20 -3
  17. package/dist/signer/default.js +61 -20
  18. package/dist/signer/interface.d.ts +22 -3
  19. package/dist/types.d.ts +10 -7
  20. package/dist/utils/ellipticCurve.d.ts +8 -1
  21. package/dist/utils/ellipticCurve.js +48 -9
  22. package/dist/utils/stark.d.ts +2 -3
  23. package/dist/utils/typedData/index.d.ts +91 -0
  24. package/dist/utils/typedData/index.js +183 -0
  25. package/dist/utils/typedData/types.d.ts +82 -0
  26. package/dist/utils/typedData/types.js +47 -0
  27. package/dist/utils/typedData/utils.d.ts +24 -0
  28. package/dist/utils/typedData/utils.js +15 -0
  29. package/index.d.ts +1 -0
  30. package/index.js +3 -1
  31. package/package.json +3 -1
  32. package/provider/default.d.ts +40 -21
  33. package/provider/default.js +85 -53
  34. package/provider/interface.d.ts +37 -21
  35. package/provider/utils.d.ts +30 -0
  36. package/provider/utils.js +39 -0
  37. package/signer/default.d.ts +20 -3
  38. package/signer/default.js +60 -17
  39. package/signer/interface.d.ts +22 -3
  40. package/src/contract.ts +2 -2
  41. package/src/index.ts +1 -0
  42. package/src/provider/default.ts +65 -40
  43. package/src/provider/interface.ts +36 -21
  44. package/src/provider/utils.ts +38 -0
  45. package/src/signer/default.ts +49 -17
  46. package/src/signer/interface.ts +26 -3
  47. package/src/types.ts +16 -7
  48. package/src/utils/ellipticCurve.ts +31 -9
  49. package/src/utils/stark.ts +4 -4
  50. package/src/utils/typedData/index.ts +176 -0
  51. package/src/utils/typedData/types.ts +82 -0
  52. package/src/utils/typedData/utils.ts +13 -0
  53. package/types.d.ts +12 -8
  54. package/utils/ellipticCurve.d.ts +12 -1
  55. package/utils/ellipticCurve.js +72 -23
  56. package/utils/stark.d.ts +2 -3
  57. package/utils/typedData/index.d.ts +113 -0
  58. package/utils/typedData/index.js +247 -0
  59. package/utils/typedData/types.d.ts +103 -0
  60. package/utils/typedData/types.js +57 -0
  61. package/utils/typedData/utils.d.ts +27 -0
  62. package/utils/typedData/utils.js +15 -0
@@ -1,5 +1,6 @@
1
1
  import {
2
2
  AddTransactionResponse,
3
+ BlockNumber,
3
4
  CallContractResponse,
4
5
  CallContractTransaction,
5
6
  CompiledContract,
@@ -8,11 +9,12 @@ import {
8
9
  GetContractAddressesResponse,
9
10
  GetTransactionResponse,
10
11
  GetTransactionStatusResponse,
12
+ Signature,
11
13
  Transaction,
12
14
  } from '../types';
13
15
  import { BigNumberish } from '../utils/number';
14
16
  import { ProviderInterface } from './interface';
15
- declare type NetworkName = 'mainnet-alpha' | 'georli-alpha';
17
+ declare type NetworkName = 'mainnet-alpha' | 'goerli-alpha';
16
18
  declare type ProviderOptions =
17
19
  | {
18
20
  network: NetworkName;
@@ -38,50 +40,67 @@ export declare class Provider implements ProviderInterface {
38
40
  /**
39
41
  * Calls a function on the StarkNet contract.
40
42
  *
41
- * [Reference](https://github.com/starkware-libs/cairo-lang/blob/f464ec4797361b6be8989e36e02ec690e74ef285/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L17-L25)
43
+ * [Reference](https://github.com/starkware-libs/cairo-lang/blob/fc97bdd8322a7df043c87c371634b26c15ed6cee/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L25-L39)
42
44
  *
43
- * @param invokeTx - transaction to be invoked
44
- * @param blockId
45
+ * @param invokeTransaction - transaction to be invoked
46
+ * @param blockHash
47
+ * @param blockNumber
45
48
  * @returns the result of the function on the smart contract.
46
49
  */
47
- callContract(invokeTx: CallContractTransaction, blockId?: number): Promise<CallContractResponse>;
50
+ callContract(
51
+ invokeTransaction: CallContractTransaction,
52
+ blockHash?: BigNumberish,
53
+ blockNumber?: BlockNumber
54
+ ): Promise<CallContractResponse>;
48
55
  /**
49
- * Gets the block information from a block ID.
56
+ * Gets the block information
50
57
  *
51
- * [Reference](https://github.com/starkware-libs/cairo-lang/blob/f464ec4797361b6be8989e36e02ec690e74ef285/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L27-L31)
58
+ * [Reference](https://github.com/starkware-libs/cairo-lang/blob/fc97bdd8322a7df043c87c371634b26c15ed6cee/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L41-L53)
52
59
  *
53
- * @param blockId
54
- * @returns the block object { block_id, previous_block_id, state_root, status, timestamp, transaction_receipts, transactions }
60
+ * @param blockHash
61
+ * @param blockNumber
62
+ * @returns the block object { block_number, previous_block_number, state_root, status, timestamp, transaction_receipts, transactions }
55
63
  */
56
- getBlock(blockId?: number): Promise<GetBlockResponse>;
64
+ getBlock(blockHash?: BigNumberish, blockNumber?: BlockNumber): Promise<GetBlockResponse>;
57
65
  /**
58
66
  * Gets the code of the deployed contract.
59
67
  *
60
- * [Reference](https://github.com/starkware-libs/cairo-lang/blob/f464ec4797361b6be8989e36e02ec690e74ef285/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L33-L36)
68
+ * [Reference](https://github.com/starkware-libs/cairo-lang/blob/fc97bdd8322a7df043c87c371634b26c15ed6cee/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L55-L68)
61
69
  *
62
70
  * @param contractAddress
63
- * @param blockId
71
+ * @param blockHash
72
+ * @param blockNumber
64
73
  * @returns Bytecode and ABI of compiled contract
65
74
  */
66
- getCode(contractAddress: string, blockId?: number): Promise<GetCodeResponse>;
75
+ getCode(
76
+ contractAddress: string,
77
+ blockHash?: BigNumberish,
78
+ blockNumber?: BlockNumber
79
+ ): Promise<GetCodeResponse>;
67
80
  /**
68
81
  * Gets the contract's storage variable at a specific key.
69
82
  *
70
- * [Reference](https://github.com/starkware-libs/cairo-lang/blob/f464ec4797361b6be8989e36e02ec690e74ef285/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L38-L46)
83
+ * [Reference](https://github.com/starkware-libs/cairo-lang/blob/fc97bdd8322a7df043c87c371634b26c15ed6cee/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L70-L85)
71
84
  *
72
85
  * @param contractAddress
73
86
  * @param key - from getStorageVarAddress('<STORAGE_VARIABLE_NAME>') (WIP)
74
- * @param blockId
87
+ * @param blockHash
88
+ * @param blockNumber
75
89
  * @returns the value of the storage variable
76
90
  */
77
- getStorageAt(contractAddress: string, key: number, blockId?: number): Promise<object>;
91
+ getStorageAt(
92
+ contractAddress: string,
93
+ key: number,
94
+ blockHash?: BigNumberish,
95
+ blockNumber?: BlockNumber
96
+ ): Promise<object>;
78
97
  /**
79
98
  * Gets the status of a transaction.
80
99
  *
81
100
  * [Reference](https://github.com/starkware-libs/cairo-lang/blob/f464ec4797361b6be8989e36e02ec690e74ef285/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L48-L52)
82
101
  *
83
102
  * @param txHash
84
- * @returns the transaction status object { block_id, tx_status: NOT_RECEIVED | RECEIVED | PENDING | REJECTED | ACCEPTED_ONCHAIN }
103
+ * @returns the transaction status object { block_number, tx_status: NOT_RECEIVED | RECEIVED | PENDING | REJECTED | ACCEPTED_ONCHAIN }
85
104
  */
86
105
  getTransactionStatus(txHash: BigNumberish): Promise<GetTransactionStatusResponse>;
87
106
  /**
@@ -90,7 +109,7 @@ export declare class Provider implements ProviderInterface {
90
109
  * [Reference](https://github.com/starkware-libs/cairo-lang/blob/f464ec4797361b6be8989e36e02ec690e74ef285/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L54-L58)
91
110
  *
92
111
  * @param txHash
93
- * @returns the transacton object { transaction_id, status, transaction, block_id?, block_number?, transaction_index?, transaction_failure_reason? }
112
+ * @returns the transacton object { transaction_id, status, transaction, block_number?, block_number?, transaction_index?, transaction_failure_reason? }
94
113
  */
95
114
  getTransaction(txHash: BigNumberish): Promise<GetTransactionResponse>;
96
115
  /**
@@ -98,10 +117,10 @@ export declare class Provider implements ProviderInterface {
98
117
  *
99
118
  * [Reference](https://github.com/starkware-libs/cairo-lang/blob/f464ec4797361b6be8989e36e02ec690e74ef285/src/starkware/starknet/services/api/gateway/gateway_client.py#L13-L17)
100
119
  *
101
- * @param tx - transaction to be invoked
120
+ * @param transaction - transaction to be invoked
102
121
  * @returns a confirmation of invoking a function on the starknet contract
103
122
  */
104
- addTransaction(tx: Transaction): Promise<AddTransactionResponse>;
123
+ addTransaction(transaction: Transaction): Promise<AddTransactionResponse>;
105
124
  /**
106
125
  * Deploys a given compiled contract (json) to starknet
107
126
  *
@@ -127,7 +146,7 @@ export declare class Provider implements ProviderInterface {
127
146
  contractAddress: string,
128
147
  entrypointSelector: string,
129
148
  calldata?: string[],
130
- signature?: [BigNumberish, BigNumberish]
149
+ signature?: Signature
131
150
  ): Promise<AddTransactionResponse>;
132
151
  waitForTx(txHash: BigNumberish, retryInterval?: number): Promise<void>;
133
152
  }
@@ -156,6 +156,7 @@ var url_join_1 = __importDefault(require('url-join'));
156
156
  var json_1 = require('../utils/json');
157
157
  var number_1 = require('../utils/number');
158
158
  var stark_1 = require('../utils/stark');
159
+ var utils_1 = require('./utils');
159
160
  function wait(delay) {
160
161
  return new Promise(function (res) {
161
162
  return setTimeout(res, delay);
@@ -164,7 +165,7 @@ function wait(delay) {
164
165
  var Provider = /** @class */ (function () {
165
166
  function Provider(optionsOrProvider) {
166
167
  if (optionsOrProvider === void 0) {
167
- optionsOrProvider = { network: 'georli-alpha' };
168
+ optionsOrProvider = { network: 'goerli-alpha' };
168
169
  }
169
170
  if (optionsOrProvider instanceof Provider) {
170
171
  this.baseUrl = optionsOrProvider.baseUrl;
@@ -184,7 +185,7 @@ var Provider = /** @class */ (function () {
184
185
  switch (name) {
185
186
  case 'mainnet-alpha':
186
187
  return 'https://alpha-mainnet.starknet.io';
187
- case 'georli-alpha':
188
+ case 'goerli-alpha':
188
189
  default:
189
190
  return 'https://alpha4.starknet.io';
190
191
  }
@@ -217,27 +218,35 @@ var Provider = /** @class */ (function () {
217
218
  /**
218
219
  * Calls a function on the StarkNet contract.
219
220
  *
220
- * [Reference](https://github.com/starkware-libs/cairo-lang/blob/f464ec4797361b6be8989e36e02ec690e74ef285/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L17-L25)
221
+ * [Reference](https://github.com/starkware-libs/cairo-lang/blob/fc97bdd8322a7df043c87c371634b26c15ed6cee/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L25-L39)
221
222
  *
222
- * @param invokeTx - transaction to be invoked
223
- * @param blockId
223
+ * @param invokeTransaction - transaction to be invoked
224
+ * @param blockHash
225
+ * @param blockNumber
224
226
  * @returns the result of the function on the smart contract.
225
227
  */
226
- Provider.prototype.callContract = function (invokeTx, blockId) {
228
+ Provider.prototype.callContract = function (invokeTransaction, blockHash, blockNumber) {
229
+ if (blockNumber === void 0) {
230
+ blockNumber = null;
231
+ }
227
232
  return __awaiter(this, void 0, void 0, function () {
228
- var data;
233
+ var formattedBlockIdentifier, data;
229
234
  return __generator(this, function (_a) {
230
235
  switch (_a.label) {
231
236
  case 0:
237
+ formattedBlockIdentifier = (0, utils_1.getFormattedBlockIdentifier)(
238
+ blockHash,
239
+ blockNumber
240
+ );
232
241
  return [
233
242
  4 /*yield*/,
234
243
  axios_1.default.post(
235
244
  (0, url_join_1.default)(
236
245
  this.feederGatewayUrl,
237
246
  'call_contract',
238
- '?blockId=' + (blockId !== null && blockId !== void 0 ? blockId : 'null')
247
+ formattedBlockIdentifier
239
248
  ),
240
- __assign({ signature: [], calldata: [] }, invokeTx)
249
+ __assign({ signature: [], calldata: [] }, invokeTransaction)
241
250
  ),
242
251
  ];
243
252
  case 1:
@@ -248,26 +257,34 @@ var Provider = /** @class */ (function () {
248
257
  });
249
258
  };
250
259
  /**
251
- * Gets the block information from a block ID.
260
+ * Gets the block information
252
261
  *
253
- * [Reference](https://github.com/starkware-libs/cairo-lang/blob/f464ec4797361b6be8989e36e02ec690e74ef285/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L27-L31)
262
+ * [Reference](https://github.com/starkware-libs/cairo-lang/blob/fc97bdd8322a7df043c87c371634b26c15ed6cee/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L41-L53)
254
263
  *
255
- * @param blockId
256
- * @returns the block object { block_id, previous_block_id, state_root, status, timestamp, transaction_receipts, transactions }
264
+ * @param blockHash
265
+ * @param blockNumber
266
+ * @returns the block object { block_number, previous_block_number, state_root, status, timestamp, transaction_receipts, transactions }
257
267
  */
258
- Provider.prototype.getBlock = function (blockId) {
268
+ Provider.prototype.getBlock = function (blockHash, blockNumber) {
269
+ if (blockNumber === void 0) {
270
+ blockNumber = null;
271
+ }
259
272
  return __awaiter(this, void 0, void 0, function () {
260
- var data;
273
+ var formattedBlockIdentifier, data;
261
274
  return __generator(this, function (_a) {
262
275
  switch (_a.label) {
263
276
  case 0:
277
+ formattedBlockIdentifier = (0, utils_1.getFormattedBlockIdentifier)(
278
+ blockHash,
279
+ blockNumber
280
+ );
264
281
  return [
265
282
  4 /*yield*/,
266
283
  axios_1.default.get(
267
284
  (0, url_join_1.default)(
268
285
  this.feederGatewayUrl,
269
286
  'get_block',
270
- '?blockId=' + (blockId !== null && blockId !== void 0 ? blockId : 'null')
287
+ formattedBlockIdentifier
271
288
  )
272
289
  ),
273
290
  ];
@@ -281,28 +298,33 @@ var Provider = /** @class */ (function () {
281
298
  /**
282
299
  * Gets the code of the deployed contract.
283
300
  *
284
- * [Reference](https://github.com/starkware-libs/cairo-lang/blob/f464ec4797361b6be8989e36e02ec690e74ef285/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L33-L36)
301
+ * [Reference](https://github.com/starkware-libs/cairo-lang/blob/fc97bdd8322a7df043c87c371634b26c15ed6cee/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L55-L68)
285
302
  *
286
303
  * @param contractAddress
287
- * @param blockId
304
+ * @param blockHash
305
+ * @param blockNumber
288
306
  * @returns Bytecode and ABI of compiled contract
289
307
  */
290
- Provider.prototype.getCode = function (contractAddress, blockId) {
308
+ Provider.prototype.getCode = function (contractAddress, blockHash, blockNumber) {
309
+ if (blockNumber === void 0) {
310
+ blockNumber = null;
311
+ }
291
312
  return __awaiter(this, void 0, void 0, function () {
292
- var data;
313
+ var formattedBlockIdentifier, data;
293
314
  return __generator(this, function (_a) {
294
315
  switch (_a.label) {
295
316
  case 0:
317
+ formattedBlockIdentifier = (0, utils_1.getFormattedBlockIdentifier)(
318
+ blockHash,
319
+ blockNumber
320
+ );
296
321
  return [
297
322
  4 /*yield*/,
298
323
  axios_1.default.get(
299
324
  (0, url_join_1.default)(
300
325
  this.feederGatewayUrl,
301
326
  'get_code',
302
- '?contractAddress=' +
303
- contractAddress +
304
- '&blockId=' +
305
- (blockId !== null && blockId !== void 0 ? blockId : 'null')
327
+ '?contractAddress=' + contractAddress + '&' + formattedBlockIdentifier
306
328
  )
307
329
  ),
308
330
  ];
@@ -317,19 +339,27 @@ var Provider = /** @class */ (function () {
317
339
  /**
318
340
  * Gets the contract's storage variable at a specific key.
319
341
  *
320
- * [Reference](https://github.com/starkware-libs/cairo-lang/blob/f464ec4797361b6be8989e36e02ec690e74ef285/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L38-L46)
342
+ * [Reference](https://github.com/starkware-libs/cairo-lang/blob/fc97bdd8322a7df043c87c371634b26c15ed6cee/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L70-L85)
321
343
  *
322
344
  * @param contractAddress
323
345
  * @param key - from getStorageVarAddress('<STORAGE_VARIABLE_NAME>') (WIP)
324
- * @param blockId
346
+ * @param blockHash
347
+ * @param blockNumber
325
348
  * @returns the value of the storage variable
326
349
  */
327
- Provider.prototype.getStorageAt = function (contractAddress, key, blockId) {
350
+ Provider.prototype.getStorageAt = function (contractAddress, key, blockHash, blockNumber) {
351
+ if (blockNumber === void 0) {
352
+ blockNumber = null;
353
+ }
328
354
  return __awaiter(this, void 0, void 0, function () {
329
- var data;
355
+ var formattedBlockIdentifier, data;
330
356
  return __generator(this, function (_a) {
331
357
  switch (_a.label) {
332
358
  case 0:
359
+ formattedBlockIdentifier = (0, utils_1.getFormattedBlockIdentifier)(
360
+ blockHash,
361
+ blockNumber
362
+ );
333
363
  return [
334
364
  4 /*yield*/,
335
365
  axios_1.default.get(
@@ -340,8 +370,8 @@ var Provider = /** @class */ (function () {
340
370
  contractAddress +
341
371
  '&key=' +
342
372
  key +
343
- '&blockId=' +
344
- (blockId !== null && blockId !== void 0 ? blockId : 'null')
373
+ '&' +
374
+ formattedBlockIdentifier
345
375
  )
346
376
  ),
347
377
  ];
@@ -358,7 +388,7 @@ var Provider = /** @class */ (function () {
358
388
  * [Reference](https://github.com/starkware-libs/cairo-lang/blob/f464ec4797361b6be8989e36e02ec690e74ef285/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L48-L52)
359
389
  *
360
390
  * @param txHash
361
- * @returns the transaction status object { block_id, tx_status: NOT_RECEIVED | RECEIVED | PENDING | REJECTED | ACCEPTED_ONCHAIN }
391
+ * @returns the transaction status object { block_number, tx_status: NOT_RECEIVED | RECEIVED | PENDING | REJECTED | ACCEPTED_ONCHAIN }
362
392
  */
363
393
  Provider.prototype.getTransactionStatus = function (txHash) {
364
394
  return __awaiter(this, void 0, void 0, function () {
@@ -390,7 +420,7 @@ var Provider = /** @class */ (function () {
390
420
  * [Reference](https://github.com/starkware-libs/cairo-lang/blob/f464ec4797361b6be8989e36e02ec690e74ef285/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L54-L58)
391
421
  *
392
422
  * @param txHash
393
- * @returns the transacton object { transaction_id, status, transaction, block_id?, block_number?, transaction_index?, transaction_failure_reason? }
423
+ * @returns the transacton object { transaction_id, status, transaction, block_number?, block_number?, transaction_index?, transaction_failure_reason? }
394
424
  */
395
425
  Provider.prototype.getTransaction = function (txHash) {
396
426
  return __awaiter(this, void 0, void 0, function () {
@@ -421,19 +451,21 @@ var Provider = /** @class */ (function () {
421
451
  *
422
452
  * [Reference](https://github.com/starkware-libs/cairo-lang/blob/f464ec4797361b6be8989e36e02ec690e74ef285/src/starkware/starknet/services/api/gateway/gateway_client.py#L13-L17)
423
453
  *
424
- * @param tx - transaction to be invoked
454
+ * @param transaction - transaction to be invoked
425
455
  * @returns a confirmation of invoking a function on the starknet contract
426
456
  */
427
- Provider.prototype.addTransaction = function (tx) {
457
+ Provider.prototype.addTransaction = function (transaction) {
428
458
  return __awaiter(this, void 0, void 0, function () {
429
459
  var signature, contract_address_salt, data;
430
460
  return __generator(this, function (_a) {
431
461
  switch (_a.label) {
432
462
  case 0:
433
- signature = tx.type === 'INVOKE_FUNCTION' && (0, stark_1.formatSignature)(tx.signature);
463
+ signature =
464
+ transaction.type === 'INVOKE_FUNCTION' &&
465
+ (0, stark_1.formatSignature)(transaction.signature);
434
466
  contract_address_salt =
435
- tx.type === 'DEPLOY' &&
436
- (0, number_1.toHex)((0, number_1.toBN)(tx.contract_address_salt));
467
+ transaction.type === 'DEPLOY' &&
468
+ (0, number_1.toHex)((0, number_1.toBN)(transaction.contract_address_salt));
437
469
  return [
438
470
  4 /*yield*/,
439
471
  axios_1.default.post(
@@ -441,7 +473,7 @@ var Provider = /** @class */ (function () {
441
473
  (0, json_1.stringify)(
442
474
  __assign(
443
475
  __assign(
444
- __assign({}, tx),
476
+ __assign({}, transaction),
445
477
  Array.isArray(signature) && { signature: signature }
446
478
  ),
447
479
  contract_address_salt && { contract_address_salt: contract_address_salt }
@@ -510,34 +542,34 @@ var Provider = /** @class */ (function () {
510
542
  retryInterval = 8000;
511
543
  }
512
544
  return __awaiter(this, void 0, void 0, function () {
513
- var onchain, res;
545
+ var onchain, res, error;
514
546
  return __generator(this, function (_a) {
515
547
  switch (_a.label) {
516
548
  case 0:
517
549
  onchain = false;
518
- _a.label = 1;
550
+ return [4 /*yield*/, wait(retryInterval)];
519
551
  case 1:
520
- if (!!onchain) return [3 /*break*/, 4];
552
+ _a.sent();
553
+ _a.label = 2;
554
+ case 2:
555
+ if (!!onchain) return [3 /*break*/, 5];
521
556
  // eslint-disable-next-line no-await-in-loop
522
557
  return [4 /*yield*/, wait(retryInterval)];
523
- case 2:
558
+ case 3:
524
559
  // eslint-disable-next-line no-await-in-loop
525
560
  _a.sent();
526
561
  return [4 /*yield*/, this.getTransactionStatus(txHash)];
527
- case 3:
562
+ case 4:
528
563
  res = _a.sent();
529
- if (
530
- res.tx_status === 'ACCEPTED_ONCHAIN' ||
531
- (res.tx_status === 'PENDING' && res.block_hash !== 'pending') // This is needed as of today. In the future there will be a different status for pending transactions.
532
- ) {
564
+ if (res.tx_status === 'ACCEPTED_ON_L1' || res.tx_status === 'ACCEPTED_ON_L2') {
533
565
  onchain = true;
534
- } else if (res.tx_status === 'REJECTED') {
535
- throw Error('REJECTED');
536
- } else if (res.tx_status === 'NOT_RECEIVED') {
537
- throw Error('NOT_RECEIVED');
566
+ } else if (res.tx_status === 'REJECTED' || res.tx_status === 'NOT_RECEIVED') {
567
+ error = Error(res.tx_status);
568
+ error.response = res;
569
+ throw error;
538
570
  }
539
- return [3 /*break*/, 1];
540
- case 4:
571
+ return [3 /*break*/, 2];
572
+ case 5:
541
573
  return [2 /*return*/];
542
574
  }
543
575
  });
@@ -1,5 +1,6 @@
1
1
  import type {
2
2
  AddTransactionResponse,
3
+ BlockNumber,
3
4
  CallContractResponse,
4
5
  CallContractTransaction,
5
6
  CompiledContract,
@@ -8,6 +9,7 @@ import type {
8
9
  GetContractAddressesResponse,
9
10
  GetTransactionResponse,
10
11
  GetTransactionStatusResponse,
12
+ Signature,
11
13
  Transaction,
12
14
  } from '../types';
13
15
  import type { BigNumberish } from '../utils/number';
@@ -25,53 +27,67 @@ export declare abstract class ProviderInterface {
25
27
  /**
26
28
  * Calls a function on the StarkNet contract.
27
29
  *
28
- * [Reference](https://github.com/starkware-libs/cairo-lang/blob/f464ec4797361b6be8989e36e02ec690e74ef285/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L17-L25)
30
+ * [Reference](https://github.com/starkware-libs/cairo-lang/blob/fc97bdd8322a7df043c87c371634b26c15ed6cee/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L25-L39)
29
31
  *
30
- * @param invokeTx - transaction to be invoked
31
- * @param blockId
32
+ * @param invokeTransaction - transaction to be invoked
33
+ * @param blockHash
34
+ * @param blockNumber
32
35
  * @returns the result of the function on the smart contract.
33
36
  */
34
37
  abstract callContract(
35
- invokeTx: CallContractTransaction,
36
- blockId?: number
38
+ invokeTransaction: CallContractTransaction,
39
+ blockHash?: BigNumberish,
40
+ blockNumber?: BlockNumber
37
41
  ): Promise<CallContractResponse>;
38
42
  /**
39
- * Gets the block information from a block ID.
43
+ * Gets the block information
40
44
  *
41
- * [Reference](https://github.com/starkware-libs/cairo-lang/blob/f464ec4797361b6be8989e36e02ec690e74ef285/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L27-L31)
45
+ * [Reference](https://github.com/starkware-libs/cairo-lang/blob/fc97bdd8322a7df043c87c371634b26c15ed6cee/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L41-L53)
42
46
  *
43
- * @param blockId
44
- * @returns the block object { block_id, previous_block_id, state_root, status, timestamp, transaction_receipts, transactions }
47
+ * @param blockHash
48
+ * @param blockNumber
49
+ * @returns the block object { block_number, previous_block_number, state_root, status, timestamp, transaction_receipts, transactions }
45
50
  */
46
- abstract getBlock(blockId?: number): Promise<GetBlockResponse>;
51
+ abstract getBlock(blockHash?: BigNumberish, blockNumber?: BlockNumber): Promise<GetBlockResponse>;
47
52
  /**
48
53
  * Gets the code of the deployed contract.
49
54
  *
50
- * [Reference](https://github.com/starkware-libs/cairo-lang/blob/f464ec4797361b6be8989e36e02ec690e74ef285/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L33-L36)
55
+ * [Reference](https://github.com/starkware-libs/cairo-lang/blob/fc97bdd8322a7df043c87c371634b26c15ed6cee/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L55-L68)
51
56
  *
52
57
  * @param contractAddress
53
- * @param blockId
58
+ * @param blockHash
59
+ * @param blockNumber
54
60
  * @returns Bytecode and ABI of compiled contract
55
61
  */
56
- abstract getCode(contractAddress: string, blockId?: number): Promise<GetCodeResponse>;
62
+ abstract getCode(
63
+ contractAddress: string,
64
+ blockHash?: BigNumberish,
65
+ blockNumber?: BlockNumber
66
+ ): Promise<GetCodeResponse>;
57
67
  /**
58
68
  * Gets the contract's storage variable at a specific key.
59
69
  *
60
- * [Reference](https://github.com/starkware-libs/cairo-lang/blob/f464ec4797361b6be8989e36e02ec690e74ef285/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L38-L46)
70
+ * [Reference](https://github.com/starkware-libs/cairo-lang/blob/fc97bdd8322a7df043c87c371634b26c15ed6cee/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L70-L85)
61
71
  *
62
72
  * @param contractAddress
63
73
  * @param key - from getStorageVarAddress('<STORAGE_VARIABLE_NAME>') (WIP)
64
- * @param blockId
74
+ * @param blockHash
75
+ * @param blockNumber
65
76
  * @returns the value of the storage variable
66
77
  */
67
- abstract getStorageAt(contractAddress: string, key: number, blockId?: number): Promise<object>;
78
+ abstract getStorageAt(
79
+ contractAddress: string,
80
+ key: number,
81
+ blockHash?: BigNumberish,
82
+ blockNumber?: BlockNumber
83
+ ): Promise<object>;
68
84
  /**
69
85
  * Gets the status of a transaction.
70
86
  *
71
87
  * [Reference](https://github.com/starkware-libs/cairo-lang/blob/f464ec4797361b6be8989e36e02ec690e74ef285/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L48-L52)
72
88
  *
73
89
  * @param txHash
74
- * @returns the transaction status object { block_id, tx_status: NOT_RECEIVED | RECEIVED | PENDING | REJECTED | ACCEPTED_ONCHAIN }
90
+ * @returns the transaction status object { block_number, tx_status: NOT_RECEIVED | RECEIVED | PENDING | REJECTED | ACCEPTED_ONCHAIN }
75
91
  */
76
92
  abstract getTransactionStatus(txHash: BigNumberish): Promise<GetTransactionStatusResponse>;
77
93
  /**
@@ -80,7 +96,7 @@ export declare abstract class ProviderInterface {
80
96
  * [Reference](https://github.com/starkware-libs/cairo-lang/blob/f464ec4797361b6be8989e36e02ec690e74ef285/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L54-L58)
81
97
  *
82
98
  * @param txHash
83
- * @returns the transacton object { transaction_id, status, transaction, block_id?, block_number?, transaction_index?, transaction_failure_reason? }
99
+ * @returns the transacton object { transaction_id, status, transaction, block_number?, block_number?, transaction_index?, transaction_failure_reason? }
84
100
  */
85
101
  abstract getTransaction(txHash: BigNumberish): Promise<GetTransactionResponse>;
86
102
  /**
@@ -88,10 +104,10 @@ export declare abstract class ProviderInterface {
88
104
  *
89
105
  * [Reference](https://github.com/starkware-libs/cairo-lang/blob/f464ec4797361b6be8989e36e02ec690e74ef285/src/starkware/starknet/services/api/gateway/gateway_client.py#L13-L17)
90
106
  *
91
- * @param tx - transaction to be invoked
107
+ * @param transaction - transaction to be invoked
92
108
  * @returns a confirmation of invoking a function on the starknet contract
93
109
  */
94
- abstract addTransaction(tx: Transaction): Promise<AddTransactionResponse>;
110
+ abstract addTransaction(transaction: Transaction): Promise<AddTransactionResponse>;
95
111
  /**
96
112
  * Deploys a given compiled contract (json) to starknet
97
113
  *
@@ -117,7 +133,7 @@ export declare abstract class ProviderInterface {
117
133
  contractAddress: string,
118
134
  entrypointSelector: string,
119
135
  calldata?: string[],
120
- signature?: [BigNumberish, BigNumberish]
136
+ signature?: Signature
121
137
  ): Promise<AddTransactionResponse>;
122
138
  abstract waitForTx(txHash: BigNumberish, retryInterval?: number): Promise<void>;
123
139
  }
@@ -0,0 +1,30 @@
1
+ import type { BlockNumber } from '../types';
2
+ import { BigNumberish } from '../utils/number';
3
+ /**
4
+ * TODO
5
+ * [Reference](https://github.com/starkware-libs/cairo-lang/blob/fc97bdd8322a7df043c87c371634b26c15ed6cee/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L148-L153)
6
+ *
7
+ * @param hashValue
8
+ * @param hashField
9
+ */
10
+ export declare function formatHash(): void;
11
+ /**
12
+ * TODO
13
+ * [Reference](https://github.com/starkware-libs/cairo-lang/blob/fc97bdd8322a7df043c87c371634b26c15ed6cee/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L156-L161)
14
+ * @param txHash
15
+ * @param txId
16
+ */
17
+ export declare function txIdentifier(): void;
18
+ /**
19
+ * Gets the block identifier for API request
20
+ *
21
+ * [Reference](https://github.com/starkware-libs/cairo-lang/blob/fc97bdd8322a7df043c87c371634b26c15ed6cee/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L164-L173)
22
+ *
23
+ * @param blockNumber
24
+ * @param blockHash
25
+ * @returns block identifier for API request
26
+ */
27
+ export declare function getFormattedBlockIdentifier(
28
+ blockHash?: BigNumberish,
29
+ blockNumber?: BlockNumber
30
+ ): string;
@@ -0,0 +1,39 @@
1
+ 'use strict';
2
+ Object.defineProperty(exports, '__esModule', { value: true });
3
+ exports.getFormattedBlockIdentifier = exports.txIdentifier = exports.formatHash = void 0;
4
+ /**
5
+ * TODO
6
+ * [Reference](https://github.com/starkware-libs/cairo-lang/blob/fc97bdd8322a7df043c87c371634b26c15ed6cee/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L148-L153)
7
+ *
8
+ * @param hashValue
9
+ * @param hashField
10
+ */
11
+ function formatHash() {}
12
+ exports.formatHash = formatHash;
13
+ /**
14
+ * TODO
15
+ * [Reference](https://github.com/starkware-libs/cairo-lang/blob/fc97bdd8322a7df043c87c371634b26c15ed6cee/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L156-L161)
16
+ * @param txHash
17
+ * @param txId
18
+ */
19
+ function txIdentifier() {}
20
+ exports.txIdentifier = txIdentifier;
21
+ /**
22
+ * Gets the block identifier for API request
23
+ *
24
+ * [Reference](https://github.com/starkware-libs/cairo-lang/blob/fc97bdd8322a7df043c87c371634b26c15ed6cee/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L164-L173)
25
+ *
26
+ * @param blockNumber
27
+ * @param blockHash
28
+ * @returns block identifier for API request
29
+ */
30
+ function getFormattedBlockIdentifier(blockHash, blockNumber) {
31
+ if (blockNumber === void 0) {
32
+ blockNumber = null;
33
+ }
34
+ if (blockHash) {
35
+ return '?blockHash=' + blockHash;
36
+ }
37
+ return '?blockNumber=' + blockNumber;
38
+ }
39
+ exports.getFormattedBlockIdentifier = getFormattedBlockIdentifier;