starknet 3.18.2 → 4.0.1

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 (165) hide show
  1. package/CHANGELOG.md +70 -0
  2. package/README.md +1 -2
  3. package/__tests__/account.test.ts +11 -56
  4. package/__tests__/contract.test.ts +11 -49
  5. package/__tests__/defaultProvider.test.ts +321 -0
  6. package/__tests__/fixtures.ts +32 -11
  7. package/__tests__/jest.setup.ts +2 -3
  8. package/__tests__/rpcProvider.test.ts +17 -0
  9. package/__tests__/sequencerProvider.test.ts +45 -0
  10. package/account/default.d.ts +54 -77
  11. package/account/default.js +271 -596
  12. package/account/index.js +18 -31
  13. package/account/interface.d.ts +66 -95
  14. package/account/interface.js +20 -30
  15. package/constants.d.ts +17 -19
  16. package/constants.js +2038 -2059
  17. package/contract/contractFactory.d.ts +25 -29
  18. package/contract/contractFactory.js +94 -210
  19. package/contract/default.d.ts +117 -146
  20. package/contract/default.js +582 -776
  21. package/contract/index.js +19 -32
  22. package/contract/interface.d.ts +72 -92
  23. package/contract/interface.js +6 -5
  24. package/dist/account/default.d.ts +5 -9
  25. package/dist/account/default.js +35 -169
  26. package/dist/account/interface.d.ts +3 -15
  27. package/dist/contract/contractFactory.js +4 -4
  28. package/dist/contract/default.d.ts +3 -3
  29. package/dist/contract/default.js +3 -2
  30. package/dist/contract/interface.d.ts +2 -2
  31. package/dist/provider/default.d.ts +18 -134
  32. package/dist/provider/default.js +47 -411
  33. package/dist/provider/index.d.ts +2 -0
  34. package/dist/provider/index.js +2 -0
  35. package/dist/provider/interface.d.ts +45 -50
  36. package/dist/provider/rpc.d.ts +57 -0
  37. package/dist/provider/rpc.js +364 -0
  38. package/dist/provider/sequencer.d.ts +66 -0
  39. package/dist/provider/sequencer.js +444 -0
  40. package/dist/types/account.d.ts +2 -3
  41. package/dist/types/api/index.d.ts +16 -0
  42. package/dist/types/api/index.js +18 -0
  43. package/dist/types/api/rpc.d.ts +221 -0
  44. package/dist/types/{api.js → api/rpc.js} +0 -0
  45. package/dist/types/api/sequencer.d.ts +289 -0
  46. package/dist/types/api/sequencer.js +2 -0
  47. package/dist/types/index.d.ts +3 -1
  48. package/dist/types/index.js +15 -1
  49. package/dist/types/lib.d.ts +3 -1
  50. package/dist/types/provider.d.ts +86 -0
  51. package/dist/types/provider.js +2 -0
  52. package/dist/utils/fetchPonyfill.d.ts +2 -0
  53. package/dist/utils/fetchPonyfill.js +6 -0
  54. package/dist/utils/provider.d.ts +4 -0
  55. package/dist/utils/provider.js +38 -0
  56. package/dist/utils/responseParser/index.d.ts +11 -0
  57. package/dist/utils/responseParser/index.js +9 -0
  58. package/dist/utils/responseParser/rpc.d.ts +13 -0
  59. package/dist/utils/responseParser/rpc.js +96 -0
  60. package/dist/utils/responseParser/sequencer.d.ts +13 -0
  61. package/dist/utils/responseParser/sequencer.js +124 -0
  62. package/index.js +42 -75
  63. package/package.json +2 -3
  64. package/provider/default.d.ts +21 -175
  65. package/provider/default.js +139 -704
  66. package/provider/errors.d.ts +4 -4
  67. package/provider/errors.js +30 -40
  68. package/provider/index.d.ts +2 -0
  69. package/provider/index.js +22 -33
  70. package/provider/interface.d.ts +104 -131
  71. package/provider/interface.js +6 -5
  72. package/provider/rpc.d.ts +57 -0
  73. package/provider/rpc.js +364 -0
  74. package/provider/sequencer.d.ts +66 -0
  75. package/provider/sequencer.js +444 -0
  76. package/provider/utils.d.ts +7 -9
  77. package/provider/utils.js +39 -44
  78. package/signer/default.d.ts +5 -9
  79. package/signer/default.js +72 -177
  80. package/signer/index.js +18 -31
  81. package/signer/interface.d.ts +29 -33
  82. package/signer/interface.js +6 -5
  83. package/src/account/default.ts +26 -146
  84. package/src/account/interface.ts +5 -20
  85. package/src/contract/contractFactory.ts +3 -6
  86. package/src/contract/default.ts +6 -4
  87. package/src/contract/interface.ts +2 -2
  88. package/src/provider/default.ts +63 -395
  89. package/src/provider/index.ts +2 -0
  90. package/src/provider/interface.ts +68 -63
  91. package/src/provider/rpc.ts +299 -0
  92. package/src/provider/sequencer.ts +385 -0
  93. package/src/types/account.ts +2 -3
  94. package/src/types/api/index.ts +17 -0
  95. package/src/types/api/rpc.ts +247 -0
  96. package/src/types/api/sequencer.ts +331 -0
  97. package/src/types/index.ts +3 -1
  98. package/src/types/lib.ts +3 -1
  99. package/src/types/provider.ts +108 -0
  100. package/src/utils/fetchPonyfill.ts +4 -0
  101. package/src/utils/provider.ts +28 -0
  102. package/src/utils/responseParser/index.ts +28 -0
  103. package/src/utils/responseParser/rpc.ts +93 -0
  104. package/src/utils/responseParser/sequencer.ts +127 -0
  105. package/types/account.d.ts +5 -7
  106. package/types/account.js +2 -2
  107. package/types/api/index.d.ts +16 -0
  108. package/types/api/index.js +18 -0
  109. package/types/api/rpc.d.ts +221 -0
  110. package/types/api/rpc.js +2 -0
  111. package/types/api/sequencer.d.ts +289 -0
  112. package/types/api/sequencer.js +2 -0
  113. package/types/contract.d.ts +1 -1
  114. package/types/contract.js +2 -2
  115. package/types/index.d.ts +3 -1
  116. package/types/index.js +35 -34
  117. package/types/lib.d.ts +36 -41
  118. package/types/lib.js +2 -2
  119. package/types/provider.d.ts +86 -0
  120. package/types/provider.js +2 -0
  121. package/types/signer.d.ts +2 -2
  122. package/types/signer.js +2 -2
  123. package/utils/address.js +26 -37
  124. package/utils/ellipticCurve.d.ts +1 -6
  125. package/utils/ellipticCurve.js +73 -137
  126. package/utils/encode.js +49 -85
  127. package/utils/fetchPonyfill.d.ts +2 -0
  128. package/utils/fetchPonyfill.js +6 -0
  129. package/utils/hash.d.ts +4 -31
  130. package/utils/hash.js +76 -141
  131. package/utils/json.d.ts +13 -45
  132. package/utils/json.js +15 -22
  133. package/utils/number.d.ts +2 -9
  134. package/utils/number.js +47 -81
  135. package/utils/provider.d.ts +4 -0
  136. package/utils/provider.js +38 -0
  137. package/utils/responseParser/index.d.ts +11 -0
  138. package/utils/responseParser/index.js +9 -0
  139. package/utils/responseParser/rpc.d.ts +13 -0
  140. package/utils/responseParser/rpc.js +96 -0
  141. package/utils/responseParser/sequencer.d.ts +13 -0
  142. package/utils/responseParser/sequencer.js +124 -0
  143. package/utils/shortString.js +13 -21
  144. package/utils/stark.d.ts +0 -1
  145. package/utils/stark.js +59 -93
  146. package/utils/transaction.d.ts +3 -6
  147. package/utils/transaction.js +50 -81
  148. package/utils/typedData/index.d.ts +3 -15
  149. package/utils/typedData/index.js +109 -175
  150. package/utils/typedData/types.d.ts +9 -9
  151. package/utils/typedData/types.js +2 -2
  152. package/utils/typedData/utils.js +6 -6
  153. package/utils/uint256.d.ts +5 -5
  154. package/utils/uint256.js +16 -26
  155. package/www/docs/API/account.md +3 -4
  156. package/www/docs/API/contract.md +2 -2
  157. package/www/docs/API/contractFactory.md +2 -2
  158. package/www/docs/API/provider.md +185 -74
  159. package/www/guides/account.md +1 -8
  160. package/www/guides/erc20.md +3 -0
  161. package/__tests__/provider.test.ts +0 -168
  162. package/dist/types/api.d.ts +0 -261
  163. package/src/types/api.ts +0 -303
  164. package/types/api.d.ts +0 -287
  165. package/types/api.js +0 -2
@@ -1,15 +1,4 @@
1
1
  "use strict";
2
- var __assign = (this && this.__assign) || function () {
3
- __assign = Object.assign || function(t) {
4
- for (var s, i = 1, n = arguments.length; i < n; i++) {
5
- s = arguments[i];
6
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
- t[p] = s[p];
8
- }
9
- return t;
10
- };
11
- return __assign.apply(this, arguments);
12
- };
13
2
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
14
3
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
15
4
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -46,465 +35,112 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
46
35
  if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
47
36
  }
48
37
  };
49
- var __read = (this && this.__read) || function (o, n) {
50
- var m = typeof Symbol === "function" && o[Symbol.iterator];
51
- if (!m) return o;
52
- var i = m.call(o), r, ar = [], e;
53
- try {
54
- while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
55
- }
56
- catch (error) { e = { error: error }; }
57
- finally {
58
- try {
59
- if (r && !r.done && (m = i["return"])) m.call(i);
60
- }
61
- finally { if (e) throw e.error; }
62
- }
63
- return ar;
64
- };
65
- var __importDefault = (this && this.__importDefault) || function (mod) {
66
- return (mod && mod.__esModule) ? mod : { "default": mod };
67
- };
68
38
  Object.defineProperty(exports, "__esModule", { value: true });
69
39
  exports.Provider = void 0;
70
- var url_join_1 = __importDefault(require("url-join"));
71
- var cross_fetch_1 = __importDefault(require("cross-fetch"));
72
- var constants_1 = require("../constants");
73
- var hash_1 = require("../utils/hash");
74
- var json_1 = require("../utils/json");
75
- var number_1 = require("../utils/number");
76
- var stark_1 = require("../utils/stark");
77
- var errors_1 = require("./errors");
78
- var interface_1 = require("./interface");
79
- var utils_1 = require("./utils");
80
- function wait(delay) {
81
- return new Promise(function (res) {
82
- setTimeout(res, delay);
83
- });
84
- }
85
- function isEmptyQueryObject(obj) {
86
- return (obj === undefined ||
87
- Object.keys(obj).length === 0 ||
88
- (Object.keys(obj).length === 1 &&
89
- Object.entries(obj).every(function (_a) {
90
- var _b = __read(_a, 2), k = _b[0], v = _b[1];
91
- return k === 'blockIdentifier' && v === null;
92
- })));
93
- }
40
+ var rpc_1 = require("./rpc");
41
+ var sequencer_1 = require("./sequencer");
94
42
  var Provider = /** @class */ (function () {
95
- function Provider(optionsOrProvider) {
96
- if (optionsOrProvider === void 0) { optionsOrProvider = { network: 'goerli-alpha' }; }
97
- var _a;
98
- if (optionsOrProvider instanceof interface_1.ProviderInterface) {
99
- this.baseUrl = optionsOrProvider.baseUrl;
100
- this.feederGatewayUrl = optionsOrProvider.feederGatewayUrl;
101
- this.gatewayUrl = optionsOrProvider.gatewayUrl;
102
- this.chainId =
103
- (_a = optionsOrProvider.chainId) !== null && _a !== void 0 ? _a : Provider.getChainIdFromBaseUrl(optionsOrProvider.baseUrl);
104
- }
105
- else {
106
- var baseUrl = 'baseUrl' in optionsOrProvider
107
- ? optionsOrProvider.baseUrl
108
- : Provider.getNetworkFromName(optionsOrProvider.network);
109
- this.baseUrl = baseUrl;
110
- this.chainId = Provider.getChainIdFromBaseUrl(baseUrl);
111
- this.feederGatewayUrl = (0, url_join_1.default)(baseUrl, 'feeder_gateway');
112
- this.gatewayUrl = (0, url_join_1.default)(baseUrl, 'gateway');
113
- }
114
- }
115
- Provider.getNetworkFromName = function (name) {
116
- switch (name) {
117
- case 'mainnet-alpha':
118
- return 'https://alpha-mainnet.starknet.io';
119
- case 'goerli-alpha':
120
- default:
121
- return 'https://alpha4.starknet.io';
43
+ function Provider(providerOrOptions) {
44
+ if (providerOrOptions && 'chainId' in providerOrOptions) {
45
+ this.provider = providerOrOptions;
122
46
  }
123
- };
124
- Provider.getChainIdFromBaseUrl = function (baseUrl) {
125
- try {
126
- var url = new URL(baseUrl);
127
- if (url.host.includes('mainnet.starknet.io')) {
128
- return constants_1.StarknetChainId.MAINNET;
129
- }
47
+ else if (providerOrOptions === null || providerOrOptions === void 0 ? void 0 : providerOrOptions.rpc) {
48
+ this.provider = new rpc_1.RpcProvider(providerOrOptions.rpc);
130
49
  }
131
- catch (_a) {
132
- // eslint-disable-next-line no-console
133
- console.error("Could not parse baseUrl: ".concat(baseUrl));
50
+ else if (providerOrOptions === null || providerOrOptions === void 0 ? void 0 : providerOrOptions.sequencer) {
51
+ this.provider = new sequencer_1.SequencerProvider(providerOrOptions.sequencer);
134
52
  }
135
- return constants_1.StarknetChainId.TESTNET;
136
- };
137
- Provider.prototype.getFetchUrl = function (endpoint) {
138
- var gatewayUrlEndpoints = ['add_transaction'];
139
- return gatewayUrlEndpoints.includes(endpoint) ? this.gatewayUrl : this.feederGatewayUrl;
140
- };
141
- Provider.prototype.getFetchMethod = function (endpoint) {
142
- var postMethodEndpoints = ['add_transaction', 'call_contract', 'estimate_fee'];
143
- return postMethodEndpoints.includes(endpoint) ? 'POST' : 'GET';
144
- };
145
- Provider.prototype.getQueryString = function (query) {
146
- if (isEmptyQueryObject(query)) {
147
- return '';
148
- }
149
- var queryString = Object.entries(query)
150
- .map(function (_a) {
151
- var _b = __read(_a, 2), key = _b[0], value = _b[1];
152
- if (key === 'blockIdentifier') {
153
- return "".concat((0, utils_1.getFormattedBlockIdentifier)(value));
154
- }
155
- return "".concat(key, "=").concat(value);
156
- })
157
- .join('&');
158
- return "?".concat(queryString);
159
- };
160
- Provider.prototype.getHeaders = function (method) {
161
- if (method === 'POST') {
162
- return {
163
- 'Content-Type': 'application/json',
164
- };
165
- }
166
- return undefined;
167
- };
168
- // typesafe fetch
169
- Provider.prototype.fetchEndpoint = function (endpoint) {
170
- // typescript type magiuc to create a nice fitting function interface
171
- var _a = []; // when both query and request are needed, we cant omit anything
172
- for (
173
- // typescript type magiuc to create a nice fitting function interface
174
- var _i = 1 // when both query and request are needed, we cant omit anything
175
- ;
176
- // typescript type magiuc to create a nice fitting function interface
177
- _i < arguments.length // when both query and request are needed, we cant omit anything
178
- ;
179
- // typescript type magiuc to create a nice fitting function interface
180
- _i++ // when both query and request are needed, we cant omit anything
181
- ) {
182
- // typescript type magiuc to create a nice fitting function interface
183
- _a[_i - 1] = arguments[_i]; // when both query and request are needed, we cant omit anything
53
+ else {
54
+ this.provider = new sequencer_1.SequencerProvider();
184
55
  }
185
- // typescript type magiuc to create a nice fitting function interface
186
- var _b = __read(_a, 2), query = _b[0], request = _b[1]; // when both query and request are needed, we cant omit anything
187
- return __awaiter(this, void 0, void 0, function () {
188
- var baseUrl, method, queryString, headers, url, res, textResponse, responseBody, errorCode, err_1;
189
- return __generator(this, function (_c) {
190
- switch (_c.label) {
191
- case 0:
192
- baseUrl = this.getFetchUrl(endpoint);
193
- method = this.getFetchMethod(endpoint);
194
- queryString = this.getQueryString(query);
195
- headers = this.getHeaders(method);
196
- url = (0, url_join_1.default)(baseUrl, endpoint, queryString);
197
- _c.label = 1;
198
- case 1:
199
- _c.trys.push([1, 4, , 5]);
200
- return [4 /*yield*/, (0, cross_fetch_1.default)(url, {
201
- method: method,
202
- body: (0, json_1.stringify)(request),
203
- headers: headers,
204
- })];
205
- case 2:
206
- res = _c.sent();
207
- return [4 /*yield*/, res.text()];
208
- case 3:
209
- textResponse = _c.sent();
210
- if (!res.ok) {
211
- responseBody = void 0;
212
- try {
213
- responseBody = (0, json_1.parse)(textResponse);
214
- }
215
- catch (_d) {
216
- // if error parsing fails, return an http error
217
- throw new errors_1.HttpError(res.statusText, res.status);
218
- }
219
- errorCode = responseBody.code || (responseBody === null || responseBody === void 0 ? void 0 : responseBody.status_code);
220
- throw new errors_1.GatewayError(responseBody.message, errorCode); // Caught locally, and re-thrown for the user
221
- }
222
- if (endpoint === 'estimate_fee') {
223
- return [2 /*return*/, (0, json_1.parseAlwaysAsBig)(textResponse, function (_, v) {
224
- if (v && typeof v === 'bigint') {
225
- return (0, number_1.toBN)(v.toString());
226
- }
227
- return v;
228
- })];
229
- }
230
- return [2 /*return*/, (0, json_1.parse)(textResponse)];
231
- case 4:
232
- err_1 = _c.sent();
233
- // rethrow custom errors
234
- if (err_1 instanceof errors_1.GatewayError || err_1 instanceof errors_1.HttpError) {
235
- throw err_1;
236
- }
237
- if (err_1 instanceof Error) {
238
- throw Error("Could not ".concat(method, " from endpoint `").concat(url, "`: ").concat(err_1.message));
239
- }
240
- throw err_1;
241
- case 5: return [2 /*return*/];
242
- }
243
- });
244
- });
245
- };
246
- /**
247
- * Gets the smart contract address on the goerli testnet.
248
- *
249
- * [Reference](https://github.com/starkware-libs/cairo-lang/blob/f464ec4797361b6be8989e36e02ec690e74ef285/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L13-L15)
250
- * @returns starknet smart contract addresses
251
- */
252
- Provider.prototype.getContractAddresses = function () {
56
+ }
57
+ Object.defineProperty(Provider.prototype, "chainId", {
58
+ get: function () {
59
+ return this.provider.chainId;
60
+ },
61
+ enumerable: false,
62
+ configurable: true
63
+ });
64
+ Provider.prototype.getBlock = function (blockIdentifier) {
65
+ if (blockIdentifier === void 0) { blockIdentifier = 'pending'; }
253
66
  return __awaiter(this, void 0, void 0, function () {
254
67
  return __generator(this, function (_a) {
255
- return [2 /*return*/, this.fetchEndpoint('get_contract_addresses')];
68
+ return [2 /*return*/, this.provider.getBlock(blockIdentifier)];
256
69
  });
257
70
  });
258
71
  };
259
- /**
260
- * Calls a function on the StarkNet contract.
261
- *
262
- * [Reference](https://github.com/starkware-libs/cairo-lang/blob/fc97bdd8322a7df043c87c371634b26c15ed6cee/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L25-L39)
263
- *
264
- * @param invokeTransaction - transaction to be invoked
265
- * @param blockHash
266
- * @param blockNumber
267
- * @returns the result of the function on the smart contract.
268
- */
269
- Provider.prototype.callContract = function (_a, _b) {
270
- var contractAddress = _a.contractAddress, entrypoint = _a.entrypoint, _c = _a.calldata, calldata = _c === void 0 ? [] : _c;
271
- var _d = _b === void 0 ? {} : _b, _e = _d.blockIdentifier, blockIdentifier = _e === void 0 ? 'pending' : _e;
72
+ Provider.prototype.getClassAt = function (contractAddress, blockIdentifier) {
73
+ if (blockIdentifier === void 0) { blockIdentifier = 'pending'; }
272
74
  return __awaiter(this, void 0, void 0, function () {
273
- return __generator(this, function (_f) {
274
- return [2 /*return*/, this.fetchEndpoint('call_contract', { blockIdentifier: blockIdentifier }, {
275
- signature: [],
276
- contract_address: contractAddress,
277
- entry_point_selector: (0, hash_1.getSelectorFromName)(entrypoint),
278
- calldata: calldata,
279
- })];
75
+ return __generator(this, function (_a) {
76
+ return [2 /*return*/, this.provider.getClassAt(contractAddress, blockIdentifier)];
280
77
  });
281
78
  });
282
79
  };
283
- /**
284
- * Gets the block information
285
- *
286
- * [Reference](https://github.com/starkware-libs/cairo-lang/blob/fc97bdd8322a7df043c87c371634b26c15ed6cee/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L41-L53)
287
- *
288
- * @param blockHash
289
- * @param blockNumber
290
- * @returns the block object { block_number, previous_block_number, state_root, status, timestamp, transaction_receipts, transactions }
291
- */
292
- Provider.prototype.getBlock = function (blockIdentifier) {
293
- if (blockIdentifier === void 0) { blockIdentifier = null; }
80
+ Provider.prototype.getEstimateFee = function (invocation, blockIdentifier, invocationDetails) {
81
+ if (blockIdentifier === void 0) { blockIdentifier = 'pending'; }
82
+ if (invocationDetails === void 0) { invocationDetails = {}; }
294
83
  return __awaiter(this, void 0, void 0, function () {
295
84
  return __generator(this, function (_a) {
296
- return [2 /*return*/, this.fetchEndpoint('get_block', { blockIdentifier: blockIdentifier })];
85
+ return [2 /*return*/, this.provider.getEstimateFee(invocation, blockIdentifier, invocationDetails)];
297
86
  });
298
87
  });
299
88
  };
300
- /**
301
- * Gets the code of the deployed contract.
302
- *
303
- * [Reference](https://github.com/starkware-libs/cairo-lang/blob/fc97bdd8322a7df043c87c371634b26c15ed6cee/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L55-L68)
304
- *
305
- * @param contractAddress
306
- * @param blockHash
307
- * @param blockNumber
308
- * @returns Bytecode and ABI of compiled contract
309
- */
310
- Provider.prototype.getCode = function (contractAddress, blockIdentifier) {
311
- if (blockIdentifier === void 0) { blockIdentifier = 'pending'; }
89
+ Provider.prototype.getStorageAt = function (contractAddress, key, blockTagOrHash) {
90
+ if (blockTagOrHash === void 0) { blockTagOrHash = 'pending'; }
312
91
  return __awaiter(this, void 0, void 0, function () {
313
92
  return __generator(this, function (_a) {
314
- return [2 /*return*/, this.fetchEndpoint('get_code', { blockIdentifier: blockIdentifier, contractAddress: contractAddress })];
93
+ return [2 /*return*/, this.provider.getStorageAt(contractAddress, key, blockTagOrHash)];
315
94
  });
316
95
  });
317
96
  };
318
- // TODO: add proper type
319
- /**
320
- * Gets the contract's storage variable at a specific key.
321
- *
322
- * [Reference](https://github.com/starkware-libs/cairo-lang/blob/fc97bdd8322a7df043c87c371634b26c15ed6cee/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L70-L85)
323
- *
324
- * @param contractAddress
325
- * @param key - from getStorageVarAddress('<STORAGE_VARIABLE_NAME>') (WIP)
326
- * @param blockHash
327
- * @param blockNumber
328
- * @returns the value of the storage variable
329
- */
330
- Provider.prototype.getStorageAt = function (contractAddress, key, blockIdentifier) {
331
- if (blockIdentifier === void 0) { blockIdentifier = 'pending'; }
97
+ Provider.prototype.getTransaction = function (txHash) {
332
98
  return __awaiter(this, void 0, void 0, function () {
333
99
  return __generator(this, function (_a) {
334
- return [2 /*return*/, this.fetchEndpoint('get_storage_at', { blockIdentifier: blockIdentifier, contractAddress: contractAddress, key: key })];
100
+ return [2 /*return*/, this.provider.getTransaction(txHash)];
335
101
  });
336
102
  });
337
103
  };
338
- /**
339
- * Gets the status of a transaction.
340
- *
341
- * [Reference](https://github.com/starkware-libs/cairo-lang/blob/f464ec4797361b6be8989e36e02ec690e74ef285/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L48-L52)
342
- *
343
- * @param txHash
344
- * @returns the transaction status object { block_number, tx_status: NOT_RECEIVED | RECEIVED | PENDING | REJECTED | ACCEPTED_ONCHAIN }
345
- */
346
- Provider.prototype.getTransactionStatus = function (txHash) {
104
+ Provider.prototype.getTransactionReceipt = function (txHash) {
347
105
  return __awaiter(this, void 0, void 0, function () {
348
- var txHashHex;
349
106
  return __generator(this, function (_a) {
350
- txHashHex = (0, number_1.toHex)((0, number_1.toBN)(txHash));
351
- return [2 /*return*/, this.fetchEndpoint('get_transaction_status', { transactionHash: txHashHex })];
107
+ return [2 /*return*/, this.provider.getTransactionReceipt(txHash)];
352
108
  });
353
109
  });
354
110
  };
355
- /**
356
- * Gets the transaction receipt from a tx hash.
357
- *
358
- * [Reference] (https://github.com/starkware-libs/cairo-lang/blob/167b28bcd940fd25ea3816204fa882a0b0a49603/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L183)
359
- *
360
- * @param txHash
361
- * @returns the transaction receipt object
362
- */
363
- Provider.prototype.getTransactionReceipt = function (txHash) {
111
+ Provider.prototype.callContract = function (request, blockIdentifier) {
112
+ if (blockIdentifier === void 0) { blockIdentifier = 'pending'; }
364
113
  return __awaiter(this, void 0, void 0, function () {
365
- var txHashHex;
366
114
  return __generator(this, function (_a) {
367
- txHashHex = (0, number_1.toHex)((0, number_1.toBN)(txHash));
368
- return [2 /*return*/, this.fetchEndpoint('get_transaction_receipt', { transactionHash: txHashHex })];
115
+ return [2 /*return*/, this.provider.callContract(request, blockIdentifier)];
369
116
  });
370
117
  });
371
118
  };
372
- /**
373
- * Gets the transaction information from a tx id.
374
- *
375
- * [Reference](https://github.com/starkware-libs/cairo-lang/blob/f464ec4797361b6be8989e36e02ec690e74ef285/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L54-L58)
376
- *
377
- * @param txHash
378
- * @returns the transacton object { transaction_id, status, transaction, block_number?, block_number?, transaction_index?, transaction_failure_reason? }
379
- */
380
- Provider.prototype.getTransaction = function (txHash) {
119
+ Provider.prototype.invokeFunction = function (functionInvocation, details) {
381
120
  return __awaiter(this, void 0, void 0, function () {
382
- var txHashHex;
383
121
  return __generator(this, function (_a) {
384
- txHashHex = (0, number_1.toHex)((0, number_1.toBN)(txHash));
385
- return [2 /*return*/, this.fetchEndpoint('get_transaction', { transactionHash: txHashHex })];
122
+ return [2 /*return*/, this.provider.invokeFunction(functionInvocation, details)];
386
123
  });
387
124
  });
388
125
  };
389
- /**
390
- * Gets the transaction trace from a tx id.
391
- *
392
- *
393
- * @param txHash
394
- * @returns the transaction trace
395
- */
396
- Provider.prototype.getTransactionTrace = function (txHash) {
126
+ Provider.prototype.deployContract = function (payload) {
397
127
  return __awaiter(this, void 0, void 0, function () {
398
- var txHashHex;
399
128
  return __generator(this, function (_a) {
400
- txHashHex = (0, number_1.toHex)((0, number_1.toBN)(txHash));
401
- return [2 /*return*/, this.fetchEndpoint('get_transaction_trace', { transactionHash: txHashHex })];
129
+ return [2 /*return*/, this.provider.deployContract(payload)];
402
130
  });
403
131
  });
404
132
  };
405
- /**
406
- * Declare a given compiled contract (json) on starknet
407
- *
408
- * @param contract - a json object containing the compiled contract
409
- * @returns a confirmation of sending a transaction on the starknet contract
410
- */
411
133
  Provider.prototype.declareContract = function (payload) {
412
- var parsedContract = typeof payload.contract === 'string'
413
- ? (0, json_1.parse)(payload.contract)
414
- : payload.contract;
415
- var contractDefinition = __assign(__assign({}, parsedContract), { program: (0, stark_1.compressProgram)(parsedContract.program) });
416
- return this.fetchEndpoint('add_transaction', undefined, {
417
- type: 'DECLARE',
418
- contract_class: contractDefinition,
419
- nonce: (0, number_1.toHex)(constants_1.ZERO),
420
- signature: [],
421
- sender_address: (0, number_1.toHex)(constants_1.ONE),
422
- });
423
- };
424
- /**
425
- * Deploys a given compiled contract (json) to starknet
426
- *
427
- * @param contract - a json object containing the compiled contract
428
- * @param address - (optional, defaults to a random address) the address where the contract should be deployed (alpha)
429
- * @returns a confirmation of sending a transaction on the starknet contract
430
- */
431
- Provider.prototype.deployContract = function (payload, _abi) {
432
- var _a, _b;
433
- var parsedContract = typeof payload.contract === 'string'
434
- ? (0, json_1.parse)(payload.contract)
435
- : payload.contract;
436
- var contractDefinition = __assign(__assign({}, parsedContract), { program: (0, stark_1.compressProgram)(parsedContract.program) });
437
- return this.fetchEndpoint('add_transaction', undefined, {
438
- type: 'DEPLOY',
439
- contract_address_salt: (_a = payload.addressSalt) !== null && _a !== void 0 ? _a : (0, stark_1.randomAddress)(),
440
- constructor_calldata: (0, number_1.bigNumberishArrayToDecimalStringArray)((_b = payload.constructorCalldata) !== null && _b !== void 0 ? _b : []),
441
- contract_definition: contractDefinition,
442
- });
443
- };
444
- /**
445
- * Invokes a function on starknet
446
- * @deprecated This method wont be supported as soon as fees are mandatory
447
- *
448
- * @param invocation
449
- * @param _abi - (optional) signature to send along
450
- * @returns response from addTransaction
451
- */
452
- Provider.prototype.invokeFunction = function (invocation, _abi) {
453
- var _a, _b;
454
- return this.fetchEndpoint('add_transaction', undefined, {
455
- type: 'INVOKE_FUNCTION',
456
- contract_address: invocation.contractAddress,
457
- entry_point_selector: (0, hash_1.getSelectorFromName)(invocation.entrypoint),
458
- calldata: (0, number_1.bigNumberishArrayToDecimalStringArray)((_a = invocation.calldata) !== null && _a !== void 0 ? _a : []),
459
- signature: (0, number_1.bigNumberishArrayToDecimalStringArray)((_b = invocation.signature) !== null && _b !== void 0 ? _b : []),
460
- });
461
- };
462
- Provider.prototype.waitForTransaction = function (txHash, retryInterval) {
463
- if (retryInterval === void 0) { retryInterval = 8000; }
464
134
  return __awaiter(this, void 0, void 0, function () {
465
- var onchain, res, successStates, errorStates, message, error;
466
135
  return __generator(this, function (_a) {
467
- switch (_a.label) {
468
- case 0:
469
- onchain = false;
470
- _a.label = 1;
471
- case 1:
472
- if (!!onchain) return [3 /*break*/, 4];
473
- // eslint-disable-next-line no-await-in-loop
474
- return [4 /*yield*/, wait(retryInterval)];
475
- case 2:
476
- // eslint-disable-next-line no-await-in-loop
477
- _a.sent();
478
- return [4 /*yield*/, this.getTransactionStatus(txHash)];
479
- case 3:
480
- res = _a.sent();
481
- successStates = ['ACCEPTED_ON_L1', 'ACCEPTED_ON_L2', 'PENDING'];
482
- errorStates = ['REJECTED', 'NOT_RECEIVED'];
483
- if (successStates.includes(res.tx_status)) {
484
- onchain = true;
485
- }
486
- else if (errorStates.includes(res.tx_status)) {
487
- message = res.tx_failure_reason
488
- ? "".concat(res.tx_status, ": ").concat(res.tx_failure_reason.code, "\n").concat(res.tx_failure_reason.error_message)
489
- : res.tx_status;
490
- error = new Error(message);
491
- error.response = res;
492
- throw error;
493
- }
494
- return [3 /*break*/, 1];
495
- case 4: return [2 /*return*/];
496
- }
136
+ return [2 /*return*/, this.provider.declareContract(payload)];
497
137
  });
498
138
  });
499
139
  };
500
- /**
501
- * @deprecated use `waitForTransaction` instead
502
- */
503
- Provider.prototype.waitForTx = function (txHash, retryInterval) {
504
- if (retryInterval === void 0) { retryInterval = 8000; }
140
+ Provider.prototype.waitForTransaction = function (txHash, retryInterval) {
505
141
  return __awaiter(this, void 0, void 0, function () {
506
142
  return __generator(this, function (_a) {
507
- return [2 /*return*/, this.waitForTransaction(txHash, retryInterval)];
143
+ return [2 /*return*/, this.provider.waitForTransaction(txHash, retryInterval)];
508
144
  });
509
145
  });
510
146
  };
@@ -1,5 +1,7 @@
1
1
  import { Provider } from './default';
2
2
  export * from './default';
3
3
  export * from './errors';
4
+ export * from './sequencer';
4
5
  export * from './interface';
6
+ export * from './rpc';
5
7
  export declare const defaultProvider: Provider;
@@ -18,5 +18,7 @@ exports.defaultProvider = void 0;
18
18
  var default_1 = require("./default");
19
19
  __exportStar(require("./default"), exports);
20
20
  __exportStar(require("./errors"), exports);
21
+ __exportStar(require("./sequencer"), exports);
21
22
  __exportStar(require("./interface"), exports);
23
+ __exportStar(require("./rpc"), exports);
22
24
  exports.defaultProvider = new default_1.Provider();