starknet 2.6.0 → 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.
package/CHANGELOG.md CHANGED
@@ -1,3 +1,13 @@
1
+ # [2.7.0](https://github.com/seanjameshan/starknet.js/compare/v2.6.0...v2.7.0) (2022-01-03)
2
+
3
+ ### Bug Fixes
4
+
5
+ - add response to the waitForTx error ([e25bdfd](https://github.com/seanjameshan/starknet.js/commit/e25bdfd428fd36e105ed272ea39462845bae5805))
6
+
7
+ ### Features
8
+
9
+ - **blockHash:** add blockHash and fix test cases ([4e107eb](https://github.com/seanjameshan/starknet.js/commit/4e107eb7e97a9b8d2efd74b2074a7d82365c932e))
10
+
1
11
  # [2.6.0](https://github.com/seanjameshan/starknet.js/compare/v2.5.0...v2.6.0) (2021-12-29)
2
12
 
3
13
  ### Bug Fixes
@@ -13,38 +13,49 @@ describe('defaultProvider', () => {
13
13
  expect(typeof GpsStatementVerifier).toBe('string');
14
14
  expect(typeof Starknet).toBe('string');
15
15
  });
16
- test('getBlock()', () => {
17
- return expect(defaultProvider.getBlock(870)).resolves.not.toThrow();
16
+ test('getBlock(blockHash=0x3bca19c3d5983e21e9537669b15f951f0664f0747a083dc714e0b9648b8575d, blockNumber=undefined)', () => {
17
+ return expect(
18
+ defaultProvider.getBlock(
19
+ '0x3bca19c3d5983e21e9537669b15f951f0664f0747a083dc714e0b9648b8575d'
20
+ )
21
+ ).resolves.not.toThrow();
18
22
  });
19
- test('getBlock(blockNumber=null)', () => {
23
+ test('getBlock(blockHash=undefined, blockNumber=36657)', () => {
24
+ return expect(defaultProvider.getBlock(undefined, 36657)).resolves.not.toThrow();
25
+ });
26
+ test('getBlock(blockHash=undefined, blockNumber=null)', () => {
20
27
  return expect(defaultProvider.getBlock()).resolves.not.toThrow();
21
28
  });
22
29
  test('getCode()', () => {
23
30
  return expect(
24
31
  defaultProvider.getCode(
25
- '0x163a1542a64402ffc93e39a4962eec51ce126f2e634631d3f1f6770a76e3a61',
26
- 870
32
+ '0x01d1f307c073bb786a66e6e042ec2a9bdc385a3373bb3738d95b966d5ce56166',
33
+ undefined,
34
+ 36663
27
35
  )
28
36
  ).resolves.not.toThrow();
29
37
  });
30
- test('getCode(blockNumber=null)', () => {
38
+ test('getCode(blockHash=undefined, blockNumber=null)', () => {
31
39
  return expect(
32
- defaultProvider.getCode('0x163a1542a64402ffc93e39a4962eec51ce126f2e634631d3f1f6770a76e3a61')
40
+ defaultProvider.getCode(
41
+ '0x01d1f307c073bb786a66e6e042ec2a9bdc385a3373bb3738d95b966d5ce56166'
42
+ )
33
43
  ).resolves.not.toThrow();
34
44
  });
35
45
  test('getStorageAt()', () => {
36
46
  return expect(
37
47
  defaultProvider.getStorageAt(
38
- '0x163a1542a64402ffc93e39a4962eec51ce126f2e634631d3f1f6770a76e3a61',
48
+ '0x01d1f307c073bb786a66e6e042ec2a9bdc385a3373bb3738d95b966d5ce56166',
39
49
  0,
40
- 870
50
+ undefined,
51
+ 36663
41
52
  )
42
53
  ).resolves.not.toThrow();
43
54
  });
44
- test('getStorageAt(blockNumber=null)', () => {
55
+ test('getStorageAt(blockHash=undefined, blockNumber=null)', () => {
45
56
  return expect(
46
57
  defaultProvider.getStorageAt(
47
- '0x163a1542a64402ffc93e39a4962eec51ce126f2e634631d3f1f6770a76e3a61',
58
+ '0x01d1f307c073bb786a66e6e042ec2a9bdc385a3373bb3738d95b966d5ce56166',
48
59
  0
49
60
  )
50
61
  ).resolves.not.toThrow();
@@ -52,14 +63,14 @@ describe('defaultProvider', () => {
52
63
  test('getTransactionStatus()', async () => {
53
64
  return expect(
54
65
  defaultProvider.getTransactionStatus(
55
- '0x72add9621ecdcb07405a4f943fe410bf57003ca250400f01ce70f8a6fc72147'
66
+ '0x37013e1cb9c133e6fe51b4b371b76b317a480f56d80576730754c1662582348'
56
67
  )
57
68
  ).resolves.not.toThrow();
58
69
  });
59
70
  test('getTransaction()', async () => {
60
71
  return expect(
61
72
  defaultProvider.getTransaction(
62
- '0x72add9621ecdcb07405a4f943fe410bf57003ca250400f01ce70f8a6fc72147'
73
+ '0x37013e1cb9c133e6fe51b4b371b76b317a480f56d80576730754c1662582348'
63
74
  )
64
75
  ).resolves.not.toThrow();
65
76
  });
@@ -23,43 +23,47 @@ export declare class Provider implements ProviderInterface {
23
23
  /**
24
24
  * Calls a function on the StarkNet contract.
25
25
  *
26
- * [Reference](https://github.com/starkware-libs/cairo-lang/blob/f464ec4797361b6be8989e36e02ec690e74ef285/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L17-L25)
26
+ * [Reference](https://github.com/starkware-libs/cairo-lang/blob/fc97bdd8322a7df043c87c371634b26c15ed6cee/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L25-L39)
27
27
  *
28
28
  * @param invokeTransaction - transaction to be invoked
29
+ * @param blockHash
29
30
  * @param blockNumber
30
31
  * @returns the result of the function on the smart contract.
31
32
  */
32
- callContract(invokeTransaction: CallContractTransaction, blockNumber?: BlockNumber): Promise<CallContractResponse>;
33
+ callContract(invokeTransaction: CallContractTransaction, blockHash?: BigNumberish, blockNumber?: BlockNumber): Promise<CallContractResponse>;
33
34
  /**
34
- * Gets the block information from a block ID.
35
+ * Gets the block information
35
36
  *
36
- * [Reference](https://github.com/starkware-libs/cairo-lang/blob/f464ec4797361b6be8989e36e02ec690e74ef285/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L27-L31)
37
+ * [Reference](https://github.com/starkware-libs/cairo-lang/blob/fc97bdd8322a7df043c87c371634b26c15ed6cee/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L41-L53)
37
38
  *
39
+ * @param blockHash
38
40
  * @param blockNumber
39
41
  * @returns the block object { block_number, previous_block_number, state_root, status, timestamp, transaction_receipts, transactions }
40
42
  */
41
- getBlock(blockNumber?: BlockNumber): Promise<GetBlockResponse>;
43
+ getBlock(blockHash?: BigNumberish, blockNumber?: BlockNumber): Promise<GetBlockResponse>;
42
44
  /**
43
45
  * Gets the code of the deployed contract.
44
46
  *
45
- * [Reference](https://github.com/starkware-libs/cairo-lang/blob/f464ec4797361b6be8989e36e02ec690e74ef285/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L33-L36)
47
+ * [Reference](https://github.com/starkware-libs/cairo-lang/blob/fc97bdd8322a7df043c87c371634b26c15ed6cee/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L55-L68)
46
48
  *
47
49
  * @param contractAddress
50
+ * @param blockHash
48
51
  * @param blockNumber
49
52
  * @returns Bytecode and ABI of compiled contract
50
53
  */
51
- getCode(contractAddress: string, blockNumber?: BlockNumber): Promise<GetCodeResponse>;
54
+ getCode(contractAddress: string, blockHash?: BigNumberish, blockNumber?: BlockNumber): Promise<GetCodeResponse>;
52
55
  /**
53
56
  * Gets the contract's storage variable at a specific key.
54
57
  *
55
- * [Reference](https://github.com/starkware-libs/cairo-lang/blob/f464ec4797361b6be8989e36e02ec690e74ef285/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L38-L46)
58
+ * [Reference](https://github.com/starkware-libs/cairo-lang/blob/fc97bdd8322a7df043c87c371634b26c15ed6cee/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L70-L85)
56
59
  *
57
60
  * @param contractAddress
58
61
  * @param key - from getStorageVarAddress('<STORAGE_VARIABLE_NAME>') (WIP)
62
+ * @param blockHash
59
63
  * @param blockNumber
60
64
  * @returns the value of the storage variable
61
65
  */
62
- getStorageAt(contractAddress: string, key: number, blockNumber?: BlockNumber): Promise<object>;
66
+ getStorageAt(contractAddress: string, key: number, blockHash?: BigNumberish, blockNumber?: BlockNumber): Promise<object>;
63
67
  /**
64
68
  * Gets the status of a transaction.
65
69
  *
@@ -56,6 +56,7 @@ var url_join_1 = __importDefault(require("url-join"));
56
56
  var json_1 = require("../utils/json");
57
57
  var number_1 = require("../utils/number");
58
58
  var stark_1 = require("../utils/stark");
59
+ var utils_1 = require("./utils");
59
60
  function wait(delay) {
60
61
  return new Promise(function (res) { return setTimeout(res, delay); });
61
62
  }
@@ -107,19 +108,22 @@ var Provider = /** @class */ (function () {
107
108
  /**
108
109
  * Calls a function on the StarkNet contract.
109
110
  *
110
- * [Reference](https://github.com/starkware-libs/cairo-lang/blob/f464ec4797361b6be8989e36e02ec690e74ef285/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L17-L25)
111
+ * [Reference](https://github.com/starkware-libs/cairo-lang/blob/fc97bdd8322a7df043c87c371634b26c15ed6cee/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L25-L39)
111
112
  *
112
113
  * @param invokeTransaction - transaction to be invoked
114
+ * @param blockHash
113
115
  * @param blockNumber
114
116
  * @returns the result of the function on the smart contract.
115
117
  */
116
- Provider.prototype.callContract = function (invokeTransaction, blockNumber) {
118
+ Provider.prototype.callContract = function (invokeTransaction, blockHash, blockNumber) {
117
119
  if (blockNumber === void 0) { blockNumber = null; }
118
120
  return __awaiter(this, void 0, void 0, function () {
119
- var data;
121
+ var formattedBlockIdentifier, data;
120
122
  return __generator(this, function (_a) {
121
123
  switch (_a.label) {
122
- case 0: return [4 /*yield*/, axios_1.default.post((0, url_join_1.default)(this.feederGatewayUrl, 'call_contract', "?blockNumber=" + blockNumber), __assign({ signature: [], calldata: [] }, invokeTransaction))];
124
+ case 0:
125
+ formattedBlockIdentifier = (0, utils_1.getFormattedBlockIdentifier)(blockHash, blockNumber);
126
+ return [4 /*yield*/, axios_1.default.post((0, url_join_1.default)(this.feederGatewayUrl, 'call_contract', formattedBlockIdentifier), __assign({ signature: [], calldata: [] }, invokeTransaction))];
123
127
  case 1:
124
128
  data = (_a.sent()).data;
125
129
  return [2 /*return*/, data];
@@ -128,20 +132,23 @@ var Provider = /** @class */ (function () {
128
132
  });
129
133
  };
130
134
  /**
131
- * Gets the block information from a block ID.
135
+ * Gets the block information
132
136
  *
133
- * [Reference](https://github.com/starkware-libs/cairo-lang/blob/f464ec4797361b6be8989e36e02ec690e74ef285/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L27-L31)
137
+ * [Reference](https://github.com/starkware-libs/cairo-lang/blob/fc97bdd8322a7df043c87c371634b26c15ed6cee/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L41-L53)
134
138
  *
139
+ * @param blockHash
135
140
  * @param blockNumber
136
141
  * @returns the block object { block_number, previous_block_number, state_root, status, timestamp, transaction_receipts, transactions }
137
142
  */
138
- Provider.prototype.getBlock = function (blockNumber) {
143
+ Provider.prototype.getBlock = function (blockHash, blockNumber) {
139
144
  if (blockNumber === void 0) { blockNumber = null; }
140
145
  return __awaiter(this, void 0, void 0, function () {
141
- var data;
146
+ var formattedBlockIdentifier, data;
142
147
  return __generator(this, function (_a) {
143
148
  switch (_a.label) {
144
- case 0: return [4 /*yield*/, axios_1.default.get((0, url_join_1.default)(this.feederGatewayUrl, 'get_block', "?blockNumber=" + blockNumber))];
149
+ case 0:
150
+ formattedBlockIdentifier = (0, utils_1.getFormattedBlockIdentifier)(blockHash, blockNumber);
151
+ return [4 /*yield*/, axios_1.default.get((0, url_join_1.default)(this.feederGatewayUrl, 'get_block', formattedBlockIdentifier))];
145
152
  case 1:
146
153
  data = (_a.sent()).data;
147
154
  return [2 /*return*/, data];
@@ -152,19 +159,22 @@ var Provider = /** @class */ (function () {
152
159
  /**
153
160
  * Gets the code of the deployed contract.
154
161
  *
155
- * [Reference](https://github.com/starkware-libs/cairo-lang/blob/f464ec4797361b6be8989e36e02ec690e74ef285/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L33-L36)
162
+ * [Reference](https://github.com/starkware-libs/cairo-lang/blob/fc97bdd8322a7df043c87c371634b26c15ed6cee/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L55-L68)
156
163
  *
157
164
  * @param contractAddress
165
+ * @param blockHash
158
166
  * @param blockNumber
159
167
  * @returns Bytecode and ABI of compiled contract
160
168
  */
161
- Provider.prototype.getCode = function (contractAddress, blockNumber) {
169
+ Provider.prototype.getCode = function (contractAddress, blockHash, blockNumber) {
162
170
  if (blockNumber === void 0) { blockNumber = null; }
163
171
  return __awaiter(this, void 0, void 0, function () {
164
- var data;
172
+ var formattedBlockIdentifier, data;
165
173
  return __generator(this, function (_a) {
166
174
  switch (_a.label) {
167
- case 0: return [4 /*yield*/, axios_1.default.get((0, url_join_1.default)(this.feederGatewayUrl, 'get_code', "?contractAddress=" + contractAddress + "&blockNumber=" + blockNumber))];
175
+ case 0:
176
+ formattedBlockIdentifier = (0, utils_1.getFormattedBlockIdentifier)(blockHash, blockNumber);
177
+ return [4 /*yield*/, axios_1.default.get((0, url_join_1.default)(this.feederGatewayUrl, 'get_code', "?contractAddress=" + contractAddress + "&" + formattedBlockIdentifier))];
168
178
  case 1:
169
179
  data = (_a.sent()).data;
170
180
  return [2 /*return*/, data];
@@ -176,20 +186,23 @@ var Provider = /** @class */ (function () {
176
186
  /**
177
187
  * Gets the contract's storage variable at a specific key.
178
188
  *
179
- * [Reference](https://github.com/starkware-libs/cairo-lang/blob/f464ec4797361b6be8989e36e02ec690e74ef285/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L38-L46)
189
+ * [Reference](https://github.com/starkware-libs/cairo-lang/blob/fc97bdd8322a7df043c87c371634b26c15ed6cee/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L70-L85)
180
190
  *
181
191
  * @param contractAddress
182
192
  * @param key - from getStorageVarAddress('<STORAGE_VARIABLE_NAME>') (WIP)
193
+ * @param blockHash
183
194
  * @param blockNumber
184
195
  * @returns the value of the storage variable
185
196
  */
186
- Provider.prototype.getStorageAt = function (contractAddress, key, blockNumber) {
197
+ Provider.prototype.getStorageAt = function (contractAddress, key, blockHash, blockNumber) {
187
198
  if (blockNumber === void 0) { blockNumber = null; }
188
199
  return __awaiter(this, void 0, void 0, function () {
189
- var data;
200
+ var formattedBlockIdentifier, data;
190
201
  return __generator(this, function (_a) {
191
202
  switch (_a.label) {
192
- case 0: return [4 /*yield*/, axios_1.default.get((0, url_join_1.default)(this.feederGatewayUrl, 'get_storage_at', "?contractAddress=" + contractAddress + "&key=" + key + "&blockNumber=" + blockNumber))];
203
+ case 0:
204
+ formattedBlockIdentifier = (0, utils_1.getFormattedBlockIdentifier)(blockHash, blockNumber);
205
+ return [4 /*yield*/, axios_1.default.get((0, url_join_1.default)(this.feederGatewayUrl, 'get_storage_at', "?contractAddress=" + contractAddress + "&key=" + key + "&" + formattedBlockIdentifier))];
193
206
  case 1:
194
207
  data = (_a.sent()).data;
195
208
  return [2 /*return*/, data];
@@ -307,7 +320,7 @@ var Provider = /** @class */ (function () {
307
320
  Provider.prototype.waitForTx = function (txHash, retryInterval) {
308
321
  if (retryInterval === void 0) { retryInterval = 8000; }
309
322
  return __awaiter(this, void 0, void 0, function () {
310
- var onchain, res;
323
+ var onchain, res, error;
311
324
  return __generator(this, function (_a) {
312
325
  switch (_a.label) {
313
326
  case 0:
@@ -329,11 +342,10 @@ var Provider = /** @class */ (function () {
329
342
  if (res.tx_status === 'ACCEPTED_ON_L1' || res.tx_status === 'ACCEPTED_ON_L2') {
330
343
  onchain = true;
331
344
  }
332
- else if (res.tx_status === 'REJECTED') {
333
- throw Error('REJECTED');
334
- }
335
- else if (res.tx_status === 'NOT_RECEIVED') {
336
- throw Error('NOT_RECEIVED');
345
+ else if (res.tx_status === 'REJECTED' || res.tx_status === 'NOT_RECEIVED') {
346
+ error = Error(res.tx_status);
347
+ error.response = res;
348
+ throw error;
337
349
  }
338
350
  return [3 /*break*/, 2];
339
351
  case 5: return [2 /*return*/];
@@ -14,43 +14,47 @@ export declare abstract class ProviderInterface {
14
14
  /**
15
15
  * Calls a function on the StarkNet contract.
16
16
  *
17
- * [Reference](https://github.com/starkware-libs/cairo-lang/blob/f464ec4797361b6be8989e36e02ec690e74ef285/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L17-L25)
17
+ * [Reference](https://github.com/starkware-libs/cairo-lang/blob/fc97bdd8322a7df043c87c371634b26c15ed6cee/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L25-L39)
18
18
  *
19
19
  * @param invokeTransaction - transaction to be invoked
20
+ * @param blockHash
20
21
  * @param blockNumber
21
22
  * @returns the result of the function on the smart contract.
22
23
  */
23
- abstract callContract(invokeTransaction: CallContractTransaction, blockNumber?: BlockNumber): Promise<CallContractResponse>;
24
+ abstract callContract(invokeTransaction: CallContractTransaction, blockHash?: BigNumberish, blockNumber?: BlockNumber): Promise<CallContractResponse>;
24
25
  /**
25
- * Gets the block information from a block ID.
26
+ * Gets the block information
26
27
  *
27
- * [Reference](https://github.com/starkware-libs/cairo-lang/blob/f464ec4797361b6be8989e36e02ec690e74ef285/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L27-L31)
28
+ * [Reference](https://github.com/starkware-libs/cairo-lang/blob/fc97bdd8322a7df043c87c371634b26c15ed6cee/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L41-L53)
28
29
  *
30
+ * @param blockHash
29
31
  * @param blockNumber
30
32
  * @returns the block object { block_number, previous_block_number, state_root, status, timestamp, transaction_receipts, transactions }
31
33
  */
32
- abstract getBlock(blockNumber?: BlockNumber): Promise<GetBlockResponse>;
34
+ abstract getBlock(blockHash?: BigNumberish, blockNumber?: BlockNumber): Promise<GetBlockResponse>;
33
35
  /**
34
36
  * Gets the code of the deployed contract.
35
37
  *
36
- * [Reference](https://github.com/starkware-libs/cairo-lang/blob/f464ec4797361b6be8989e36e02ec690e74ef285/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L33-L36)
38
+ * [Reference](https://github.com/starkware-libs/cairo-lang/blob/fc97bdd8322a7df043c87c371634b26c15ed6cee/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L55-L68)
37
39
  *
38
40
  * @param contractAddress
41
+ * @param blockHash
39
42
  * @param blockNumber
40
43
  * @returns Bytecode and ABI of compiled contract
41
44
  */
42
- abstract getCode(contractAddress: string, blockNumber?: BlockNumber): Promise<GetCodeResponse>;
45
+ abstract getCode(contractAddress: string, blockHash?: BigNumberish, blockNumber?: BlockNumber): Promise<GetCodeResponse>;
43
46
  /**
44
47
  * Gets the contract's storage variable at a specific key.
45
48
  *
46
- * [Reference](https://github.com/starkware-libs/cairo-lang/blob/f464ec4797361b6be8989e36e02ec690e74ef285/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L38-L46)
49
+ * [Reference](https://github.com/starkware-libs/cairo-lang/blob/fc97bdd8322a7df043c87c371634b26c15ed6cee/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L70-L85)
47
50
  *
48
51
  * @param contractAddress
49
52
  * @param key - from getStorageVarAddress('<STORAGE_VARIABLE_NAME>') (WIP)
53
+ * @param blockHash
50
54
  * @param blockNumber
51
55
  * @returns the value of the storage variable
52
56
  */
53
- abstract getStorageAt(contractAddress: string, key: number, blockNumber?: BlockNumber): Promise<object>;
57
+ abstract getStorageAt(contractAddress: string, key: number, blockHash?: BigNumberish, blockNumber?: BlockNumber): Promise<object>;
54
58
  /**
55
59
  * Gets the status of a transaction.
56
60
  *
@@ -0,0 +1,27 @@
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(blockHash?: BigNumberish, blockNumber?: BlockNumber): string;
@@ -0,0 +1,37 @@
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) { blockNumber = null; }
32
+ if (blockHash) {
33
+ return "?blockHash=" + blockHash;
34
+ }
35
+ return "?blockNumber=" + blockNumber;
36
+ }
37
+ exports.getFormattedBlockIdentifier = getFormattedBlockIdentifier;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "starknet",
3
- "version": "2.6.0",
3
+ "version": "2.7.0",
4
4
  "description": "JavaScript library for StarkNet",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -40,46 +40,60 @@ export declare class Provider implements ProviderInterface {
40
40
  /**
41
41
  * Calls a function on the StarkNet contract.
42
42
  *
43
- * [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)
44
44
  *
45
45
  * @param invokeTransaction - transaction to be invoked
46
+ * @param blockHash
46
47
  * @param blockNumber
47
48
  * @returns the result of the function on the smart contract.
48
49
  */
49
50
  callContract(
50
51
  invokeTransaction: CallContractTransaction,
52
+ blockHash?: BigNumberish,
51
53
  blockNumber?: BlockNumber
52
54
  ): Promise<CallContractResponse>;
53
55
  /**
54
- * Gets the block information from a block ID.
56
+ * Gets the block information
55
57
  *
56
- * [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)
57
59
  *
60
+ * @param blockHash
58
61
  * @param blockNumber
59
62
  * @returns the block object { block_number, previous_block_number, state_root, status, timestamp, transaction_receipts, transactions }
60
63
  */
61
- getBlock(blockNumber?: BlockNumber): Promise<GetBlockResponse>;
64
+ getBlock(blockHash?: BigNumberish, blockNumber?: BlockNumber): Promise<GetBlockResponse>;
62
65
  /**
63
66
  * Gets the code of the deployed contract.
64
67
  *
65
- * [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)
66
69
  *
67
70
  * @param contractAddress
71
+ * @param blockHash
68
72
  * @param blockNumber
69
73
  * @returns Bytecode and ABI of compiled contract
70
74
  */
71
- getCode(contractAddress: string, blockNumber?: BlockNumber): Promise<GetCodeResponse>;
75
+ getCode(
76
+ contractAddress: string,
77
+ blockHash?: BigNumberish,
78
+ blockNumber?: BlockNumber
79
+ ): Promise<GetCodeResponse>;
72
80
  /**
73
81
  * Gets the contract's storage variable at a specific key.
74
82
  *
75
- * [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)
76
84
  *
77
85
  * @param contractAddress
78
86
  * @param key - from getStorageVarAddress('<STORAGE_VARIABLE_NAME>') (WIP)
87
+ * @param blockHash
79
88
  * @param blockNumber
80
89
  * @returns the value of the storage variable
81
90
  */
82
- getStorageAt(contractAddress: string, key: number, blockNumber?: BlockNumber): Promise<object>;
91
+ getStorageAt(
92
+ contractAddress: string,
93
+ key: number,
94
+ blockHash?: BigNumberish,
95
+ blockNumber?: BlockNumber
96
+ ): Promise<object>;
83
97
  /**
84
98
  * Gets the status of a transaction.
85
99
  *
@@ -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);
@@ -217,28 +218,33 @@ 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
223
  * @param invokeTransaction - transaction to be invoked
224
+ * @param blockHash
223
225
  * @param blockNumber
224
226
  * @returns the result of the function on the smart contract.
225
227
  */
226
- Provider.prototype.callContract = function (invokeTransaction, blockNumber) {
228
+ Provider.prototype.callContract = function (invokeTransaction, blockHash, blockNumber) {
227
229
  if (blockNumber === void 0) {
228
230
  blockNumber = null;
229
231
  }
230
232
  return __awaiter(this, void 0, void 0, function () {
231
- var data;
233
+ var formattedBlockIdentifier, data;
232
234
  return __generator(this, function (_a) {
233
235
  switch (_a.label) {
234
236
  case 0:
237
+ formattedBlockIdentifier = (0, utils_1.getFormattedBlockIdentifier)(
238
+ blockHash,
239
+ blockNumber
240
+ );
235
241
  return [
236
242
  4 /*yield*/,
237
243
  axios_1.default.post(
238
244
  (0, url_join_1.default)(
239
245
  this.feederGatewayUrl,
240
246
  'call_contract',
241
- '?blockNumber=' + blockNumber
247
+ formattedBlockIdentifier
242
248
  ),
243
249
  __assign({ signature: [], calldata: [] }, invokeTransaction)
244
250
  ),
@@ -251,29 +257,34 @@ var Provider = /** @class */ (function () {
251
257
  });
252
258
  };
253
259
  /**
254
- * Gets the block information from a block ID.
260
+ * Gets the block information
255
261
  *
256
- * [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)
257
263
  *
264
+ * @param blockHash
258
265
  * @param blockNumber
259
266
  * @returns the block object { block_number, previous_block_number, state_root, status, timestamp, transaction_receipts, transactions }
260
267
  */
261
- Provider.prototype.getBlock = function (blockNumber) {
268
+ Provider.prototype.getBlock = function (blockHash, blockNumber) {
262
269
  if (blockNumber === void 0) {
263
270
  blockNumber = null;
264
271
  }
265
272
  return __awaiter(this, void 0, void 0, function () {
266
- var data;
273
+ var formattedBlockIdentifier, data;
267
274
  return __generator(this, function (_a) {
268
275
  switch (_a.label) {
269
276
  case 0:
277
+ formattedBlockIdentifier = (0, utils_1.getFormattedBlockIdentifier)(
278
+ blockHash,
279
+ blockNumber
280
+ );
270
281
  return [
271
282
  4 /*yield*/,
272
283
  axios_1.default.get(
273
284
  (0, url_join_1.default)(
274
285
  this.feederGatewayUrl,
275
286
  'get_block',
276
- '?blockNumber=' + blockNumber
287
+ formattedBlockIdentifier
277
288
  )
278
289
  ),
279
290
  ];
@@ -287,28 +298,33 @@ var Provider = /** @class */ (function () {
287
298
  /**
288
299
  * Gets the code of the deployed contract.
289
300
  *
290
- * [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)
291
302
  *
292
303
  * @param contractAddress
304
+ * @param blockHash
293
305
  * @param blockNumber
294
306
  * @returns Bytecode and ABI of compiled contract
295
307
  */
296
- Provider.prototype.getCode = function (contractAddress, blockNumber) {
308
+ Provider.prototype.getCode = function (contractAddress, blockHash, blockNumber) {
297
309
  if (blockNumber === void 0) {
298
310
  blockNumber = null;
299
311
  }
300
312
  return __awaiter(this, void 0, void 0, function () {
301
- var data;
313
+ var formattedBlockIdentifier, data;
302
314
  return __generator(this, function (_a) {
303
315
  switch (_a.label) {
304
316
  case 0:
317
+ formattedBlockIdentifier = (0, utils_1.getFormattedBlockIdentifier)(
318
+ blockHash,
319
+ blockNumber
320
+ );
305
321
  return [
306
322
  4 /*yield*/,
307
323
  axios_1.default.get(
308
324
  (0, url_join_1.default)(
309
325
  this.feederGatewayUrl,
310
326
  'get_code',
311
- '?contractAddress=' + contractAddress + '&blockNumber=' + blockNumber
327
+ '?contractAddress=' + contractAddress + '&' + formattedBlockIdentifier
312
328
  )
313
329
  ),
314
330
  ];
@@ -323,22 +339,27 @@ var Provider = /** @class */ (function () {
323
339
  /**
324
340
  * Gets the contract's storage variable at a specific key.
325
341
  *
326
- * [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)
327
343
  *
328
344
  * @param contractAddress
329
345
  * @param key - from getStorageVarAddress('<STORAGE_VARIABLE_NAME>') (WIP)
346
+ * @param blockHash
330
347
  * @param blockNumber
331
348
  * @returns the value of the storage variable
332
349
  */
333
- Provider.prototype.getStorageAt = function (contractAddress, key, blockNumber) {
350
+ Provider.prototype.getStorageAt = function (contractAddress, key, blockHash, blockNumber) {
334
351
  if (blockNumber === void 0) {
335
352
  blockNumber = null;
336
353
  }
337
354
  return __awaiter(this, void 0, void 0, function () {
338
- var data;
355
+ var formattedBlockIdentifier, data;
339
356
  return __generator(this, function (_a) {
340
357
  switch (_a.label) {
341
358
  case 0:
359
+ formattedBlockIdentifier = (0, utils_1.getFormattedBlockIdentifier)(
360
+ blockHash,
361
+ blockNumber
362
+ );
342
363
  return [
343
364
  4 /*yield*/,
344
365
  axios_1.default.get(
@@ -349,8 +370,8 @@ var Provider = /** @class */ (function () {
349
370
  contractAddress +
350
371
  '&key=' +
351
372
  key +
352
- '&blockNumber=' +
353
- blockNumber
373
+ '&' +
374
+ formattedBlockIdentifier
354
375
  )
355
376
  ),
356
377
  ];
@@ -521,7 +542,7 @@ var Provider = /** @class */ (function () {
521
542
  retryInterval = 8000;
522
543
  }
523
544
  return __awaiter(this, void 0, void 0, function () {
524
- var onchain, res;
545
+ var onchain, res, error;
525
546
  return __generator(this, function (_a) {
526
547
  switch (_a.label) {
527
548
  case 0:
@@ -542,10 +563,10 @@ var Provider = /** @class */ (function () {
542
563
  res = _a.sent();
543
564
  if (res.tx_status === 'ACCEPTED_ON_L1' || res.tx_status === 'ACCEPTED_ON_L2') {
544
565
  onchain = true;
545
- } else if (res.tx_status === 'REJECTED') {
546
- throw Error('REJECTED');
547
- } else if (res.tx_status === 'NOT_RECEIVED') {
548
- 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;
549
570
  }
550
571
  return [3 /*break*/, 2];
551
572
  case 5:
@@ -27,48 +27,58 @@ export declare abstract class ProviderInterface {
27
27
  /**
28
28
  * Calls a function on the StarkNet contract.
29
29
  *
30
- * [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)
31
31
  *
32
32
  * @param invokeTransaction - transaction to be invoked
33
+ * @param blockHash
33
34
  * @param blockNumber
34
35
  * @returns the result of the function on the smart contract.
35
36
  */
36
37
  abstract callContract(
37
38
  invokeTransaction: CallContractTransaction,
39
+ blockHash?: BigNumberish,
38
40
  blockNumber?: BlockNumber
39
41
  ): Promise<CallContractResponse>;
40
42
  /**
41
- * Gets the block information from a block ID.
43
+ * Gets the block information
42
44
  *
43
- * [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)
44
46
  *
47
+ * @param blockHash
45
48
  * @param blockNumber
46
49
  * @returns the block object { block_number, previous_block_number, state_root, status, timestamp, transaction_receipts, transactions }
47
50
  */
48
- abstract getBlock(blockNumber?: BlockNumber): Promise<GetBlockResponse>;
51
+ abstract getBlock(blockHash?: BigNumberish, blockNumber?: BlockNumber): Promise<GetBlockResponse>;
49
52
  /**
50
53
  * Gets the code of the deployed contract.
51
54
  *
52
- * [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)
53
56
  *
54
57
  * @param contractAddress
58
+ * @param blockHash
55
59
  * @param blockNumber
56
60
  * @returns Bytecode and ABI of compiled contract
57
61
  */
58
- abstract getCode(contractAddress: string, blockNumber?: BlockNumber): Promise<GetCodeResponse>;
62
+ abstract getCode(
63
+ contractAddress: string,
64
+ blockHash?: BigNumberish,
65
+ blockNumber?: BlockNumber
66
+ ): Promise<GetCodeResponse>;
59
67
  /**
60
68
  * Gets the contract's storage variable at a specific key.
61
69
  *
62
- * [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)
63
71
  *
64
72
  * @param contractAddress
65
73
  * @param key - from getStorageVarAddress('<STORAGE_VARIABLE_NAME>') (WIP)
74
+ * @param blockHash
66
75
  * @param blockNumber
67
76
  * @returns the value of the storage variable
68
77
  */
69
78
  abstract getStorageAt(
70
79
  contractAddress: string,
71
80
  key: number,
81
+ blockHash?: BigNumberish,
72
82
  blockNumber?: BlockNumber
73
83
  ): Promise<object>;
74
84
  /**
@@ -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;
@@ -19,6 +19,7 @@ import { parse, stringify } from '../utils/json';
19
19
  import { BigNumberish, toBN, toHex } from '../utils/number';
20
20
  import { compressProgram, formatSignature, randomAddress } from '../utils/stark';
21
21
  import { ProviderInterface } from './interface';
22
+ import { getFormattedBlockIdentifier } from './utils';
22
23
 
23
24
  type NetworkName = 'mainnet-alpha' | 'goerli-alpha';
24
25
 
@@ -83,18 +84,22 @@ export class Provider implements ProviderInterface {
83
84
  /**
84
85
  * Calls a function on the StarkNet contract.
85
86
  *
86
- * [Reference](https://github.com/starkware-libs/cairo-lang/blob/f464ec4797361b6be8989e36e02ec690e74ef285/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L17-L25)
87
+ * [Reference](https://github.com/starkware-libs/cairo-lang/blob/fc97bdd8322a7df043c87c371634b26c15ed6cee/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L25-L39)
87
88
  *
88
89
  * @param invokeTransaction - transaction to be invoked
90
+ * @param blockHash
89
91
  * @param blockNumber
90
92
  * @returns the result of the function on the smart contract.
91
93
  */
92
94
  public async callContract(
93
95
  invokeTransaction: CallContractTransaction,
96
+ blockHash?: BigNumberish,
94
97
  blockNumber: BlockNumber = null
95
98
  ): Promise<CallContractResponse> {
99
+ const formattedBlockIdentifier = getFormattedBlockIdentifier(blockHash, blockNumber);
100
+
96
101
  const { data } = await axios.post<CallContractResponse>(
97
- urljoin(this.feederGatewayUrl, 'call_contract', `?blockNumber=${blockNumber}`),
102
+ urljoin(this.feederGatewayUrl, 'call_contract', formattedBlockIdentifier),
98
103
  {
99
104
  signature: [],
100
105
  calldata: [],
@@ -105,16 +110,22 @@ export class Provider implements ProviderInterface {
105
110
  }
106
111
 
107
112
  /**
108
- * Gets the block information from a block ID.
113
+ * Gets the block information
109
114
  *
110
- * [Reference](https://github.com/starkware-libs/cairo-lang/blob/f464ec4797361b6be8989e36e02ec690e74ef285/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L27-L31)
115
+ * [Reference](https://github.com/starkware-libs/cairo-lang/blob/fc97bdd8322a7df043c87c371634b26c15ed6cee/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L41-L53)
111
116
  *
117
+ * @param blockHash
112
118
  * @param blockNumber
113
119
  * @returns the block object { block_number, previous_block_number, state_root, status, timestamp, transaction_receipts, transactions }
114
120
  */
115
- public async getBlock(blockNumber: BlockNumber = null): Promise<GetBlockResponse> {
121
+ public async getBlock(
122
+ blockHash?: BigNumberish,
123
+ blockNumber: BlockNumber = null
124
+ ): Promise<GetBlockResponse> {
125
+ const formattedBlockIdentifier = getFormattedBlockIdentifier(blockHash, blockNumber);
126
+
116
127
  const { data } = await axios.get<GetBlockResponse>(
117
- urljoin(this.feederGatewayUrl, 'get_block', `?blockNumber=${blockNumber}`)
128
+ urljoin(this.feederGatewayUrl, 'get_block', formattedBlockIdentifier)
118
129
  );
119
130
  return data;
120
131
  }
@@ -122,21 +133,25 @@ export class Provider implements ProviderInterface {
122
133
  /**
123
134
  * Gets the code of the deployed contract.
124
135
  *
125
- * [Reference](https://github.com/starkware-libs/cairo-lang/blob/f464ec4797361b6be8989e36e02ec690e74ef285/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L33-L36)
136
+ * [Reference](https://github.com/starkware-libs/cairo-lang/blob/fc97bdd8322a7df043c87c371634b26c15ed6cee/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L55-L68)
126
137
  *
127
138
  * @param contractAddress
139
+ * @param blockHash
128
140
  * @param blockNumber
129
141
  * @returns Bytecode and ABI of compiled contract
130
142
  */
131
143
  public async getCode(
132
144
  contractAddress: string,
145
+ blockHash?: BigNumberish,
133
146
  blockNumber: BlockNumber = null
134
147
  ): Promise<GetCodeResponse> {
148
+ const formattedBlockIdentifier = getFormattedBlockIdentifier(blockHash, blockNumber);
149
+
135
150
  const { data } = await axios.get<GetCodeResponse>(
136
151
  urljoin(
137
152
  this.feederGatewayUrl,
138
153
  'get_code',
139
- `?contractAddress=${contractAddress}&blockNumber=${blockNumber}`
154
+ `?contractAddress=${contractAddress}&${formattedBlockIdentifier}`
140
155
  )
141
156
  );
142
157
  return data;
@@ -146,23 +161,27 @@ export class Provider implements ProviderInterface {
146
161
  /**
147
162
  * Gets the contract's storage variable at a specific key.
148
163
  *
149
- * [Reference](https://github.com/starkware-libs/cairo-lang/blob/f464ec4797361b6be8989e36e02ec690e74ef285/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L38-L46)
164
+ * [Reference](https://github.com/starkware-libs/cairo-lang/blob/fc97bdd8322a7df043c87c371634b26c15ed6cee/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L70-L85)
150
165
  *
151
166
  * @param contractAddress
152
167
  * @param key - from getStorageVarAddress('<STORAGE_VARIABLE_NAME>') (WIP)
168
+ * @param blockHash
153
169
  * @param blockNumber
154
170
  * @returns the value of the storage variable
155
171
  */
156
172
  public async getStorageAt(
157
173
  contractAddress: string,
158
174
  key: number,
175
+ blockHash?: BigNumberish,
159
176
  blockNumber: BlockNumber = null
160
177
  ): Promise<object> {
178
+ const formattedBlockIdentifier = getFormattedBlockIdentifier(blockHash, blockNumber);
179
+
161
180
  const { data } = await axios.get<object>(
162
181
  urljoin(
163
182
  this.feederGatewayUrl,
164
183
  'get_storage_at',
165
- `?contractAddress=${contractAddress}&key=${key}&blockNumber=${blockNumber}`
184
+ `?contractAddress=${contractAddress}&key=${key}&${formattedBlockIdentifier}`
166
185
  )
167
186
  );
168
187
  return data;
@@ -293,10 +312,10 @@ export class Provider implements ProviderInterface {
293
312
 
294
313
  if (res.tx_status === 'ACCEPTED_ON_L1' || res.tx_status === 'ACCEPTED_ON_L2') {
295
314
  onchain = true;
296
- } else if (res.tx_status === 'REJECTED') {
297
- throw Error('REJECTED');
298
- } else if (res.tx_status === 'NOT_RECEIVED') {
299
- throw Error('NOT_RECEIVED');
315
+ } else if (res.tx_status === 'REJECTED' || res.tx_status === 'NOT_RECEIVED') {
316
+ const error = Error(res.tx_status) as Error & { response: GetTransactionStatusResponse };
317
+ error.response = res;
318
+ throw error;
300
319
  }
301
320
  }
302
321
  }
@@ -32,38 +32,46 @@ export abstract class ProviderInterface {
32
32
  /**
33
33
  * Calls a function on the StarkNet contract.
34
34
  *
35
- * [Reference](https://github.com/starkware-libs/cairo-lang/blob/f464ec4797361b6be8989e36e02ec690e74ef285/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L17-L25)
35
+ * [Reference](https://github.com/starkware-libs/cairo-lang/blob/fc97bdd8322a7df043c87c371634b26c15ed6cee/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L25-L39)
36
36
  *
37
37
  * @param invokeTransaction - transaction to be invoked
38
+ * @param blockHash
38
39
  * @param blockNumber
39
40
  * @returns the result of the function on the smart contract.
40
41
  */
41
42
  public abstract callContract(
42
43
  invokeTransaction: CallContractTransaction,
44
+ blockHash?: BigNumberish,
43
45
  blockNumber?: BlockNumber
44
46
  ): Promise<CallContractResponse>;
45
47
 
46
48
  /**
47
- * Gets the block information from a block ID.
49
+ * Gets the block information
48
50
  *
49
- * [Reference](https://github.com/starkware-libs/cairo-lang/blob/f464ec4797361b6be8989e36e02ec690e74ef285/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L27-L31)
51
+ * [Reference](https://github.com/starkware-libs/cairo-lang/blob/fc97bdd8322a7df043c87c371634b26c15ed6cee/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L41-L53)
50
52
  *
53
+ * @param blockHash
51
54
  * @param blockNumber
52
55
  * @returns the block object { block_number, previous_block_number, state_root, status, timestamp, transaction_receipts, transactions }
53
56
  */
54
- public abstract getBlock(blockNumber?: BlockNumber): Promise<GetBlockResponse>;
57
+ public abstract getBlock(
58
+ blockHash?: BigNumberish,
59
+ blockNumber?: BlockNumber
60
+ ): Promise<GetBlockResponse>;
55
61
 
56
62
  /**
57
63
  * Gets the code of the deployed contract.
58
64
  *
59
- * [Reference](https://github.com/starkware-libs/cairo-lang/blob/f464ec4797361b6be8989e36e02ec690e74ef285/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L33-L36)
65
+ * [Reference](https://github.com/starkware-libs/cairo-lang/blob/fc97bdd8322a7df043c87c371634b26c15ed6cee/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L55-L68)
60
66
  *
61
67
  * @param contractAddress
68
+ * @param blockHash
62
69
  * @param blockNumber
63
70
  * @returns Bytecode and ABI of compiled contract
64
71
  */
65
72
  public abstract getCode(
66
73
  contractAddress: string,
74
+ blockHash?: BigNumberish,
67
75
  blockNumber?: BlockNumber
68
76
  ): Promise<GetCodeResponse>;
69
77
 
@@ -71,16 +79,18 @@ export abstract class ProviderInterface {
71
79
  /**
72
80
  * Gets the contract's storage variable at a specific key.
73
81
  *
74
- * [Reference](https://github.com/starkware-libs/cairo-lang/blob/f464ec4797361b6be8989e36e02ec690e74ef285/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L38-L46)
82
+ * [Reference](https://github.com/starkware-libs/cairo-lang/blob/fc97bdd8322a7df043c87c371634b26c15ed6cee/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L70-L85)
75
83
  *
76
84
  * @param contractAddress
77
85
  * @param key - from getStorageVarAddress('<STORAGE_VARIABLE_NAME>') (WIP)
86
+ * @param blockHash
78
87
  * @param blockNumber
79
88
  * @returns the value of the storage variable
80
89
  */
81
90
  public abstract getStorageAt(
82
91
  contractAddress: string,
83
92
  key: number,
93
+ blockHash?: BigNumberish,
84
94
  blockNumber?: BlockNumber
85
95
  ): Promise<object>;
86
96
 
@@ -0,0 +1,38 @@
1
+ import type { BlockNumber } from '../types';
2
+ import { BigNumberish } from '../utils/number';
3
+
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
+ export function formatHash() {}
12
+
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
+ export function txIdentifier() {}
20
+
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
+ export function getFormattedBlockIdentifier(
31
+ blockHash?: BigNumberish,
32
+ blockNumber: BlockNumber = null
33
+ ): string {
34
+ if (blockHash) {
35
+ return `?blockHash=${blockHash}`;
36
+ }
37
+ return `?blockNumber=${blockNumber}`;
38
+ }