starknet 4.12.0 → 4.13.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 (224) hide show
  1. package/.eslintrc +1 -0
  2. package/CHANGELOG.md +14 -0
  3. package/__tests__/account.test.ts +0 -2
  4. package/dist/index.d.ts +2683 -24
  5. package/dist/index.global.js +22994 -0
  6. package/dist/index.global.js.map +1 -0
  7. package/dist/index.js +4713 -53
  8. package/dist/index.js.map +1 -0
  9. package/dist/index.mjs +4655 -0
  10. package/dist/index.mjs.map +1 -0
  11. package/index.d.ts +2683 -24
  12. package/index.global.js +22994 -0
  13. package/index.global.js.map +1 -0
  14. package/index.js +4713 -53
  15. package/index.js.map +1 -0
  16. package/index.mjs +4655 -0
  17. package/index.mjs.map +1 -0
  18. package/package.json +8 -2
  19. package/src/account/default.ts +43 -8
  20. package/src/account/interface.ts +25 -2
  21. package/src/constants.ts +0 -1
  22. package/src/provider/default.ts +3 -0
  23. package/src/provider/interface.ts +2 -0
  24. package/src/provider/rpc.ts +4 -4
  25. package/src/provider/sequencer.ts +4 -1
  26. package/src/types/lib.ts +1 -1
  27. package/src/types/provider.ts +5 -0
  28. package/src/utils/ellipticCurve.ts +3 -1
  29. package/src/utils/fetchPonyfill.ts +3 -2
  30. package/src/utils/hash.ts +3 -2
  31. package/src/utils/number.ts +2 -2
  32. package/tsup.config.ts +10 -0
  33. package/account/default.d.ts +0 -30
  34. package/account/default.js +0 -526
  35. package/account/index.d.ts +0 -2
  36. package/account/index.js +0 -18
  37. package/account/interface.d.ts +0 -161
  38. package/account/interface.js +0 -27
  39. package/constants.d.ts +0 -36
  40. package/constants.js +0 -2067
  41. package/contract/contractFactory.d.ts +0 -31
  42. package/contract/contractFactory.js +0 -102
  43. package/contract/default.d.ts +0 -108
  44. package/contract/default.js +0 -640
  45. package/contract/index.d.ts +0 -3
  46. package/contract/index.js +0 -19
  47. package/contract/interface.d.ts +0 -80
  48. package/contract/interface.js +0 -9
  49. package/dist/account/default.d.ts +0 -30
  50. package/dist/account/default.js +0 -526
  51. package/dist/account/index.d.ts +0 -2
  52. package/dist/account/index.js +0 -18
  53. package/dist/account/interface.d.ts +0 -161
  54. package/dist/account/interface.js +0 -27
  55. package/dist/constants.d.ts +0 -36
  56. package/dist/constants.js +0 -2067
  57. package/dist/contract/contractFactory.d.ts +0 -31
  58. package/dist/contract/contractFactory.js +0 -102
  59. package/dist/contract/default.d.ts +0 -108
  60. package/dist/contract/default.js +0 -640
  61. package/dist/contract/index.d.ts +0 -3
  62. package/dist/contract/index.js +0 -19
  63. package/dist/contract/interface.d.ts +0 -80
  64. package/dist/contract/interface.js +0 -9
  65. package/dist/provider/default.d.ts +0 -37
  66. package/dist/provider/default.js +0 -207
  67. package/dist/provider/errors.d.ts +0 -9
  68. package/dist/provider/errors.js +0 -40
  69. package/dist/provider/index.d.ts +0 -7
  70. package/dist/provider/index.js +0 -24
  71. package/dist/provider/interface.d.ts +0 -203
  72. package/dist/provider/interface.js +0 -9
  73. package/dist/provider/rpc.d.ts +0 -86
  74. package/dist/provider/rpc.js +0 -605
  75. package/dist/provider/sequencer.d.ts +0 -79
  76. package/dist/provider/sequencer.js +0 -575
  77. package/dist/provider/utils.d.ts +0 -30
  78. package/dist/provider/utils.js +0 -84
  79. package/dist/signer/default.d.ts +0 -13
  80. package/dist/signer/default.js +0 -102
  81. package/dist/signer/index.d.ts +0 -2
  82. package/dist/signer/index.js +0 -18
  83. package/dist/signer/interface.d.ts +0 -60
  84. package/dist/signer/interface.js +0 -9
  85. package/dist/types/account.d.ts +0 -11
  86. package/dist/types/account.js +0 -2
  87. package/dist/types/api/index.d.ts +0 -10
  88. package/dist/types/api/index.js +0 -18
  89. package/dist/types/api/openrpc.d.ts +0 -572
  90. package/dist/types/api/openrpc.js +0 -45
  91. package/dist/types/api/rpc.d.ts +0 -43
  92. package/dist/types/api/rpc.js +0 -2
  93. package/dist/types/api/sequencer.d.ts +0 -320
  94. package/dist/types/api/sequencer.js +0 -2
  95. package/dist/types/contract.d.ts +0 -5
  96. package/dist/types/contract.js +0 -2
  97. package/dist/types/index.d.ts +0 -7
  98. package/dist/types/index.js +0 -35
  99. package/dist/types/lib.d.ts +0 -120
  100. package/dist/types/lib.js +0 -8
  101. package/dist/types/provider.d.ts +0 -99
  102. package/dist/types/provider.js +0 -2
  103. package/dist/types/signer.d.ts +0 -19
  104. package/dist/types/signer.js +0 -2
  105. package/dist/utils/address.d.ts +0 -5
  106. package/dist/utils/address.js +0 -41
  107. package/dist/utils/ellipticCurve.d.ts +0 -29
  108. package/dist/utils/ellipticCurve.js +0 -132
  109. package/dist/utils/encode.d.ts +0 -15
  110. package/dist/utils/encode.js +0 -96
  111. package/dist/utils/fetchPonyfill.d.ts +0 -2
  112. package/dist/utils/fetchPonyfill.js +0 -6
  113. package/dist/utils/hash.d.ts +0 -37
  114. package/dist/utils/hash.js +0 -162
  115. package/dist/utils/json.d.ts +0 -16
  116. package/dist/utils/json.js +0 -19
  117. package/dist/utils/merkle.d.ts +0 -10
  118. package/dist/utils/merkle.js +0 -89
  119. package/dist/utils/number.d.ts +0 -16
  120. package/dist/utils/number.js +0 -112
  121. package/dist/utils/provider.d.ts +0 -4
  122. package/dist/utils/provider.js +0 -38
  123. package/dist/utils/responseParser/index.d.ts +0 -11
  124. package/dist/utils/responseParser/index.js +0 -9
  125. package/dist/utils/responseParser/rpc.d.ts +0 -20
  126. package/dist/utils/responseParser/rpc.js +0 -44
  127. package/dist/utils/responseParser/sequencer.d.ts +0 -17
  128. package/dist/utils/responseParser/sequencer.js +0 -99
  129. package/dist/utils/shortString.d.ts +0 -4
  130. package/dist/utils/shortString.js +0 -26
  131. package/dist/utils/stark.d.ts +0 -16
  132. package/dist/utils/stark.js +0 -91
  133. package/dist/utils/transaction.d.ts +0 -20
  134. package/dist/utils/transaction.js +0 -79
  135. package/dist/utils/typedData/index.d.ts +0 -72
  136. package/dist/utils/typedData/index.js +0 -239
  137. package/dist/utils/typedData/types.d.ts +0 -32
  138. package/dist/utils/typedData/types.js +0 -2
  139. package/dist/utils/typedData/utils.d.ts +0 -8
  140. package/dist/utils/typedData/utils.js +0 -16
  141. package/dist/utils/uint256.d.ts +0 -11
  142. package/dist/utils/uint256.js +0 -28
  143. package/dist/utils/url.d.ts +0 -7
  144. package/dist/utils/url.js +0 -49
  145. package/provider/default.d.ts +0 -37
  146. package/provider/default.js +0 -207
  147. package/provider/errors.d.ts +0 -9
  148. package/provider/errors.js +0 -40
  149. package/provider/index.d.ts +0 -7
  150. package/provider/index.js +0 -24
  151. package/provider/interface.d.ts +0 -203
  152. package/provider/interface.js +0 -9
  153. package/provider/rpc.d.ts +0 -86
  154. package/provider/rpc.js +0 -605
  155. package/provider/sequencer.d.ts +0 -79
  156. package/provider/sequencer.js +0 -575
  157. package/provider/utils.d.ts +0 -30
  158. package/provider/utils.js +0 -84
  159. package/signer/default.d.ts +0 -13
  160. package/signer/default.js +0 -102
  161. package/signer/index.d.ts +0 -2
  162. package/signer/index.js +0 -18
  163. package/signer/interface.d.ts +0 -60
  164. package/signer/interface.js +0 -9
  165. package/types/account.d.ts +0 -11
  166. package/types/account.js +0 -2
  167. package/types/api/index.d.ts +0 -10
  168. package/types/api/index.js +0 -18
  169. package/types/api/openrpc.d.ts +0 -572
  170. package/types/api/openrpc.js +0 -45
  171. package/types/api/rpc.d.ts +0 -43
  172. package/types/api/rpc.js +0 -2
  173. package/types/api/sequencer.d.ts +0 -320
  174. package/types/api/sequencer.js +0 -2
  175. package/types/contract.d.ts +0 -5
  176. package/types/contract.js +0 -2
  177. package/types/index.d.ts +0 -7
  178. package/types/index.js +0 -35
  179. package/types/lib.d.ts +0 -120
  180. package/types/lib.js +0 -8
  181. package/types/provider.d.ts +0 -99
  182. package/types/provider.js +0 -2
  183. package/types/signer.d.ts +0 -19
  184. package/types/signer.js +0 -2
  185. package/utils/address.d.ts +0 -5
  186. package/utils/address.js +0 -41
  187. package/utils/ellipticCurve.d.ts +0 -29
  188. package/utils/ellipticCurve.js +0 -132
  189. package/utils/encode.d.ts +0 -15
  190. package/utils/encode.js +0 -96
  191. package/utils/fetchPonyfill.d.ts +0 -2
  192. package/utils/fetchPonyfill.js +0 -6
  193. package/utils/hash.d.ts +0 -37
  194. package/utils/hash.js +0 -162
  195. package/utils/json.d.ts +0 -16
  196. package/utils/json.js +0 -19
  197. package/utils/merkle.d.ts +0 -10
  198. package/utils/merkle.js +0 -89
  199. package/utils/number.d.ts +0 -16
  200. package/utils/number.js +0 -112
  201. package/utils/provider.d.ts +0 -4
  202. package/utils/provider.js +0 -38
  203. package/utils/responseParser/index.d.ts +0 -11
  204. package/utils/responseParser/index.js +0 -9
  205. package/utils/responseParser/rpc.d.ts +0 -20
  206. package/utils/responseParser/rpc.js +0 -44
  207. package/utils/responseParser/sequencer.d.ts +0 -17
  208. package/utils/responseParser/sequencer.js +0 -99
  209. package/utils/shortString.d.ts +0 -4
  210. package/utils/shortString.js +0 -26
  211. package/utils/stark.d.ts +0 -16
  212. package/utils/stark.js +0 -91
  213. package/utils/transaction.d.ts +0 -20
  214. package/utils/transaction.js +0 -79
  215. package/utils/typedData/index.d.ts +0 -72
  216. package/utils/typedData/index.js +0 -239
  217. package/utils/typedData/types.d.ts +0 -32
  218. package/utils/typedData/types.js +0 -2
  219. package/utils/typedData/utils.d.ts +0 -8
  220. package/utils/typedData/utils.js +0 -16
  221. package/utils/uint256.d.ts +0 -11
  222. package/utils/uint256.js +0 -28
  223. package/utils/url.d.ts +0 -7
  224. package/utils/url.js +0 -49
@@ -1,605 +0,0 @@
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
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
14
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
15
- return new (P || (P = Promise))(function (resolve, reject) {
16
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
17
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
18
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
19
- step((generator = generator.apply(thisArg, _arguments || [])).next());
20
- });
21
- };
22
- var __generator = (this && this.__generator) || function (thisArg, body) {
23
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
24
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
25
- function verb(n) { return function (v) { return step([n, v]); }; }
26
- function step(op) {
27
- if (f) throw new TypeError("Generator is already executing.");
28
- while (_) try {
29
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
30
- if (y = 0, t) op = [op[0] & 2, t.value];
31
- switch (op[0]) {
32
- case 0: case 1: t = op; break;
33
- case 4: _.label++; return { value: op[1], done: false };
34
- case 5: _.label++; y = op[1]; op = [0]; continue;
35
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
36
- default:
37
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
38
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
39
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
40
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
41
- if (t[2]) _.ops.pop();
42
- _.trys.pop(); continue;
43
- }
44
- op = body.call(thisArg, _);
45
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
46
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
47
- }
48
- };
49
- var __importDefault = (this && this.__importDefault) || function (mod) {
50
- return (mod && mod.__esModule) ? mod : { "default": mod };
51
- };
52
- Object.defineProperty(exports, "__esModule", { value: true });
53
- exports.RpcProvider = void 0;
54
- var fetchPonyfill_1 = __importDefault(require("../utils/fetchPonyfill"));
55
- var hash_1 = require("../utils/hash");
56
- var json_1 = require("../utils/json");
57
- var number_1 = require("../utils/number");
58
- var provider_1 = require("../utils/provider");
59
- var rpc_1 = require("../utils/responseParser/rpc");
60
- var stark_1 = require("../utils/stark");
61
- var utils_1 = require("./utils");
62
- var RpcProvider = /** @class */ (function () {
63
- function RpcProvider(optionsOrProvider) {
64
- var _this = this;
65
- this.responseParser = new rpc_1.RPCResponseParser();
66
- var nodeUrl = optionsOrProvider.nodeUrl, retries = optionsOrProvider.retries, headers = optionsOrProvider.headers;
67
- this.nodeUrl = nodeUrl;
68
- this.retries = retries || 200;
69
- this.headers = __assign({ 'Content-Type': 'application/json' }, headers);
70
- this.getChainId().then(function (chainId) {
71
- _this.chainId = chainId;
72
- });
73
- }
74
- RpcProvider.prototype.fetch = function (method, params) {
75
- return (0, fetchPonyfill_1.default)("".concat(this.nodeUrl, "/rpc/v0.2"), {
76
- method: 'POST',
77
- body: (0, json_1.stringify)({ method: method, jsonrpc: '2.0', params: params, id: 0 }),
78
- headers: this.headers,
79
- });
80
- };
81
- RpcProvider.prototype.errorHandler = function (error) {
82
- if (error) {
83
- var code = error.code, message = error.message;
84
- throw new Error("".concat(code, ": ").concat(message));
85
- }
86
- };
87
- RpcProvider.prototype.fetchEndpoint = function (method, params) {
88
- var _a;
89
- return __awaiter(this, void 0, void 0, function () {
90
- var rawResult, _b, error, result, error_1;
91
- return __generator(this, function (_c) {
92
- switch (_c.label) {
93
- case 0:
94
- _c.trys.push([0, 3, , 4]);
95
- return [4 /*yield*/, this.fetch(method, params)];
96
- case 1:
97
- rawResult = _c.sent();
98
- return [4 /*yield*/, rawResult.json()];
99
- case 2:
100
- _b = _c.sent(), error = _b.error, result = _b.result;
101
- this.errorHandler(error);
102
- return [2 /*return*/, result];
103
- case 3:
104
- error_1 = _c.sent();
105
- this.errorHandler((_a = error_1 === null || error_1 === void 0 ? void 0 : error_1.response) === null || _a === void 0 ? void 0 : _a.data);
106
- throw error_1;
107
- case 4: return [2 /*return*/];
108
- }
109
- });
110
- });
111
- };
112
- // Methods from Interface
113
- RpcProvider.prototype.getChainId = function () {
114
- return __awaiter(this, void 0, void 0, function () {
115
- return __generator(this, function (_a) {
116
- return [2 /*return*/, this.fetchEndpoint('starknet_chainId')];
117
- });
118
- });
119
- };
120
- // Methods from Interface
121
- RpcProvider.prototype.getBlock = function (blockIdentifier) {
122
- if (blockIdentifier === void 0) { blockIdentifier = 'pending'; }
123
- return __awaiter(this, void 0, void 0, function () {
124
- return __generator(this, function (_a) {
125
- return [2 /*return*/, this.getBlockWithTxHashes(blockIdentifier).then(this.responseParser.parseGetBlockResponse)];
126
- });
127
- });
128
- };
129
- RpcProvider.prototype.getBlockHashAndNumber = function () {
130
- return __awaiter(this, void 0, void 0, function () {
131
- return __generator(this, function (_a) {
132
- return [2 /*return*/, this.fetchEndpoint('starknet_blockHashAndNumber')];
133
- });
134
- });
135
- };
136
- RpcProvider.prototype.getBlockWithTxHashes = function (blockIdentifier) {
137
- if (blockIdentifier === void 0) { blockIdentifier = 'pending'; }
138
- return __awaiter(this, void 0, void 0, function () {
139
- var block_id;
140
- return __generator(this, function (_a) {
141
- block_id = new utils_1.Block(blockIdentifier).identifier;
142
- return [2 /*return*/, this.fetchEndpoint('starknet_getBlockWithTxHashes', { block_id: block_id })];
143
- });
144
- });
145
- };
146
- RpcProvider.prototype.getBlockWithTxs = function (blockIdentifier) {
147
- if (blockIdentifier === void 0) { blockIdentifier = 'pending'; }
148
- return __awaiter(this, void 0, void 0, function () {
149
- var block_id;
150
- return __generator(this, function (_a) {
151
- block_id = new utils_1.Block(blockIdentifier).identifier;
152
- return [2 /*return*/, this.fetchEndpoint('starknet_getBlockWithTxs', { block_id: block_id })];
153
- });
154
- });
155
- };
156
- RpcProvider.prototype.getClassHashAt = function (contractAddress, blockIdentifier) {
157
- if (blockIdentifier === void 0) { blockIdentifier = 'pending'; }
158
- return __awaiter(this, void 0, void 0, function () {
159
- var block_id;
160
- return __generator(this, function (_a) {
161
- block_id = new utils_1.Block(blockIdentifier).identifier;
162
- return [2 /*return*/, this.fetchEndpoint('starknet_getClassHashAt', {
163
- block_id: block_id,
164
- contract_address: contractAddress,
165
- })];
166
- });
167
- });
168
- };
169
- RpcProvider.prototype.getNonce = function (contractAddress, blockIdentifier) {
170
- if (blockIdentifier === void 0) { blockIdentifier = 'pending'; }
171
- return __awaiter(this, void 0, void 0, function () {
172
- var block_id;
173
- return __generator(this, function (_a) {
174
- block_id = new utils_1.Block(blockIdentifier).identifier;
175
- return [2 /*return*/, this.fetchEndpoint('starknet_getNonce', {
176
- contract_address: contractAddress,
177
- block_id: block_id,
178
- })];
179
- });
180
- });
181
- };
182
- RpcProvider.prototype.getPendingTransactions = function () {
183
- return __awaiter(this, void 0, void 0, function () {
184
- return __generator(this, function (_a) {
185
- return [2 /*return*/, this.fetchEndpoint('starknet_pendingTransactions')];
186
- });
187
- });
188
- };
189
- RpcProvider.prototype.getProtocolVersion = function () {
190
- return __awaiter(this, void 0, void 0, function () {
191
- return __generator(this, function (_a) {
192
- throw new Error('Pathfinder does not implement this rpc 0.1.0 method');
193
- });
194
- });
195
- };
196
- RpcProvider.prototype.getStateUpdate = function (blockIdentifier) {
197
- if (blockIdentifier === void 0) { blockIdentifier = 'pending'; }
198
- return __awaiter(this, void 0, void 0, function () {
199
- var block_id;
200
- return __generator(this, function (_a) {
201
- block_id = new utils_1.Block(blockIdentifier).identifier;
202
- return [2 /*return*/, this.fetchEndpoint('starknet_getStateUpdate', { block_id: block_id })];
203
- });
204
- });
205
- };
206
- RpcProvider.prototype.getStorageAt = function (contractAddress, key, blockIdentifier) {
207
- if (blockIdentifier === void 0) { blockIdentifier = 'pending'; }
208
- return __awaiter(this, void 0, void 0, function () {
209
- var parsedKey, block_id;
210
- return __generator(this, function (_a) {
211
- parsedKey = (0, number_1.toHex)((0, number_1.toBN)(key));
212
- block_id = new utils_1.Block(blockIdentifier).identifier;
213
- return [2 /*return*/, this.fetchEndpoint('starknet_getStorageAt', {
214
- contract_address: contractAddress,
215
- key: parsedKey,
216
- block_id: block_id,
217
- })];
218
- });
219
- });
220
- };
221
- // Methods from Interface
222
- RpcProvider.prototype.getTransaction = function (txHash) {
223
- return __awaiter(this, void 0, void 0, function () {
224
- return __generator(this, function (_a) {
225
- return [2 /*return*/, this.getTransactionByHash(txHash).then(this.responseParser.parseGetTransactionResponse)];
226
- });
227
- });
228
- };
229
- RpcProvider.prototype.getTransactionByHash = function (txHash) {
230
- return __awaiter(this, void 0, void 0, function () {
231
- return __generator(this, function (_a) {
232
- return [2 /*return*/, this.fetchEndpoint('starknet_getTransactionByHash', { transaction_hash: txHash })];
233
- });
234
- });
235
- };
236
- RpcProvider.prototype.getTransactionByBlockIdAndIndex = function (blockIdentifier, index) {
237
- return __awaiter(this, void 0, void 0, function () {
238
- var block_id;
239
- return __generator(this, function (_a) {
240
- block_id = new utils_1.Block(blockIdentifier).identifier;
241
- return [2 /*return*/, this.fetchEndpoint('starknet_getTransactionByBlockIdAndIndex', { block_id: block_id, index: index })];
242
- });
243
- });
244
- };
245
- RpcProvider.prototype.getTransactionReceipt = function (txHash) {
246
- return __awaiter(this, void 0, void 0, function () {
247
- return __generator(this, function (_a) {
248
- return [2 /*return*/, this.fetchEndpoint('starknet_getTransactionReceipt', { transaction_hash: txHash })];
249
- });
250
- });
251
- };
252
- RpcProvider.prototype.getClassByHash = function (classHash) {
253
- return __awaiter(this, void 0, void 0, function () {
254
- return __generator(this, function (_a) {
255
- return [2 /*return*/, this.getClass(classHash)];
256
- });
257
- });
258
- };
259
- RpcProvider.prototype.getClass = function (classHash, blockIdentifier) {
260
- if (blockIdentifier === void 0) { blockIdentifier = 'pending'; }
261
- return __awaiter(this, void 0, void 0, function () {
262
- var block_id;
263
- return __generator(this, function (_a) {
264
- block_id = new utils_1.Block(blockIdentifier).identifier;
265
- return [2 /*return*/, this.fetchEndpoint('starknet_getClass', { class_hash: classHash, block_id: block_id })];
266
- });
267
- });
268
- };
269
- RpcProvider.prototype.getClassAt = function (contractAddress, blockIdentifier) {
270
- if (blockIdentifier === void 0) { blockIdentifier = 'pending'; }
271
- return __awaiter(this, void 0, void 0, function () {
272
- var block_id;
273
- return __generator(this, function (_a) {
274
- block_id = new utils_1.Block(blockIdentifier).identifier;
275
- return [2 /*return*/, this.fetchEndpoint('starknet_getClassAt', {
276
- block_id: block_id,
277
- contract_address: contractAddress,
278
- })];
279
- });
280
- });
281
- };
282
- RpcProvider.prototype.getCode = function (_contractAddress, _blockIdentifier) {
283
- return __awaiter(this, void 0, void 0, function () {
284
- return __generator(this, function (_a) {
285
- throw new Error('RPC does not implement getCode function');
286
- });
287
- });
288
- };
289
- RpcProvider.prototype.getEstimateFee = function (invocation, invocationDetails, blockIdentifier) {
290
- if (blockIdentifier === void 0) { blockIdentifier = 'pending'; }
291
- return __awaiter(this, void 0, void 0, function () {
292
- return __generator(this, function (_a) {
293
- return [2 /*return*/, this.getInvokeEstimateFee(invocation, invocationDetails, blockIdentifier)];
294
- });
295
- });
296
- };
297
- RpcProvider.prototype.getInvokeEstimateFee = function (invocation, invocationDetails, blockIdentifier) {
298
- if (blockIdentifier === void 0) { blockIdentifier = 'pending'; }
299
- return __awaiter(this, void 0, void 0, function () {
300
- var block_id;
301
- return __generator(this, function (_a) {
302
- block_id = new utils_1.Block(blockIdentifier).identifier;
303
- return [2 /*return*/, this.fetchEndpoint('starknet_estimateFee', {
304
- request: {
305
- type: 'INVOKE',
306
- contract_address: invocation.contractAddress,
307
- calldata: (0, provider_1.parseCalldata)(invocation.calldata),
308
- signature: (0, number_1.bigNumberishArrayToHexadecimalStringArray)(invocation.signature || []),
309
- version: (0, number_1.toHex)((0, number_1.toBN)((invocationDetails === null || invocationDetails === void 0 ? void 0 : invocationDetails.version) || 0)),
310
- nonce: (0, number_1.toHex)((0, number_1.toBN)(invocationDetails.nonce)),
311
- max_fee: (0, number_1.toHex)((0, number_1.toBN)((invocationDetails === null || invocationDetails === void 0 ? void 0 : invocationDetails.maxFee) || 0)),
312
- },
313
- block_id: block_id,
314
- }).then(this.responseParser.parseFeeEstimateResponse)];
315
- });
316
- });
317
- };
318
- // TODO: Revisit after Pathfinder release with JSON-RPC v0.2.1 RPC Spec
319
- RpcProvider.prototype.getDeclareEstimateFee = function (_a, details, blockIdentifier) {
320
- var senderAddress = _a.senderAddress, contractDefinition = _a.contractDefinition, signature = _a.signature;
321
- if (blockIdentifier === void 0) { blockIdentifier = 'pending'; }
322
- return __awaiter(this, void 0, void 0, function () {
323
- var block_id;
324
- return __generator(this, function (_b) {
325
- block_id = new utils_1.Block(blockIdentifier).identifier;
326
- return [2 /*return*/, this.fetchEndpoint('starknet_estimateFee', {
327
- request: {
328
- type: 'DECLARE',
329
- contract_class: {
330
- program: contractDefinition.program,
331
- entry_points_by_type: contractDefinition.entry_points_by_type,
332
- abi: contractDefinition.abi, // rpc 2.0
333
- },
334
- sender_address: senderAddress,
335
- signature: (0, number_1.bigNumberishArrayToHexadecimalStringArray)(signature || []),
336
- version: (0, number_1.toHex)((0, number_1.toBN)((details === null || details === void 0 ? void 0 : details.version) || 0)),
337
- nonce: (0, number_1.toHex)((0, number_1.toBN)(details.nonce)),
338
- max_fee: (0, number_1.toHex)((0, number_1.toBN)((details === null || details === void 0 ? void 0 : details.maxFee) || 0)),
339
- },
340
- block_id: block_id,
341
- }).then(this.responseParser.parseFeeEstimateResponse)];
342
- });
343
- });
344
- };
345
- RpcProvider.prototype.getDeployAccountEstimateFee = function (_a, details, blockIdentifier) {
346
- var classHash = _a.classHash, constructorCalldata = _a.constructorCalldata, addressSalt = _a.addressSalt, signature = _a.signature;
347
- if (blockIdentifier === void 0) { blockIdentifier = 'pending'; }
348
- return __awaiter(this, void 0, void 0, function () {
349
- var block_id;
350
- return __generator(this, function (_b) {
351
- block_id = new utils_1.Block(blockIdentifier).identifier;
352
- return [2 /*return*/, this.fetchEndpoint('starknet_estimateFee', {
353
- request: {
354
- type: 'DEPLOY_ACCOUNT',
355
- constructor_calldata: (0, number_1.bigNumberishArrayToHexadecimalStringArray)(constructorCalldata || []),
356
- class_hash: (0, number_1.toHex)((0, number_1.toBN)(classHash)),
357
- contract_address_salt: (0, number_1.toHex)((0, number_1.toBN)(addressSalt || 0)),
358
- signature: (0, number_1.bigNumberishArrayToHexadecimalStringArray)(signature || []),
359
- version: (0, number_1.toHex)((0, number_1.toBN)((details === null || details === void 0 ? void 0 : details.version) || 0)),
360
- nonce: (0, number_1.toHex)((0, number_1.toBN)(details.nonce)),
361
- max_fee: (0, number_1.toHex)((0, number_1.toBN)((details === null || details === void 0 ? void 0 : details.maxFee) || 0)),
362
- },
363
- block_id: block_id,
364
- }).then(this.responseParser.parseFeeEstimateResponse)];
365
- });
366
- });
367
- };
368
- // TODO: Revisit after Pathfinder release with JSON-RPC v0.2.1 RPC Spec
369
- RpcProvider.prototype.declareContract = function (_a, details) {
370
- var contractDefinition = _a.contractDefinition, signature = _a.signature, senderAddress = _a.senderAddress;
371
- return __awaiter(this, void 0, void 0, function () {
372
- return __generator(this, function (_b) {
373
- return [2 /*return*/, this.fetchEndpoint('starknet_addDeclareTransaction', {
374
- declare_transaction: {
375
- contract_class: {
376
- program: contractDefinition.program,
377
- entry_points_by_type: contractDefinition.entry_points_by_type,
378
- abi: contractDefinition.abi, // rpc 2.0
379
- },
380
- type: 'DECLARE',
381
- version: (0, number_1.toHex)((0, number_1.toBN)(details.version || 0)),
382
- max_fee: (0, number_1.toHex)((0, number_1.toBN)(details.maxFee || 0)),
383
- signature: (0, number_1.bigNumberishArrayToHexadecimalStringArray)(signature || []),
384
- sender_address: senderAddress,
385
- nonce: (0, number_1.toHex)((0, number_1.toBN)(details.nonce)),
386
- },
387
- })];
388
- });
389
- });
390
- };
391
- /**
392
- * @deprecated This method wont be supported soon, use Account.deploy instead
393
- */
394
- RpcProvider.prototype.deployContract = function (_a, details) {
395
- var contract = _a.contract, constructorCalldata = _a.constructorCalldata, addressSalt = _a.addressSalt;
396
- return __awaiter(this, void 0, void 0, function () {
397
- var contractDefinition;
398
- return __generator(this, function (_b) {
399
- contractDefinition = (0, provider_1.parseContract)(contract);
400
- return [2 /*return*/, this.fetchEndpoint('starknet_addDeployTransaction', {
401
- deploy_transaction: {
402
- contract_address_salt: addressSalt !== null && addressSalt !== void 0 ? addressSalt : (0, stark_1.randomAddress)(),
403
- constructor_calldata: (0, number_1.bigNumberishArrayToHexadecimalStringArray)(constructorCalldata !== null && constructorCalldata !== void 0 ? constructorCalldata : []),
404
- contract_class: {
405
- program: contractDefinition.program,
406
- entry_points_by_type: contractDefinition.entry_points_by_type,
407
- abi: contractDefinition.abi,
408
- },
409
- type: 'DEPLOY',
410
- version: (0, number_1.toHex)((0, number_1.toBN)((details === null || details === void 0 ? void 0 : details.version) || 0)),
411
- },
412
- })];
413
- });
414
- });
415
- };
416
- RpcProvider.prototype.deployAccountContract = function (_a, details) {
417
- var classHash = _a.classHash, constructorCalldata = _a.constructorCalldata, addressSalt = _a.addressSalt, signature = _a.signature;
418
- return __awaiter(this, void 0, void 0, function () {
419
- return __generator(this, function (_b) {
420
- return [2 /*return*/, this.fetchEndpoint('starknet_addDeployAccountTransaction', {
421
- constructor_calldata: (0, number_1.bigNumberishArrayToHexadecimalStringArray)(constructorCalldata || []),
422
- class_hash: (0, number_1.toHex)((0, number_1.toBN)(classHash)),
423
- contract_address_salt: (0, number_1.toHex)((0, number_1.toBN)(addressSalt || 0)),
424
- type: 'DEPLOY',
425
- max_fee: (0, number_1.toHex)((0, number_1.toBN)(details.maxFee || 0)),
426
- version: (0, number_1.toHex)((0, number_1.toBN)(details.version || 0)),
427
- signature: (0, number_1.bigNumberishArrayToHexadecimalStringArray)(signature || []),
428
- nonce: (0, number_1.toHex)((0, number_1.toBN)(details.nonce)),
429
- })];
430
- });
431
- });
432
- };
433
- RpcProvider.prototype.invokeFunction = function (functionInvocation, details) {
434
- return __awaiter(this, void 0, void 0, function () {
435
- return __generator(this, function (_a) {
436
- return [2 /*return*/, this.fetchEndpoint('starknet_addInvokeTransaction', {
437
- invoke_transaction: {
438
- sender_address: functionInvocation.contractAddress,
439
- calldata: (0, provider_1.parseCalldata)(functionInvocation.calldata),
440
- type: 'INVOKE',
441
- max_fee: (0, number_1.toHex)((0, number_1.toBN)(details.maxFee || 0)),
442
- version: (0, number_1.toHex)((0, number_1.toBN)(details.version || 0)),
443
- signature: (0, number_1.bigNumberishArrayToHexadecimalStringArray)(functionInvocation.signature || []),
444
- nonce: (0, number_1.toHex)((0, number_1.toBN)(details.nonce)),
445
- },
446
- })];
447
- });
448
- });
449
- };
450
- // Methods from Interface
451
- RpcProvider.prototype.callContract = function (call, blockIdentifier) {
452
- if (blockIdentifier === void 0) { blockIdentifier = 'pending'; }
453
- return __awaiter(this, void 0, void 0, function () {
454
- var block_id, result;
455
- return __generator(this, function (_a) {
456
- switch (_a.label) {
457
- case 0:
458
- block_id = new utils_1.Block(blockIdentifier).identifier;
459
- return [4 /*yield*/, this.fetchEndpoint('starknet_call', {
460
- request: {
461
- contract_address: call.contractAddress,
462
- entry_point_selector: (0, hash_1.getSelectorFromName)(call.entrypoint),
463
- calldata: (0, provider_1.parseCalldata)(call.calldata),
464
- },
465
- block_id: block_id,
466
- })];
467
- case 1:
468
- result = _a.sent();
469
- return [2 /*return*/, this.responseParser.parseCallContractResponse(result)];
470
- }
471
- });
472
- });
473
- };
474
- RpcProvider.prototype.traceTransaction = function (transactionHash) {
475
- return __awaiter(this, void 0, void 0, function () {
476
- return __generator(this, function (_a) {
477
- return [2 /*return*/, this.fetchEndpoint('starknet_traceTransaction', { transaction_hash: transactionHash })];
478
- });
479
- });
480
- };
481
- RpcProvider.prototype.traceBlockTransactions = function (blockHash) {
482
- return __awaiter(this, void 0, void 0, function () {
483
- return __generator(this, function (_a) {
484
- return [2 /*return*/, this.fetchEndpoint('starknet_traceBlockTransactions', { block_hash: blockHash })];
485
- });
486
- });
487
- };
488
- RpcProvider.prototype.waitForTransaction = function (txHash, retryInterval) {
489
- if (retryInterval === void 0) { retryInterval = 8000; }
490
- return __awaiter(this, void 0, void 0, function () {
491
- var retries, onchain, successStates, errorStates, res, error, message, error, error_2;
492
- return __generator(this, function (_a) {
493
- switch (_a.label) {
494
- case 0:
495
- retries = this.retries;
496
- onchain = false;
497
- _a.label = 1;
498
- case 1:
499
- if (!!onchain) return [3 /*break*/, 7];
500
- successStates = ['ACCEPTED_ON_L1', 'ACCEPTED_ON_L2', 'PENDING'];
501
- errorStates = ['REJECTED', 'NOT_RECEIVED'];
502
- // eslint-disable-next-line no-await-in-loop
503
- return [4 /*yield*/, (0, provider_1.wait)(retryInterval)];
504
- case 2:
505
- // eslint-disable-next-line no-await-in-loop
506
- _a.sent();
507
- _a.label = 3;
508
- case 3:
509
- _a.trys.push([3, 5, , 6]);
510
- return [4 /*yield*/, this.getTransactionReceipt(txHash)];
511
- case 4:
512
- res = _a.sent();
513
- if (!('status' in res)) {
514
- error = new Error('pending transaction');
515
- throw error;
516
- }
517
- if (res.status && successStates.includes(res.status)) {
518
- onchain = true;
519
- }
520
- else if (res.status && errorStates.includes(res.status)) {
521
- message = res.status;
522
- error = new Error(message);
523
- error.response = res;
524
- throw error;
525
- }
526
- return [3 /*break*/, 6];
527
- case 5:
528
- error_2 = _a.sent();
529
- if (error_2 instanceof Error && errorStates.includes(error_2.message)) {
530
- throw error_2;
531
- }
532
- if (retries === 0) {
533
- throw new Error('waitForTransaction timedout with retries');
534
- }
535
- return [3 /*break*/, 6];
536
- case 6:
537
- retries -= 1;
538
- return [3 /*break*/, 1];
539
- case 7: return [4 /*yield*/, (0, provider_1.wait)(retryInterval)];
540
- case 8:
541
- _a.sent();
542
- return [2 /*return*/];
543
- }
544
- });
545
- });
546
- };
547
- /**
548
- * Gets the transaction count from a block.
549
- *
550
- *
551
- * @param blockIdentifier
552
- * @returns Number of transactions
553
- */
554
- RpcProvider.prototype.getTransactionCount = function (blockIdentifier) {
555
- if (blockIdentifier === void 0) { blockIdentifier = 'pending'; }
556
- return __awaiter(this, void 0, void 0, function () {
557
- var block_id;
558
- return __generator(this, function (_a) {
559
- block_id = new utils_1.Block(blockIdentifier).identifier;
560
- return [2 /*return*/, this.fetchEndpoint('starknet_getBlockTransactionCount', { block_id: block_id })];
561
- });
562
- });
563
- };
564
- /**
565
- * Gets the latest block number
566
- *
567
- *
568
- * @returns Number of the latest block
569
- */
570
- RpcProvider.prototype.getBlockNumber = function () {
571
- return __awaiter(this, void 0, void 0, function () {
572
- return __generator(this, function (_a) {
573
- return [2 /*return*/, this.fetchEndpoint('starknet_blockNumber')];
574
- });
575
- });
576
- };
577
- /**
578
- * Gets syncing status of the node
579
- *
580
- *
581
- * @returns Object with the stats data
582
- */
583
- RpcProvider.prototype.getSyncingStats = function () {
584
- return __awaiter(this, void 0, void 0, function () {
585
- return __generator(this, function (_a) {
586
- return [2 /*return*/, this.fetchEndpoint('starknet_syncing')];
587
- });
588
- });
589
- };
590
- /**
591
- * Gets all the events filtered
592
- *
593
- *
594
- * @returns events and the pagination of the events
595
- */
596
- RpcProvider.prototype.getEvents = function (eventFilter) {
597
- return __awaiter(this, void 0, void 0, function () {
598
- return __generator(this, function (_a) {
599
- return [2 /*return*/, this.fetchEndpoint('starknet_getEvents', { filter: eventFilter })];
600
- });
601
- });
602
- };
603
- return RpcProvider;
604
- }());
605
- exports.RpcProvider = RpcProvider;