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