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