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.
- package/CHANGELOG.md +65 -0
- package/README.md +1 -0
- package/__mocks__/typedDataStructArrayExample.json +44 -0
- package/__tests__/account.test.ts +11 -56
- package/__tests__/contract.test.ts +11 -49
- package/__tests__/defaultProvider.test.ts +321 -0
- package/__tests__/fixtures.ts +32 -11
- package/__tests__/rpcProvider.test.ts +17 -0
- package/__tests__/sequencerProvider.test.ts +45 -0
- package/__tests__/utils/typedData.test.ts +24 -0
- package/account/default.d.ts +54 -77
- package/account/default.js +271 -596
- package/account/index.js +18 -31
- package/account/interface.d.ts +66 -95
- package/account/interface.js +20 -30
- package/constants.d.ts +17 -19
- package/constants.js +2038 -2059
- package/contract/contractFactory.d.ts +25 -29
- package/contract/contractFactory.js +94 -210
- package/contract/default.d.ts +117 -146
- package/contract/default.js +582 -776
- package/contract/index.js +19 -32
- package/contract/interface.d.ts +72 -92
- package/contract/interface.js +6 -5
- package/dist/account/default.d.ts +5 -9
- package/dist/account/default.js +35 -169
- package/dist/account/interface.d.ts +3 -15
- package/dist/contract/contractFactory.js +4 -4
- package/dist/contract/default.d.ts +3 -3
- package/dist/contract/default.js +3 -2
- package/dist/contract/interface.d.ts +2 -2
- package/dist/provider/default.d.ts +18 -134
- package/dist/provider/default.js +47 -410
- package/dist/provider/index.d.ts +2 -0
- package/dist/provider/index.js +2 -0
- package/dist/provider/interface.d.ts +45 -50
- package/dist/provider/rpc.d.ts +57 -0
- package/dist/provider/rpc.js +364 -0
- package/dist/provider/sequencer.d.ts +66 -0
- package/dist/provider/sequencer.js +443 -0
- package/dist/types/account.d.ts +2 -3
- package/dist/types/api/index.d.ts +16 -0
- package/dist/types/api/index.js +18 -0
- package/dist/types/api/rpc.d.ts +221 -0
- package/dist/types/{api.js → api/rpc.js} +0 -0
- package/dist/types/api/sequencer.d.ts +289 -0
- package/dist/types/api/sequencer.js +2 -0
- package/dist/types/index.d.ts +3 -1
- package/dist/types/index.js +15 -1
- package/dist/types/lib.d.ts +3 -1
- package/dist/types/provider.d.ts +86 -0
- package/dist/types/provider.js +2 -0
- package/dist/utils/provider.d.ts +4 -0
- package/dist/utils/provider.js +38 -0
- package/dist/utils/responseParser/index.d.ts +11 -0
- package/dist/utils/responseParser/index.js +9 -0
- package/dist/utils/responseParser/rpc.d.ts +13 -0
- package/dist/utils/responseParser/rpc.js +96 -0
- package/dist/utils/responseParser/sequencer.d.ts +13 -0
- package/dist/utils/responseParser/sequencer.js +124 -0
- package/dist/utils/typedData/index.js +14 -0
- package/index.js +42 -75
- package/package.json +1 -1
- package/provider/default.d.ts +21 -175
- package/provider/default.js +139 -703
- package/provider/errors.d.ts +4 -4
- package/provider/errors.js +30 -40
- package/provider/index.d.ts +2 -0
- package/provider/index.js +22 -33
- package/provider/interface.d.ts +104 -131
- package/provider/interface.js +6 -5
- package/provider/rpc.d.ts +57 -0
- package/provider/rpc.js +364 -0
- package/provider/sequencer.d.ts +66 -0
- package/provider/sequencer.js +443 -0
- package/provider/utils.d.ts +7 -9
- package/provider/utils.js +39 -44
- package/signer/default.d.ts +5 -9
- package/signer/default.js +72 -177
- package/signer/index.js +18 -31
- package/signer/interface.d.ts +29 -33
- package/signer/interface.js +6 -5
- package/src/account/default.ts +26 -146
- package/src/account/interface.ts +5 -20
- package/src/contract/contractFactory.ts +3 -6
- package/src/contract/default.ts +6 -4
- package/src/contract/interface.ts +2 -2
- package/src/provider/default.ts +63 -394
- package/src/provider/index.ts +2 -0
- package/src/provider/interface.ts +68 -63
- package/src/provider/rpc.ts +300 -0
- package/src/provider/sequencer.ts +384 -0
- package/src/types/account.ts +2 -3
- package/src/types/api/index.ts +17 -0
- package/src/types/api/rpc.ts +247 -0
- package/src/types/api/sequencer.ts +331 -0
- package/src/types/index.ts +3 -1
- package/src/types/lib.ts +3 -1
- package/src/types/provider.ts +108 -0
- package/src/utils/provider.ts +28 -0
- package/src/utils/responseParser/index.ts +28 -0
- package/src/utils/responseParser/rpc.ts +93 -0
- package/src/utils/responseParser/sequencer.ts +127 -0
- package/src/utils/typedData/index.ts +18 -0
- package/types/account.d.ts +5 -7
- package/types/account.js +2 -2
- package/types/api/index.d.ts +16 -0
- package/types/api/index.js +18 -0
- package/types/api/rpc.d.ts +221 -0
- package/types/api/rpc.js +2 -0
- package/types/api/sequencer.d.ts +289 -0
- package/types/api/sequencer.js +2 -0
- package/types/contract.d.ts +1 -1
- package/types/contract.js +2 -2
- package/types/index.d.ts +3 -1
- package/types/index.js +35 -34
- package/types/lib.d.ts +36 -41
- package/types/lib.js +2 -2
- package/types/provider.d.ts +86 -0
- package/types/provider.js +2 -0
- package/types/signer.d.ts +2 -2
- package/types/signer.js +2 -2
- package/utils/address.js +26 -37
- package/utils/ellipticCurve.d.ts +1 -6
- package/utils/ellipticCurve.js +73 -137
- package/utils/encode.js +49 -85
- package/utils/hash.d.ts +4 -31
- package/utils/hash.js +76 -141
- package/utils/json.d.ts +13 -45
- package/utils/json.js +15 -22
- package/utils/number.d.ts +2 -9
- package/utils/number.js +47 -81
- package/utils/provider.d.ts +4 -0
- package/utils/provider.js +38 -0
- package/utils/responseParser/index.d.ts +11 -0
- package/utils/responseParser/index.js +9 -0
- package/utils/responseParser/rpc.d.ts +13 -0
- package/utils/responseParser/rpc.js +96 -0
- package/utils/responseParser/sequencer.d.ts +13 -0
- package/utils/responseParser/sequencer.js +124 -0
- package/utils/shortString.js +13 -21
- package/utils/stark.d.ts +0 -1
- package/utils/stark.js +59 -93
- package/utils/transaction.d.ts +3 -6
- package/utils/transaction.js +50 -81
- package/utils/typedData/index.d.ts +3 -15
- package/utils/typedData/index.js +109 -157
- package/utils/typedData/types.d.ts +9 -9
- package/utils/typedData/types.js +2 -2
- package/utils/typedData/utils.js +6 -6
- package/utils/uint256.d.ts +5 -5
- package/utils/uint256.js +16 -26
- package/www/docs/API/account.md +3 -4
- package/www/docs/API/contract.md +2 -2
- package/www/docs/API/contractFactory.md +2 -2
- package/www/docs/API/provider.md +185 -74
- package/www/guides/account.md +1 -8
- package/www/guides/erc20.md +3 -0
- package/__tests__/provider.test.ts +0 -168
- package/dist/types/api.d.ts +0 -261
- package/src/types/api.ts +0 -303
- package/types/api.d.ts +0 -287
- package/types/api.js +0 -2
package/dist/provider/default.js
CHANGED
|
@@ -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
|
|
71
|
-
var
|
|
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(
|
|
95
|
-
if (
|
|
96
|
-
|
|
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
|
-
|
|
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
|
-
|
|
131
|
-
|
|
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
|
-
|
|
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
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
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.
|
|
68
|
+
return [2 /*return*/, this.provider.getBlock(blockIdentifier)];
|
|
255
69
|
});
|
|
256
70
|
});
|
|
257
71
|
};
|
|
258
|
-
|
|
259
|
-
|
|
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 (
|
|
273
|
-
return [2 /*return*/, this.
|
|
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
|
-
|
|
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.
|
|
85
|
+
return [2 /*return*/, this.provider.getEstimateFee(invocation, blockIdentifier, invocationDetails)];
|
|
296
86
|
});
|
|
297
87
|
});
|
|
298
88
|
};
|
|
299
|
-
|
|
300
|
-
|
|
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.
|
|
93
|
+
return [2 /*return*/, this.provider.getStorageAt(contractAddress, key, blockTagOrHash)];
|
|
314
94
|
});
|
|
315
95
|
});
|
|
316
96
|
};
|
|
317
|
-
|
|
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.
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
};
|
package/dist/provider/index.d.ts
CHANGED
package/dist/provider/index.js
CHANGED
|
@@ -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();
|