starknet 6.1.4 → 6.2.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/dist/index.js CHANGED
@@ -53,7 +53,9 @@ __export(src_exports, {
53
53
  Provider: () => RpcProvider2,
54
54
  ProviderInterface: () => ProviderInterface,
55
55
  RPC: () => api_exports,
56
- RpcChannel: () => RpcChannel,
56
+ RPC06: () => rpc_0_6_exports,
57
+ RPC07: () => rpc_0_7_exports,
58
+ RpcChannel: () => RpcChannel2,
57
59
  RpcProvider: () => RpcProvider2,
58
60
  SIMULATION_FLAG: () => SIMULATION_FLAG,
59
61
  Signer: () => Signer,
@@ -120,7 +122,7 @@ __export(constants_exports, {
120
122
  RPC_NODES: () => RPC_NODES,
121
123
  StarknetChainId: () => StarknetChainId,
122
124
  TEXT_TO_FELT_MAX_LEN: () => TEXT_TO_FELT_MAX_LEN,
123
- TRANSACTION_VERSION: () => ETransactionVersion,
125
+ TRANSACTION_VERSION: () => ETransactionVersion4,
124
126
  TransactionHashPrefix: () => TransactionHashPrefix,
125
127
  UDC: () => UDC,
126
128
  ZERO: () => ZERO
@@ -129,6 +131,30 @@ __export(constants_exports, {
129
131
  // src/types/api/index.ts
130
132
  var api_exports = {};
131
133
  __export(api_exports, {
134
+ EBlockTag: () => EBlockTag2,
135
+ EDAMode: () => EDAMode2,
136
+ EDataAvailabilityMode: () => EDataAvailabilityMode2,
137
+ ESimulationFlag: () => ESimulationFlag2,
138
+ ETransactionExecutionStatus: () => ETransactionExecutionStatus2,
139
+ ETransactionFinalityStatus: () => ETransactionFinalityStatus2,
140
+ ETransactionStatus: () => ETransactionStatus2,
141
+ ETransactionType: () => ETransactionType2,
142
+ ETransactionVersion: () => ETransactionVersion4,
143
+ ETransactionVersion2: () => ETransactionVersion22,
144
+ ETransactionVersion3: () => ETransactionVersion32,
145
+ Errors: () => errors_exports2,
146
+ JRPC: () => jsonrpc_exports,
147
+ RPCSPEC06: () => rpcspec_0_6_exports,
148
+ RPCSPEC07: () => rpcspec_0_7_exports,
149
+ SPEC: () => components_exports2
150
+ });
151
+
152
+ // src/types/api/jsonrpc/index.ts
153
+ var jsonrpc_exports = {};
154
+
155
+ // src/types/api/rpcspec_0_6/index.ts
156
+ var rpcspec_0_6_exports = {};
157
+ __export(rpcspec_0_6_exports, {
132
158
  EBlockTag: () => EBlockTag,
133
159
  EDAMode: () => EDAMode,
134
160
  EDataAvailabilityMode: () => EDataAvailabilityMode,
@@ -141,13 +167,9 @@ __export(api_exports, {
141
167
  ETransactionVersion2: () => ETransactionVersion2,
142
168
  ETransactionVersion3: () => ETransactionVersion3,
143
169
  Errors: () => errors_exports,
144
- JRPC: () => jsonrpc_exports,
145
170
  SPEC: () => components_exports
146
171
  });
147
172
 
148
- // src/types/api/jsonrpc/index.ts
149
- var jsonrpc_exports = {};
150
-
151
173
  // src/types/api/rpcspec_0_6/errors.ts
152
174
  var errors_exports = {};
153
175
 
@@ -155,77 +177,173 @@ var errors_exports = {};
155
177
  var components_exports = {};
156
178
 
157
179
  // src/types/api/rpcspec_0_6/nonspec.ts
158
- var ETransactionType = /* @__PURE__ */ ((ETransactionType2) => {
159
- ETransactionType2["DECLARE"] = "DECLARE";
160
- ETransactionType2["DEPLOY"] = "DEPLOY";
161
- ETransactionType2["DEPLOY_ACCOUNT"] = "DEPLOY_ACCOUNT";
162
- ETransactionType2["INVOKE"] = "INVOKE";
163
- ETransactionType2["L1_HANDLER"] = "L1_HANDLER";
164
- return ETransactionType2;
180
+ var ETransactionType = /* @__PURE__ */ ((ETransactionType3) => {
181
+ ETransactionType3["DECLARE"] = "DECLARE";
182
+ ETransactionType3["DEPLOY"] = "DEPLOY";
183
+ ETransactionType3["DEPLOY_ACCOUNT"] = "DEPLOY_ACCOUNT";
184
+ ETransactionType3["INVOKE"] = "INVOKE";
185
+ ETransactionType3["L1_HANDLER"] = "L1_HANDLER";
186
+ return ETransactionType3;
165
187
  })(ETransactionType || {});
166
- var ESimulationFlag = /* @__PURE__ */ ((ESimulationFlag2) => {
167
- ESimulationFlag2["SKIP_VALIDATE"] = "SKIP_VALIDATE";
168
- ESimulationFlag2["SKIP_FEE_CHARGE"] = "SKIP_FEE_CHARGE";
169
- return ESimulationFlag2;
188
+ var ESimulationFlag = /* @__PURE__ */ ((ESimulationFlag3) => {
189
+ ESimulationFlag3["SKIP_VALIDATE"] = "SKIP_VALIDATE";
190
+ ESimulationFlag3["SKIP_FEE_CHARGE"] = "SKIP_FEE_CHARGE";
191
+ return ESimulationFlag3;
170
192
  })(ESimulationFlag || {});
171
- var ETransactionStatus = /* @__PURE__ */ ((ETransactionStatus2) => {
172
- ETransactionStatus2["RECEIVED"] = "RECEIVED";
173
- ETransactionStatus2["REJECTED"] = "REJECTED";
174
- ETransactionStatus2["ACCEPTED_ON_L2"] = "ACCEPTED_ON_L2";
175
- ETransactionStatus2["ACCEPTED_ON_L1"] = "ACCEPTED_ON_L1";
176
- return ETransactionStatus2;
193
+ var ETransactionStatus = /* @__PURE__ */ ((ETransactionStatus3) => {
194
+ ETransactionStatus3["RECEIVED"] = "RECEIVED";
195
+ ETransactionStatus3["REJECTED"] = "REJECTED";
196
+ ETransactionStatus3["ACCEPTED_ON_L2"] = "ACCEPTED_ON_L2";
197
+ ETransactionStatus3["ACCEPTED_ON_L1"] = "ACCEPTED_ON_L1";
198
+ return ETransactionStatus3;
177
199
  })(ETransactionStatus || {});
178
- var ETransactionFinalityStatus = /* @__PURE__ */ ((ETransactionFinalityStatus2) => {
179
- ETransactionFinalityStatus2["ACCEPTED_ON_L2"] = "ACCEPTED_ON_L2";
180
- ETransactionFinalityStatus2["ACCEPTED_ON_L1"] = "ACCEPTED_ON_L1";
181
- return ETransactionFinalityStatus2;
200
+ var ETransactionFinalityStatus = /* @__PURE__ */ ((ETransactionFinalityStatus3) => {
201
+ ETransactionFinalityStatus3["ACCEPTED_ON_L2"] = "ACCEPTED_ON_L2";
202
+ ETransactionFinalityStatus3["ACCEPTED_ON_L1"] = "ACCEPTED_ON_L1";
203
+ return ETransactionFinalityStatus3;
182
204
  })(ETransactionFinalityStatus || {});
183
- var ETransactionExecutionStatus = /* @__PURE__ */ ((ETransactionExecutionStatus2) => {
184
- ETransactionExecutionStatus2["SUCCEEDED"] = "SUCCEEDED";
185
- ETransactionExecutionStatus2["REVERTED"] = "REVERTED";
186
- return ETransactionExecutionStatus2;
205
+ var ETransactionExecutionStatus = /* @__PURE__ */ ((ETransactionExecutionStatus3) => {
206
+ ETransactionExecutionStatus3["SUCCEEDED"] = "SUCCEEDED";
207
+ ETransactionExecutionStatus3["REVERTED"] = "REVERTED";
208
+ return ETransactionExecutionStatus3;
187
209
  })(ETransactionExecutionStatus || {});
188
- var EBlockTag = /* @__PURE__ */ ((EBlockTag2) => {
189
- EBlockTag2["LATEST"] = "latest";
190
- EBlockTag2["PENDING"] = "pending";
191
- return EBlockTag2;
210
+ var EBlockTag = /* @__PURE__ */ ((EBlockTag3) => {
211
+ EBlockTag3["LATEST"] = "latest";
212
+ EBlockTag3["PENDING"] = "pending";
213
+ return EBlockTag3;
192
214
  })(EBlockTag || {});
193
- var EDataAvailabilityMode = /* @__PURE__ */ ((EDataAvailabilityMode2) => {
194
- EDataAvailabilityMode2["L1"] = "L1";
195
- EDataAvailabilityMode2["L2"] = "L2";
196
- return EDataAvailabilityMode2;
215
+ var EDataAvailabilityMode = /* @__PURE__ */ ((EDataAvailabilityMode3) => {
216
+ EDataAvailabilityMode3["L1"] = "L1";
217
+ EDataAvailabilityMode3["L2"] = "L2";
218
+ return EDataAvailabilityMode3;
197
219
  })(EDataAvailabilityMode || {});
198
- var EDAMode = /* @__PURE__ */ ((EDAMode3) => {
199
- EDAMode3[EDAMode3["L1"] = 0] = "L1";
200
- EDAMode3[EDAMode3["L2"] = 1] = "L2";
201
- return EDAMode3;
220
+ var EDAMode = /* @__PURE__ */ ((EDAMode4) => {
221
+ EDAMode4[EDAMode4["L1"] = 0] = "L1";
222
+ EDAMode4[EDAMode4["L2"] = 1] = "L2";
223
+ return EDAMode4;
202
224
  })(EDAMode || {});
203
- var ETransactionVersion = /* @__PURE__ */ ((ETransactionVersion4) => {
204
- ETransactionVersion4["V0"] = "0x0";
205
- ETransactionVersion4["V1"] = "0x1";
206
- ETransactionVersion4["V2"] = "0x2";
207
- ETransactionVersion4["V3"] = "0x3";
208
- ETransactionVersion4["F0"] = "0x100000000000000000000000000000000";
209
- ETransactionVersion4["F1"] = "0x100000000000000000000000000000001";
210
- ETransactionVersion4["F2"] = "0x100000000000000000000000000000002";
211
- ETransactionVersion4["F3"] = "0x100000000000000000000000000000003";
212
- return ETransactionVersion4;
225
+ var ETransactionVersion = /* @__PURE__ */ ((ETransactionVersion5) => {
226
+ ETransactionVersion5["V0"] = "0x0";
227
+ ETransactionVersion5["V1"] = "0x1";
228
+ ETransactionVersion5["V2"] = "0x2";
229
+ ETransactionVersion5["V3"] = "0x3";
230
+ ETransactionVersion5["F0"] = "0x100000000000000000000000000000000";
231
+ ETransactionVersion5["F1"] = "0x100000000000000000000000000000001";
232
+ ETransactionVersion5["F2"] = "0x100000000000000000000000000000002";
233
+ ETransactionVersion5["F3"] = "0x100000000000000000000000000000003";
234
+ return ETransactionVersion5;
213
235
  })(ETransactionVersion || {});
214
- var ETransactionVersion2 = /* @__PURE__ */ ((ETransactionVersion23) => {
215
- ETransactionVersion23["V0"] = "0x0";
216
- ETransactionVersion23["V1"] = "0x1";
217
- ETransactionVersion23["V2"] = "0x2";
218
- ETransactionVersion23["F0"] = "0x100000000000000000000000000000000";
219
- ETransactionVersion23["F1"] = "0x100000000000000000000000000000001";
220
- ETransactionVersion23["F2"] = "0x100000000000000000000000000000002";
221
- return ETransactionVersion23;
236
+ var ETransactionVersion2 = /* @__PURE__ */ ((ETransactionVersion24) => {
237
+ ETransactionVersion24["V0"] = "0x0";
238
+ ETransactionVersion24["V1"] = "0x1";
239
+ ETransactionVersion24["V2"] = "0x2";
240
+ ETransactionVersion24["F0"] = "0x100000000000000000000000000000000";
241
+ ETransactionVersion24["F1"] = "0x100000000000000000000000000000001";
242
+ ETransactionVersion24["F2"] = "0x100000000000000000000000000000002";
243
+ return ETransactionVersion24;
222
244
  })(ETransactionVersion2 || {});
223
- var ETransactionVersion3 = /* @__PURE__ */ ((ETransactionVersion33) => {
224
- ETransactionVersion33["V3"] = "0x3";
225
- ETransactionVersion33["F3"] = "0x100000000000000000000000000000003";
226
- return ETransactionVersion33;
245
+ var ETransactionVersion3 = /* @__PURE__ */ ((ETransactionVersion34) => {
246
+ ETransactionVersion34["V3"] = "0x3";
247
+ ETransactionVersion34["F3"] = "0x100000000000000000000000000000003";
248
+ return ETransactionVersion34;
227
249
  })(ETransactionVersion3 || {});
228
250
 
251
+ // src/types/api/rpcspec_0_7/index.ts
252
+ var rpcspec_0_7_exports = {};
253
+ __export(rpcspec_0_7_exports, {
254
+ EBlockTag: () => EBlockTag2,
255
+ EDAMode: () => EDAMode2,
256
+ EDataAvailabilityMode: () => EDataAvailabilityMode2,
257
+ ESimulationFlag: () => ESimulationFlag2,
258
+ ETransactionExecutionStatus: () => ETransactionExecutionStatus2,
259
+ ETransactionFinalityStatus: () => ETransactionFinalityStatus2,
260
+ ETransactionStatus: () => ETransactionStatus2,
261
+ ETransactionType: () => ETransactionType2,
262
+ ETransactionVersion: () => ETransactionVersion4,
263
+ ETransactionVersion2: () => ETransactionVersion22,
264
+ ETransactionVersion3: () => ETransactionVersion32,
265
+ Errors: () => errors_exports2,
266
+ SPEC: () => components_exports2
267
+ });
268
+
269
+ // src/types/api/rpcspec_0_7/errors.ts
270
+ var errors_exports2 = {};
271
+
272
+ // src/types/api/rpcspec_0_7/components.ts
273
+ var components_exports2 = {};
274
+
275
+ // src/types/api/rpcspec_0_7/nonspec.ts
276
+ var ETransactionType2 = /* @__PURE__ */ ((ETransactionType3) => {
277
+ ETransactionType3["DECLARE"] = "DECLARE";
278
+ ETransactionType3["DEPLOY"] = "DEPLOY";
279
+ ETransactionType3["DEPLOY_ACCOUNT"] = "DEPLOY_ACCOUNT";
280
+ ETransactionType3["INVOKE"] = "INVOKE";
281
+ ETransactionType3["L1_HANDLER"] = "L1_HANDLER";
282
+ return ETransactionType3;
283
+ })(ETransactionType2 || {});
284
+ var ESimulationFlag2 = /* @__PURE__ */ ((ESimulationFlag3) => {
285
+ ESimulationFlag3["SKIP_VALIDATE"] = "SKIP_VALIDATE";
286
+ ESimulationFlag3["SKIP_FEE_CHARGE"] = "SKIP_FEE_CHARGE";
287
+ return ESimulationFlag3;
288
+ })(ESimulationFlag2 || {});
289
+ var ETransactionStatus2 = /* @__PURE__ */ ((ETransactionStatus3) => {
290
+ ETransactionStatus3["RECEIVED"] = "RECEIVED";
291
+ ETransactionStatus3["REJECTED"] = "REJECTED";
292
+ ETransactionStatus3["ACCEPTED_ON_L2"] = "ACCEPTED_ON_L2";
293
+ ETransactionStatus3["ACCEPTED_ON_L1"] = "ACCEPTED_ON_L1";
294
+ return ETransactionStatus3;
295
+ })(ETransactionStatus2 || {});
296
+ var ETransactionFinalityStatus2 = /* @__PURE__ */ ((ETransactionFinalityStatus3) => {
297
+ ETransactionFinalityStatus3["ACCEPTED_ON_L2"] = "ACCEPTED_ON_L2";
298
+ ETransactionFinalityStatus3["ACCEPTED_ON_L1"] = "ACCEPTED_ON_L1";
299
+ return ETransactionFinalityStatus3;
300
+ })(ETransactionFinalityStatus2 || {});
301
+ var ETransactionExecutionStatus2 = /* @__PURE__ */ ((ETransactionExecutionStatus3) => {
302
+ ETransactionExecutionStatus3["SUCCEEDED"] = "SUCCEEDED";
303
+ ETransactionExecutionStatus3["REVERTED"] = "REVERTED";
304
+ return ETransactionExecutionStatus3;
305
+ })(ETransactionExecutionStatus2 || {});
306
+ var EBlockTag2 = /* @__PURE__ */ ((EBlockTag3) => {
307
+ EBlockTag3["LATEST"] = "latest";
308
+ EBlockTag3["PENDING"] = "pending";
309
+ return EBlockTag3;
310
+ })(EBlockTag2 || {});
311
+ var EDataAvailabilityMode2 = /* @__PURE__ */ ((EDataAvailabilityMode3) => {
312
+ EDataAvailabilityMode3["L1"] = "L1";
313
+ EDataAvailabilityMode3["L2"] = "L2";
314
+ return EDataAvailabilityMode3;
315
+ })(EDataAvailabilityMode2 || {});
316
+ var EDAMode2 = /* @__PURE__ */ ((EDAMode4) => {
317
+ EDAMode4[EDAMode4["L1"] = 0] = "L1";
318
+ EDAMode4[EDAMode4["L2"] = 1] = "L2";
319
+ return EDAMode4;
320
+ })(EDAMode2 || {});
321
+ var ETransactionVersion4 = /* @__PURE__ */ ((ETransactionVersion5) => {
322
+ ETransactionVersion5["V0"] = "0x0";
323
+ ETransactionVersion5["V1"] = "0x1";
324
+ ETransactionVersion5["V2"] = "0x2";
325
+ ETransactionVersion5["V3"] = "0x3";
326
+ ETransactionVersion5["F0"] = "0x100000000000000000000000000000000";
327
+ ETransactionVersion5["F1"] = "0x100000000000000000000000000000001";
328
+ ETransactionVersion5["F2"] = "0x100000000000000000000000000000002";
329
+ ETransactionVersion5["F3"] = "0x100000000000000000000000000000003";
330
+ return ETransactionVersion5;
331
+ })(ETransactionVersion4 || {});
332
+ var ETransactionVersion22 = /* @__PURE__ */ ((ETransactionVersion24) => {
333
+ ETransactionVersion24["V0"] = "0x0";
334
+ ETransactionVersion24["V1"] = "0x1";
335
+ ETransactionVersion24["V2"] = "0x2";
336
+ ETransactionVersion24["F0"] = "0x100000000000000000000000000000000";
337
+ ETransactionVersion24["F1"] = "0x100000000000000000000000000000001";
338
+ ETransactionVersion24["F2"] = "0x100000000000000000000000000000002";
339
+ return ETransactionVersion24;
340
+ })(ETransactionVersion22 || {});
341
+ var ETransactionVersion32 = /* @__PURE__ */ ((ETransactionVersion34) => {
342
+ ETransactionVersion34["V3"] = "0x3";
343
+ ETransactionVersion34["F3"] = "0x100000000000000000000000000000003";
344
+ return ETransactionVersion34;
345
+ })(ETransactionVersion32 || {});
346
+
229
347
  // src/utils/encode.ts
230
348
  var encode_exports = {};
231
349
  __export(encode_exports, {
@@ -320,11 +438,11 @@ var NetworkName = /* @__PURE__ */ ((NetworkName2) => {
320
438
  NetworkName2["SN_SEPOLIA"] = "SN_SEPOLIA";
321
439
  return NetworkName2;
322
440
  })(NetworkName || {});
323
- var StarknetChainId = /* @__PURE__ */ ((StarknetChainId5) => {
324
- StarknetChainId5["SN_MAIN"] = "0x534e5f4d41494e";
325
- StarknetChainId5["SN_GOERLI"] = "0x534e5f474f45524c49";
326
- StarknetChainId5["SN_SEPOLIA"] = "0x534e5f5345504f4c4941";
327
- return StarknetChainId5;
441
+ var StarknetChainId = /* @__PURE__ */ ((StarknetChainId6) => {
442
+ StarknetChainId6["SN_MAIN"] = "0x534e5f4d41494e";
443
+ StarknetChainId6["SN_GOERLI"] = "0x534e5f474f45524c49";
444
+ StarknetChainId6["SN_SEPOLIA"] = "0x534e5f5345504f4c4941";
445
+ return StarknetChainId6;
328
446
  })(StarknetChainId || {});
329
447
  var TransactionHashPrefix = /* @__PURE__ */ ((TransactionHashPrefix2) => {
330
448
  TransactionHashPrefix2["DECLARE"] = "0x6465636c617265";
@@ -391,6 +509,12 @@ var HttpError = class extends LibraryError {
391
509
  }
392
510
  };
393
511
 
512
+ // src/channel/rpc_0_6.ts
513
+ var rpc_0_6_exports = {};
514
+ __export(rpc_0_6_exports, {
515
+ RpcChannel: () => RpcChannel
516
+ });
517
+
394
518
  // src/types/index.ts
395
519
  var types_exports = {};
396
520
  __export(types_exports, {
@@ -2825,10 +2949,10 @@ function intDAM(dam) {
2825
2949
  function toTransactionVersion(defaultVersion, providedVersion) {
2826
2950
  const providedVersion0xs = providedVersion ? toHex(providedVersion) : void 0;
2827
2951
  const defaultVersion0xs = toHex(defaultVersion);
2828
- if (providedVersion && !Object.values(ETransactionVersion).includes(providedVersion0xs)) {
2952
+ if (providedVersion && !Object.values(ETransactionVersion4).includes(providedVersion0xs)) {
2829
2953
  throw Error(`providedVersion ${providedVersion} is not ETransactionVersion`);
2830
2954
  }
2831
- if (!Object.values(ETransactionVersion).includes(defaultVersion0xs)) {
2955
+ if (!Object.values(ETransactionVersion4).includes(defaultVersion0xs)) {
2832
2956
  throw Error(`defaultVersion ${defaultVersion} is not ETransactionVersion`);
2833
2957
  }
2834
2958
  return providedVersion ? providedVersion0xs : defaultVersion0xs;
@@ -3112,11 +3236,11 @@ var RpcChannel = class {
3112
3236
  requestId;
3113
3237
  blockIdentifier;
3114
3238
  chainId;
3115
- speckVersion;
3239
+ specVersion;
3116
3240
  waitMode;
3117
3241
  // behave like web2 rpc and return when tx is processed
3118
3242
  constructor(optionsOrProvider) {
3119
- const { nodeUrl, retries, headers, blockIdentifier, chainId, waitMode } = optionsOrProvider || {};
3243
+ const { nodeUrl, retries, headers, blockIdentifier, chainId, specVersion, waitMode } = optionsOrProvider || {};
3120
3244
  if (Object.values(NetworkName).includes(nodeUrl)) {
3121
3245
  this.nodeUrl = getDefaultNodeUrl(nodeUrl, optionsOrProvider?.default);
3122
3246
  } else if (nodeUrl) {
@@ -3128,6 +3252,7 @@ var RpcChannel = class {
3128
3252
  this.headers = { ...defaultOptions.headers, ...headers };
3129
3253
  this.blockIdentifier = blockIdentifier || defaultOptions.blockIdentifier;
3130
3254
  this.chainId = chainId;
3255
+ this.specVersion = specVersion;
3131
3256
  this.waitMode = waitMode || false;
3132
3257
  this.requestId = 0;
3133
3258
  }
@@ -3176,8 +3301,8 @@ var RpcChannel = class {
3176
3301
  return this.chainId;
3177
3302
  }
3178
3303
  async getSpecVersion() {
3179
- this.speckVersion ??= await this.fetchEndpoint("starknet_specVersion");
3180
- return this.speckVersion;
3304
+ this.specVersion ??= await this.fetchEndpoint("starknet_specVersion");
3305
+ return this.specVersion;
3181
3306
  }
3182
3307
  getNonceForAddress(contractAddress, blockIdentifier = this.blockIdentifier) {
3183
3308
  const contract_address = toHex(contractAddress);
@@ -3261,9 +3386,9 @@ var RpcChannel = class {
3261
3386
  const block_id = new Block(blockIdentifier).identifier;
3262
3387
  const simulationFlags = [];
3263
3388
  if (skipValidate)
3264
- simulationFlags.push(api_exports.ESimulationFlag.SKIP_VALIDATE);
3389
+ simulationFlags.push(rpcspec_0_6_exports.ESimulationFlag.SKIP_VALIDATE);
3265
3390
  if (skipFeeCharge)
3266
- simulationFlags.push(api_exports.ESimulationFlag.SKIP_FEE_CHARGE);
3391
+ simulationFlags.push(rpcspec_0_6_exports.ESimulationFlag.SKIP_FEE_CHARGE);
3267
3392
  return this.fetchEndpoint("starknet_simulateTransactions", {
3268
3393
  block_id,
3269
3394
  transactions: invocations.map((it) => this.buildTransaction(it)),
@@ -3277,15 +3402,15 @@ var RpcChannel = class {
3277
3402
  let isErrorState = false;
3278
3403
  const retryInterval = options?.retryInterval ?? 5e3;
3279
3404
  const errorStates = options?.errorStates ?? [
3280
- api_exports.ETransactionStatus.REJECTED
3405
+ rpcspec_0_6_exports.ETransactionStatus.REJECTED
3281
3406
  // TODO: commented out to preserve the long-standing behavior of "reverted" not being treated as an error by default
3282
3407
  // should decide which behavior to keep in the future
3283
3408
  // RPC.ETransactionExecutionStatus.REVERTED,
3284
3409
  ];
3285
3410
  const successStates = options?.successStates ?? [
3286
- api_exports.ETransactionExecutionStatus.SUCCEEDED,
3287
- api_exports.ETransactionStatus.ACCEPTED_ON_L2,
3288
- api_exports.ETransactionStatus.ACCEPTED_ON_L1
3411
+ rpcspec_0_6_exports.ETransactionExecutionStatus.SUCCEEDED,
3412
+ rpcspec_0_6_exports.ETransactionStatus.ACCEPTED_ON_L2,
3413
+ rpcspec_0_6_exports.ETransactionStatus.ACCEPTED_ON_L1
3289
3414
  ];
3290
3415
  let txStatus;
3291
3416
  while (!onchain) {
@@ -3368,9 +3493,9 @@ var RpcChannel = class {
3368
3493
  async getEstimateFee(invocations, { blockIdentifier = this.blockIdentifier, skipValidate = true }) {
3369
3494
  const block_id = new Block(blockIdentifier).identifier;
3370
3495
  let flags = {};
3371
- if (isVersion("0.6", await this.getSpecVersion())) {
3496
+ if (!isVersion("0.5", await this.getSpecVersion())) {
3372
3497
  flags = {
3373
- simulation_flags: skipValidate ? [api_exports.ESimulationFlag.SKIP_VALIDATE] : []
3498
+ simulation_flags: skipValidate ? [rpcspec_0_6_exports.ESimulationFlag.SKIP_VALIDATE] : []
3374
3499
  };
3375
3500
  }
3376
3501
  return this.fetchEndpoint("starknet_estimateFee", {
@@ -3386,9 +3511,9 @@ var RpcChannel = class {
3386
3511
  invoke_transaction: {
3387
3512
  sender_address: functionInvocation.contractAddress,
3388
3513
  calldata: CallData.toHex(functionInvocation.calldata),
3389
- type: api_exports.ETransactionType.INVOKE,
3514
+ type: rpcspec_0_6_exports.ETransactionType.INVOKE,
3390
3515
  max_fee: toHex(details.maxFee || 0),
3391
- version: "0x1" /* V1 */,
3516
+ version: rpcspec_0_6_exports.ETransactionVersion.V1,
3392
3517
  signature: signatureToHexArray(functionInvocation.signature),
3393
3518
  nonce: toHex(details.nonce)
3394
3519
  }
@@ -3396,10 +3521,10 @@ var RpcChannel = class {
3396
3521
  } else {
3397
3522
  promise = this.fetchEndpoint("starknet_addInvokeTransaction", {
3398
3523
  invoke_transaction: {
3399
- type: api_exports.ETransactionType.INVOKE,
3524
+ type: rpcspec_0_6_exports.ETransactionType.INVOKE,
3400
3525
  sender_address: functionInvocation.contractAddress,
3401
3526
  calldata: CallData.toHex(functionInvocation.calldata),
3402
- version: "0x3" /* V3 */,
3527
+ version: rpcspec_0_6_exports.ETransactionVersion.V3,
3403
3528
  signature: signatureToHexArray(functionInvocation.signature),
3404
3529
  nonce: toHex(details.nonce),
3405
3530
  resource_bounds: details.resourceBounds,
@@ -3418,13 +3543,13 @@ var RpcChannel = class {
3418
3543
  if (!isSierra(contract) && !isV3Tx(details)) {
3419
3544
  promise = this.fetchEndpoint("starknet_addDeclareTransaction", {
3420
3545
  declare_transaction: {
3421
- type: api_exports.ETransactionType.DECLARE,
3546
+ type: rpcspec_0_6_exports.ETransactionType.DECLARE,
3422
3547
  contract_class: {
3423
3548
  program: contract.program,
3424
3549
  entry_points_by_type: contract.entry_points_by_type,
3425
3550
  abi: contract.abi
3426
3551
  },
3427
- version: "0x1" /* V1 */,
3552
+ version: rpcspec_0_6_exports.ETransactionVersion.V1,
3428
3553
  max_fee: toHex(details.maxFee || 0),
3429
3554
  signature: signatureToHexArray(signature),
3430
3555
  sender_address: senderAddress,
@@ -3434,7 +3559,7 @@ var RpcChannel = class {
3434
3559
  } else if (isSierra(contract) && !isV3Tx(details)) {
3435
3560
  promise = this.fetchEndpoint("starknet_addDeclareTransaction", {
3436
3561
  declare_transaction: {
3437
- type: api_exports.ETransactionType.DECLARE,
3562
+ type: rpcspec_0_6_exports.ETransactionType.DECLARE,
3438
3563
  contract_class: {
3439
3564
  sierra_program: decompressProgram(contract.sierra_program),
3440
3565
  contract_class_version: contract.contract_class_version,
@@ -3442,7 +3567,7 @@ var RpcChannel = class {
3442
3567
  abi: contract.abi
3443
3568
  },
3444
3569
  compiled_class_hash: compiledClassHash || "",
3445
- version: "0x2" /* V2 */,
3570
+ version: rpcspec_0_6_exports.ETransactionVersion.V2,
3446
3571
  max_fee: toHex(details.maxFee || 0),
3447
3572
  signature: signatureToHexArray(signature),
3448
3573
  sender_address: senderAddress,
@@ -3452,10 +3577,10 @@ var RpcChannel = class {
3452
3577
  } else if (isSierra(contract) && isV3Tx(details)) {
3453
3578
  promise = this.fetchEndpoint("starknet_addDeclareTransaction", {
3454
3579
  declare_transaction: {
3455
- type: api_exports.ETransactionType.DECLARE,
3580
+ type: rpcspec_0_6_exports.ETransactionType.DECLARE,
3456
3581
  sender_address: senderAddress,
3457
3582
  compiled_class_hash: compiledClassHash || "",
3458
- version: "0x3" /* V3 */,
3583
+ version: rpcspec_0_6_exports.ETransactionVersion.V3,
3459
3584
  signature: signatureToHexArray(signature),
3460
3585
  nonce: toHex(details.nonce),
3461
3586
  contract_class: {
@@ -3485,9 +3610,9 @@ var RpcChannel = class {
3485
3610
  constructor_calldata: CallData.toHex(constructorCalldata || []),
3486
3611
  class_hash: toHex(classHash),
3487
3612
  contract_address_salt: toHex(addressSalt || 0),
3488
- type: api_exports.ETransactionType.DEPLOY_ACCOUNT,
3613
+ type: rpcspec_0_6_exports.ETransactionType.DEPLOY_ACCOUNT,
3489
3614
  max_fee: toHex(details.maxFee || 0),
3490
- version: "0x1" /* V1 */,
3615
+ version: rpcspec_0_6_exports.ETransactionVersion.V1,
3491
3616
  signature: signatureToHexArray(signature),
3492
3617
  nonce: toHex(details.nonce)
3493
3618
  }
@@ -3495,8 +3620,8 @@ var RpcChannel = class {
3495
3620
  } else {
3496
3621
  promise = this.fetchEndpoint("starknet_addDeployAccountTransaction", {
3497
3622
  deploy_account_transaction: {
3498
- type: api_exports.ETransactionType.DEPLOY_ACCOUNT,
3499
- version: "0x3" /* V3 */,
3623
+ type: rpcspec_0_6_exports.ETransactionType.DEPLOY_ACCOUNT,
3624
+ version: rpcspec_0_6_exports.ETransactionVersion.V3,
3500
3625
  signature: signatureToHexArray(signature),
3501
3626
  nonce: toHex(details.nonce),
3502
3627
  contract_address_salt: toHex(addressSalt || 0),
@@ -3579,7 +3704,7 @@ var RpcChannel = class {
3579
3704
  if (invocation.type === "INVOKE_FUNCTION" /* INVOKE */) {
3580
3705
  return {
3581
3706
  // v0 v1 v3
3582
- type: api_exports.ETransactionType.INVOKE,
3707
+ type: rpcspec_0_6_exports.ETransactionType.INVOKE,
3583
3708
  // TODO: Diff between sequencer and rpc invoke type
3584
3709
  sender_address: invocation.contractAddress,
3585
3710
  calldata: CallData.toHex(invocation.calldata),
@@ -3625,106 +3750,645 @@ var RpcChannel = class {
3625
3750
  }
3626
3751
  };
3627
3752
 
3628
- // src/utils/responseParser/rpc.ts
3629
- var RPCResponseParser = class {
3630
- parseGetBlockResponse(res) {
3631
- return { status: "PENDING", ...res };
3632
- }
3633
- parseTransactionReceipt(res) {
3634
- if ("actual_fee" in res && typeof res.actual_fee === "string") {
3635
- return {
3636
- ...res,
3637
- actual_fee: {
3638
- amount: res.actual_fee,
3639
- unit: "FRI"
3640
- }
3641
- };
3753
+ // src/channel/rpc_0_7.ts
3754
+ var rpc_0_7_exports = {};
3755
+ __export(rpc_0_7_exports, {
3756
+ RpcChannel: () => RpcChannel2
3757
+ });
3758
+ var defaultOptions2 = {
3759
+ headers: { "Content-Type": "application/json" },
3760
+ blockIdentifier: "pending" /* pending */,
3761
+ retries: 200
3762
+ };
3763
+ var RpcChannel2 = class {
3764
+ nodeUrl;
3765
+ headers;
3766
+ retries;
3767
+ requestId;
3768
+ blockIdentifier;
3769
+ chainId;
3770
+ speckVersion;
3771
+ waitMode;
3772
+ // behave like web2 rpc and return when tx is processed
3773
+ constructor(optionsOrProvider) {
3774
+ const { nodeUrl, retries, headers, blockIdentifier, chainId, waitMode } = optionsOrProvider || {};
3775
+ if (Object.values(NetworkName).includes(nodeUrl)) {
3776
+ this.nodeUrl = getDefaultNodeUrl(nodeUrl, optionsOrProvider?.default);
3777
+ } else if (nodeUrl) {
3778
+ this.nodeUrl = nodeUrl;
3779
+ } else {
3780
+ this.nodeUrl = getDefaultNodeUrl(void 0, optionsOrProvider?.default);
3642
3781
  }
3643
- return res;
3782
+ this.retries = retries || defaultOptions2.retries;
3783
+ this.headers = { ...defaultOptions2.headers, ...headers };
3784
+ this.blockIdentifier = blockIdentifier || defaultOptions2.blockIdentifier;
3785
+ this.chainId = chainId;
3786
+ this.waitMode = waitMode || false;
3787
+ this.requestId = 0;
3644
3788
  }
3645
- parseFeeEstimateResponse(res) {
3646
- const val = res[0];
3647
- return {
3648
- overall_fee: toBigInt(val.overall_fee),
3649
- gas_consumed: toBigInt(val.gas_consumed),
3650
- gas_price: toBigInt(val.gas_price),
3651
- unit: val.unit,
3652
- suggestedMaxFee: estimatedFeeToMaxFee(val.overall_fee),
3653
- resourceBounds: estimateFeeToBounds(val)
3789
+ fetch(method, params, id = 0) {
3790
+ const rpcRequestBody = {
3791
+ id,
3792
+ jsonrpc: "2.0",
3793
+ method,
3794
+ ...params && { params }
3654
3795
  };
3655
- }
3656
- parseFeeEstimateBulkResponse(res) {
3657
- return res.map((val) => ({
3658
- overall_fee: toBigInt(val.overall_fee),
3659
- gas_consumed: toBigInt(val.gas_consumed),
3660
- gas_price: toBigInt(val.gas_price),
3661
- unit: val.unit,
3662
- suggestedMaxFee: estimatedFeeToMaxFee(val.overall_fee),
3663
- resourceBounds: estimateFeeToBounds(val)
3664
- }));
3665
- }
3666
- parseSimulateTransactionResponse(res) {
3667
- return res.map((it) => {
3668
- return {
3669
- ...it,
3670
- suggestedMaxFee: estimatedFeeToMaxFee(BigInt(it.fee_estimation.overall_fee)),
3671
- resourceBounds: estimateFeeToBounds(it.fee_estimation)
3672
- };
3796
+ return fetchPonyfill_default(this.nodeUrl, {
3797
+ method: "POST",
3798
+ body: stringify2(rpcRequestBody),
3799
+ headers: this.headers
3673
3800
  });
3674
3801
  }
3675
- parseContractClassResponse(res) {
3676
- return {
3677
- ...res,
3678
- abi: typeof res.abi === "string" ? JSON.parse(res.abi) : res.abi
3679
- };
3680
- }
3681
- };
3682
-
3683
- // src/provider/rpc.ts
3684
- var RpcProvider = class {
3685
- responseParser = new RPCResponseParser();
3686
- channel;
3687
- constructor(optionsOrProvider) {
3688
- if (optionsOrProvider && "channel" in optionsOrProvider) {
3689
- this.channel = optionsOrProvider.channel;
3690
- } else {
3691
- this.channel = new RpcChannel({ ...optionsOrProvider, waitMode: false });
3802
+ errorHandler(method, params, rpcError, otherError) {
3803
+ if (rpcError) {
3804
+ const { code, message, data } = rpcError;
3805
+ throw new LibraryError(
3806
+ `RPC: ${method} with params ${stringify2(params, null, 2)}
3807
+
3808
+ ${code}: ${message}: ${stringify2(data)}`
3809
+ );
3810
+ }
3811
+ if (otherError instanceof LibraryError) {
3812
+ throw otherError;
3813
+ }
3814
+ if (otherError) {
3815
+ throw Error(otherError.message);
3692
3816
  }
3693
3817
  }
3694
- fetch(method, params, id = 0) {
3695
- return this.channel.fetch(method, params, id);
3818
+ async fetchEndpoint(method, params) {
3819
+ try {
3820
+ const rawResult = await this.fetch(method, params, this.requestId += 1);
3821
+ const { error, result } = await rawResult.json();
3822
+ this.errorHandler(method, params, error);
3823
+ return result;
3824
+ } catch (error) {
3825
+ this.errorHandler(method, params, error?.response?.data, error);
3826
+ throw error;
3827
+ }
3696
3828
  }
3697
3829
  async getChainId() {
3698
- return this.channel.getChainId();
3830
+ this.chainId ??= await this.fetchEndpoint("starknet_chainId");
3831
+ return this.chainId;
3699
3832
  }
3700
3833
  async getSpecVersion() {
3701
- return this.channel.getSpecVersion();
3702
- }
3703
- async getNonceForAddress(contractAddress, blockIdentifier) {
3704
- return this.channel.getNonceForAddress(contractAddress, blockIdentifier);
3834
+ this.speckVersion ??= await this.fetchEndpoint("starknet_specVersion");
3835
+ return this.speckVersion;
3705
3836
  }
3706
- async getBlock(blockIdentifier) {
3707
- return this.channel.getBlockWithTxHashes(blockIdentifier).then(this.responseParser.parseGetBlockResponse);
3837
+ getNonceForAddress(contractAddress, blockIdentifier = this.blockIdentifier) {
3838
+ const contract_address = toHex(contractAddress);
3839
+ const block_id = new Block(blockIdentifier).identifier;
3840
+ return this.fetchEndpoint("starknet_getNonce", {
3841
+ contract_address,
3842
+ block_id
3843
+ });
3708
3844
  }
3709
3845
  /**
3710
3846
  * Get the most recent accepted block hash and number
3711
3847
  */
3712
- async getBlockLatestAccepted() {
3713
- return this.channel.getBlockLatestAccepted();
3848
+ getBlockLatestAccepted() {
3849
+ return this.fetchEndpoint("starknet_blockHashAndNumber");
3714
3850
  }
3715
3851
  /**
3716
3852
  * Get the most recent accepted block number
3717
3853
  * redundant use getBlockLatestAccepted();
3718
3854
  * @returns Number of the latest block
3719
3855
  */
3720
- async getBlockNumber() {
3721
- return this.channel.getBlockNumber();
3856
+ getBlockNumber() {
3857
+ return this.fetchEndpoint("starknet_blockNumber");
3722
3858
  }
3723
- async getBlockWithTxHashes(blockIdentifier) {
3724
- return this.channel.getBlockWithTxHashes(blockIdentifier);
3859
+ getBlockWithTxHashes(blockIdentifier = this.blockIdentifier) {
3860
+ const block_id = new Block(blockIdentifier).identifier;
3861
+ return this.fetchEndpoint("starknet_getBlockWithTxHashes", { block_id });
3725
3862
  }
3726
- async getBlockWithTxs(blockIdentifier) {
3727
- return this.channel.getBlockWithTxs(blockIdentifier);
3863
+ getBlockWithTxs(blockIdentifier = this.blockIdentifier) {
3864
+ const block_id = new Block(blockIdentifier).identifier;
3865
+ return this.fetchEndpoint("starknet_getBlockWithTxs", { block_id });
3866
+ }
3867
+ getBlockWithReceipts(blockIdentifier = this.blockIdentifier) {
3868
+ const block_id = new Block(blockIdentifier).identifier;
3869
+ return this.fetchEndpoint("starknet_getBlockWithReceipts", { block_id });
3870
+ }
3871
+ getBlockStateUpdate(blockIdentifier = this.blockIdentifier) {
3872
+ const block_id = new Block(blockIdentifier).identifier;
3873
+ return this.fetchEndpoint("starknet_getStateUpdate", { block_id });
3874
+ }
3875
+ getBlockTransactionsTraces(blockIdentifier = this.blockIdentifier) {
3876
+ const block_id = new Block(blockIdentifier).identifier;
3877
+ return this.fetchEndpoint("starknet_traceBlockTransactions", { block_id });
3878
+ }
3879
+ getBlockTransactionCount(blockIdentifier = this.blockIdentifier) {
3880
+ const block_id = new Block(blockIdentifier).identifier;
3881
+ return this.fetchEndpoint("starknet_getBlockTransactionCount", { block_id });
3882
+ }
3883
+ getTransactionByHash(txHash) {
3884
+ const transaction_hash = toHex(txHash);
3885
+ return this.fetchEndpoint("starknet_getTransactionByHash", {
3886
+ transaction_hash
3887
+ });
3888
+ }
3889
+ getTransactionByBlockIdAndIndex(blockIdentifier, index) {
3890
+ const block_id = new Block(blockIdentifier).identifier;
3891
+ return this.fetchEndpoint("starknet_getTransactionByBlockIdAndIndex", { block_id, index });
3892
+ }
3893
+ getTransactionReceipt(txHash) {
3894
+ const transaction_hash = toHex(txHash);
3895
+ return this.fetchEndpoint("starknet_getTransactionReceipt", { transaction_hash });
3896
+ }
3897
+ getTransactionTrace(txHash) {
3898
+ const transaction_hash = toHex(txHash);
3899
+ return this.fetchEndpoint("starknet_traceTransaction", { transaction_hash });
3900
+ }
3901
+ /**
3902
+ * Get the status of a transaction
3903
+ */
3904
+ getTransactionStatus(transactionHash) {
3905
+ const transaction_hash = toHex(transactionHash);
3906
+ return this.fetchEndpoint("starknet_getTransactionStatus", { transaction_hash });
3907
+ }
3908
+ /**
3909
+ * @param invocations AccountInvocations
3910
+ * @param simulateTransactionOptions blockIdentifier and flags to skip validation and fee charge<br/>
3911
+ * - blockIdentifier<br/>
3912
+ * - skipValidate (default false)<br/>
3913
+ * - skipFeeCharge (default true)<br/>
3914
+ */
3915
+ simulateTransaction(invocations, {
3916
+ blockIdentifier = this.blockIdentifier,
3917
+ skipValidate = true,
3918
+ skipFeeCharge = true
3919
+ } = {}) {
3920
+ const block_id = new Block(blockIdentifier).identifier;
3921
+ const simulationFlags = [];
3922
+ if (skipValidate)
3923
+ simulationFlags.push(rpcspec_0_7_exports.ESimulationFlag.SKIP_VALIDATE);
3924
+ if (skipFeeCharge)
3925
+ simulationFlags.push(rpcspec_0_7_exports.ESimulationFlag.SKIP_FEE_CHARGE);
3926
+ return this.fetchEndpoint("starknet_simulateTransactions", {
3927
+ block_id,
3928
+ transactions: invocations.map((it) => this.buildTransaction(it)),
3929
+ simulation_flags: simulationFlags
3930
+ });
3931
+ }
3932
+ async waitForTransaction(txHash, options) {
3933
+ const transactionHash = toHex(txHash);
3934
+ let { retries } = this;
3935
+ let onchain = false;
3936
+ let isErrorState = false;
3937
+ const retryInterval = options?.retryInterval ?? 5e3;
3938
+ const errorStates = options?.errorStates ?? [
3939
+ rpcspec_0_7_exports.ETransactionStatus.REJECTED
3940
+ // TODO: commented out to preserve the long-standing behavior of "reverted" not being treated as an error by default
3941
+ // should decide which behavior to keep in the future
3942
+ // RPC.ETransactionExecutionStatus.REVERTED,
3943
+ ];
3944
+ const successStates = options?.successStates ?? [
3945
+ rpcspec_0_7_exports.ETransactionExecutionStatus.SUCCEEDED,
3946
+ rpcspec_0_7_exports.ETransactionStatus.ACCEPTED_ON_L2,
3947
+ rpcspec_0_7_exports.ETransactionStatus.ACCEPTED_ON_L1
3948
+ ];
3949
+ let txStatus;
3950
+ while (!onchain) {
3951
+ await wait(retryInterval);
3952
+ try {
3953
+ txStatus = await this.getTransactionStatus(transactionHash);
3954
+ const executionStatus = txStatus.execution_status;
3955
+ const finalityStatus = txStatus.finality_status;
3956
+ if (!finalityStatus) {
3957
+ const error = new Error("waiting for transaction status");
3958
+ throw error;
3959
+ }
3960
+ if (errorStates.includes(executionStatus) || errorStates.includes(finalityStatus)) {
3961
+ const message = `${executionStatus}: ${finalityStatus}`;
3962
+ const error = new Error(message);
3963
+ error.response = txStatus;
3964
+ isErrorState = true;
3965
+ throw error;
3966
+ } else if (successStates.includes(executionStatus) || successStates.includes(finalityStatus)) {
3967
+ onchain = true;
3968
+ }
3969
+ } catch (error) {
3970
+ if (error instanceof Error && isErrorState) {
3971
+ throw error;
3972
+ }
3973
+ if (retries <= 0) {
3974
+ throw new Error(`waitForTransaction timed-out with retries ${this.retries}`);
3975
+ }
3976
+ }
3977
+ retries -= 1;
3978
+ }
3979
+ let txReceipt = null;
3980
+ while (txReceipt === null) {
3981
+ try {
3982
+ txReceipt = await this.getTransactionReceipt(transactionHash);
3983
+ } catch (error) {
3984
+ if (retries <= 0) {
3985
+ throw new Error(`waitForTransaction timed-out with retries ${this.retries}`);
3986
+ }
3987
+ }
3988
+ retries -= 1;
3989
+ await wait(retryInterval);
3990
+ }
3991
+ return txReceipt;
3992
+ }
3993
+ getStorageAt(contractAddress, key, blockIdentifier = this.blockIdentifier) {
3994
+ const contract_address = toHex(contractAddress);
3995
+ const parsedKey = toStorageKey(key);
3996
+ const block_id = new Block(blockIdentifier).identifier;
3997
+ return this.fetchEndpoint("starknet_getStorageAt", {
3998
+ contract_address,
3999
+ key: parsedKey,
4000
+ block_id
4001
+ });
4002
+ }
4003
+ getClassHashAt(contractAddress, blockIdentifier = this.blockIdentifier) {
4004
+ const contract_address = toHex(contractAddress);
4005
+ const block_id = new Block(blockIdentifier).identifier;
4006
+ return this.fetchEndpoint("starknet_getClassHashAt", {
4007
+ block_id,
4008
+ contract_address
4009
+ });
4010
+ }
4011
+ getClass(classHash, blockIdentifier = this.blockIdentifier) {
4012
+ const class_hash = toHex(classHash);
4013
+ const block_id = new Block(blockIdentifier).identifier;
4014
+ return this.fetchEndpoint("starknet_getClass", {
4015
+ class_hash,
4016
+ block_id
4017
+ });
4018
+ }
4019
+ getClassAt(contractAddress, blockIdentifier = this.blockIdentifier) {
4020
+ const contract_address = toHex(contractAddress);
4021
+ const block_id = new Block(blockIdentifier).identifier;
4022
+ return this.fetchEndpoint("starknet_getClassAt", {
4023
+ block_id,
4024
+ contract_address
4025
+ });
4026
+ }
4027
+ async getEstimateFee(invocations, { blockIdentifier = this.blockIdentifier, skipValidate = true }) {
4028
+ const block_id = new Block(blockIdentifier).identifier;
4029
+ let flags = {};
4030
+ if (!isVersion("0.5", await this.getSpecVersion())) {
4031
+ flags = {
4032
+ simulation_flags: skipValidate ? [rpcspec_0_7_exports.ESimulationFlag.SKIP_VALIDATE] : []
4033
+ };
4034
+ }
4035
+ return this.fetchEndpoint("starknet_estimateFee", {
4036
+ request: invocations.map((it) => this.buildTransaction(it, "fee")),
4037
+ block_id,
4038
+ ...flags
4039
+ });
4040
+ }
4041
+ async invoke(functionInvocation, details) {
4042
+ let promise;
4043
+ if (!isV3Tx(details)) {
4044
+ promise = this.fetchEndpoint("starknet_addInvokeTransaction", {
4045
+ invoke_transaction: {
4046
+ sender_address: functionInvocation.contractAddress,
4047
+ calldata: CallData.toHex(functionInvocation.calldata),
4048
+ type: rpcspec_0_7_exports.ETransactionType.INVOKE,
4049
+ max_fee: toHex(details.maxFee || 0),
4050
+ version: rpcspec_0_7_exports.ETransactionVersion.V1,
4051
+ signature: signatureToHexArray(functionInvocation.signature),
4052
+ nonce: toHex(details.nonce)
4053
+ }
4054
+ });
4055
+ } else {
4056
+ promise = this.fetchEndpoint("starknet_addInvokeTransaction", {
4057
+ invoke_transaction: {
4058
+ type: rpcspec_0_7_exports.ETransactionType.INVOKE,
4059
+ sender_address: functionInvocation.contractAddress,
4060
+ calldata: CallData.toHex(functionInvocation.calldata),
4061
+ version: rpcspec_0_7_exports.ETransactionVersion.V3,
4062
+ signature: signatureToHexArray(functionInvocation.signature),
4063
+ nonce: toHex(details.nonce),
4064
+ resource_bounds: details.resourceBounds,
4065
+ tip: toHex(details.tip),
4066
+ paymaster_data: details.paymasterData.map((it) => toHex(it)),
4067
+ account_deployment_data: details.accountDeploymentData.map((it) => toHex(it)),
4068
+ nonce_data_availability_mode: details.nonceDataAvailabilityMode,
4069
+ fee_data_availability_mode: details.feeDataAvailabilityMode
4070
+ }
4071
+ });
4072
+ }
4073
+ return this.waitMode ? this.waitForTransaction((await promise).transaction_hash) : promise;
4074
+ }
4075
+ async declare({ contract, signature, senderAddress, compiledClassHash }, details) {
4076
+ let promise;
4077
+ if (!isSierra(contract) && !isV3Tx(details)) {
4078
+ promise = this.fetchEndpoint("starknet_addDeclareTransaction", {
4079
+ declare_transaction: {
4080
+ type: rpcspec_0_7_exports.ETransactionType.DECLARE,
4081
+ contract_class: {
4082
+ program: contract.program,
4083
+ entry_points_by_type: contract.entry_points_by_type,
4084
+ abi: contract.abi
4085
+ },
4086
+ version: rpcspec_0_7_exports.ETransactionVersion.V1,
4087
+ max_fee: toHex(details.maxFee || 0),
4088
+ signature: signatureToHexArray(signature),
4089
+ sender_address: senderAddress,
4090
+ nonce: toHex(details.nonce)
4091
+ }
4092
+ });
4093
+ } else if (isSierra(contract) && !isV3Tx(details)) {
4094
+ promise = this.fetchEndpoint("starknet_addDeclareTransaction", {
4095
+ declare_transaction: {
4096
+ type: rpcspec_0_7_exports.ETransactionType.DECLARE,
4097
+ contract_class: {
4098
+ sierra_program: decompressProgram(contract.sierra_program),
4099
+ contract_class_version: contract.contract_class_version,
4100
+ entry_points_by_type: contract.entry_points_by_type,
4101
+ abi: contract.abi
4102
+ },
4103
+ compiled_class_hash: compiledClassHash || "",
4104
+ version: rpcspec_0_7_exports.ETransactionVersion.V2,
4105
+ max_fee: toHex(details.maxFee || 0),
4106
+ signature: signatureToHexArray(signature),
4107
+ sender_address: senderAddress,
4108
+ nonce: toHex(details.nonce)
4109
+ }
4110
+ });
4111
+ } else if (isSierra(contract) && isV3Tx(details)) {
4112
+ promise = this.fetchEndpoint("starknet_addDeclareTransaction", {
4113
+ declare_transaction: {
4114
+ type: rpcspec_0_7_exports.ETransactionType.DECLARE,
4115
+ sender_address: senderAddress,
4116
+ compiled_class_hash: compiledClassHash || "",
4117
+ version: rpcspec_0_7_exports.ETransactionVersion.V3,
4118
+ signature: signatureToHexArray(signature),
4119
+ nonce: toHex(details.nonce),
4120
+ contract_class: {
4121
+ sierra_program: decompressProgram(contract.sierra_program),
4122
+ contract_class_version: contract.contract_class_version,
4123
+ entry_points_by_type: contract.entry_points_by_type,
4124
+ abi: contract.abi
4125
+ },
4126
+ resource_bounds: details.resourceBounds,
4127
+ tip: toHex(details.tip),
4128
+ paymaster_data: details.paymasterData.map((it) => toHex(it)),
4129
+ account_deployment_data: details.accountDeploymentData.map((it) => toHex(it)),
4130
+ nonce_data_availability_mode: details.nonceDataAvailabilityMode,
4131
+ fee_data_availability_mode: details.feeDataAvailabilityMode
4132
+ }
4133
+ });
4134
+ } else {
4135
+ throw Error("declare unspotted parameters");
4136
+ }
4137
+ return this.waitMode ? this.waitForTransaction((await promise).transaction_hash) : promise;
4138
+ }
4139
+ async deployAccount({ classHash, constructorCalldata, addressSalt, signature }, details) {
4140
+ let promise;
4141
+ if (!isV3Tx(details)) {
4142
+ promise = this.fetchEndpoint("starknet_addDeployAccountTransaction", {
4143
+ deploy_account_transaction: {
4144
+ constructor_calldata: CallData.toHex(constructorCalldata || []),
4145
+ class_hash: toHex(classHash),
4146
+ contract_address_salt: toHex(addressSalt || 0),
4147
+ type: rpcspec_0_7_exports.ETransactionType.DEPLOY_ACCOUNT,
4148
+ max_fee: toHex(details.maxFee || 0),
4149
+ version: rpcspec_0_7_exports.ETransactionVersion.V1,
4150
+ signature: signatureToHexArray(signature),
4151
+ nonce: toHex(details.nonce)
4152
+ }
4153
+ });
4154
+ } else {
4155
+ promise = this.fetchEndpoint("starknet_addDeployAccountTransaction", {
4156
+ deploy_account_transaction: {
4157
+ type: rpcspec_0_7_exports.ETransactionType.DEPLOY_ACCOUNT,
4158
+ version: rpcspec_0_7_exports.ETransactionVersion.V3,
4159
+ signature: signatureToHexArray(signature),
4160
+ nonce: toHex(details.nonce),
4161
+ contract_address_salt: toHex(addressSalt || 0),
4162
+ constructor_calldata: CallData.toHex(constructorCalldata || []),
4163
+ class_hash: toHex(classHash),
4164
+ resource_bounds: details.resourceBounds,
4165
+ tip: toHex(details.tip),
4166
+ paymaster_data: details.paymasterData.map((it) => toHex(it)),
4167
+ nonce_data_availability_mode: details.nonceDataAvailabilityMode,
4168
+ fee_data_availability_mode: details.feeDataAvailabilityMode
4169
+ }
4170
+ });
4171
+ }
4172
+ return this.waitMode ? this.waitForTransaction((await promise).transaction_hash) : promise;
4173
+ }
4174
+ callContract(call, blockIdentifier = this.blockIdentifier) {
4175
+ const block_id = new Block(blockIdentifier).identifier;
4176
+ return this.fetchEndpoint("starknet_call", {
4177
+ request: {
4178
+ contract_address: call.contractAddress,
4179
+ entry_point_selector: getSelectorFromName(call.entrypoint),
4180
+ calldata: CallData.toHex(call.calldata)
4181
+ },
4182
+ block_id
4183
+ });
4184
+ }
4185
+ /**
4186
+ * NEW: Estimate the fee for a message from L1
4187
+ * @param message Message From L1
4188
+ */
4189
+ estimateMessageFee(message, blockIdentifier = this.blockIdentifier) {
4190
+ const { from_address, to_address, entry_point_selector, payload } = message;
4191
+ const formattedMessage = {
4192
+ from_address: toHex(from_address),
4193
+ to_address: toHex(to_address),
4194
+ entry_point_selector: getSelector(entry_point_selector),
4195
+ payload: getHexStringArray(payload)
4196
+ };
4197
+ const block_id = new Block(blockIdentifier).identifier;
4198
+ return this.fetchEndpoint("starknet_estimateMessageFee", {
4199
+ message: formattedMessage,
4200
+ block_id
4201
+ });
4202
+ }
4203
+ /**
4204
+ * Returns an object about the sync status, or false if the node is not synching
4205
+ * @returns Object with the stats data
4206
+ */
4207
+ getSyncingStats() {
4208
+ return this.fetchEndpoint("starknet_syncing");
4209
+ }
4210
+ /**
4211
+ * Returns all events matching the given filter
4212
+ * @returns events and the pagination of the events
4213
+ */
4214
+ getEvents(eventFilter) {
4215
+ return this.fetchEndpoint("starknet_getEvents", { filter: eventFilter });
4216
+ }
4217
+ buildTransaction(invocation, versionType) {
4218
+ const defaultVersions = getVersionsByType(versionType);
4219
+ let details;
4220
+ if (!isV3Tx(invocation)) {
4221
+ details = {
4222
+ signature: signatureToHexArray(invocation.signature),
4223
+ nonce: toHex(invocation.nonce),
4224
+ max_fee: toHex(invocation.maxFee || 0)
4225
+ };
4226
+ } else {
4227
+ details = {
4228
+ signature: signatureToHexArray(invocation.signature),
4229
+ nonce: toHex(invocation.nonce),
4230
+ resource_bounds: invocation.resourceBounds,
4231
+ tip: toHex(invocation.tip),
4232
+ paymaster_data: invocation.paymasterData.map((it) => toHex(it)),
4233
+ nonce_data_availability_mode: invocation.nonceDataAvailabilityMode,
4234
+ fee_data_availability_mode: invocation.feeDataAvailabilityMode,
4235
+ account_deployment_data: invocation.accountDeploymentData.map((it) => toHex(it))
4236
+ };
4237
+ }
4238
+ if (invocation.type === "INVOKE_FUNCTION" /* INVOKE */) {
4239
+ return {
4240
+ // v0 v1 v3
4241
+ type: rpcspec_0_7_exports.ETransactionType.INVOKE,
4242
+ // TODO: Diff between sequencer and rpc invoke type
4243
+ sender_address: invocation.contractAddress,
4244
+ calldata: CallData.toHex(invocation.calldata),
4245
+ version: toHex(invocation.version || defaultVersions.v3),
4246
+ ...details
4247
+ };
4248
+ }
4249
+ if (invocation.type === "DECLARE" /* DECLARE */) {
4250
+ if (!isSierra(invocation.contract)) {
4251
+ return {
4252
+ type: invocation.type,
4253
+ contract_class: invocation.contract,
4254
+ sender_address: invocation.senderAddress,
4255
+ version: toHex(invocation.version || defaultVersions.v1),
4256
+ ...details
4257
+ };
4258
+ }
4259
+ return {
4260
+ // Cairo 1 - v2 v3
4261
+ type: invocation.type,
4262
+ contract_class: {
4263
+ ...invocation.contract,
4264
+ sierra_program: decompressProgram(invocation.contract.sierra_program)
4265
+ },
4266
+ compiled_class_hash: invocation.compiledClassHash || "",
4267
+ sender_address: invocation.senderAddress,
4268
+ version: toHex(invocation.version || defaultVersions.v3),
4269
+ ...details
4270
+ };
4271
+ }
4272
+ if (invocation.type === "DEPLOY_ACCOUNT" /* DEPLOY_ACCOUNT */) {
4273
+ const { account_deployment_data, ...restDetails } = details;
4274
+ return {
4275
+ type: invocation.type,
4276
+ constructor_calldata: CallData.toHex(invocation.constructorCalldata || []),
4277
+ class_hash: toHex(invocation.classHash),
4278
+ contract_address_salt: toHex(invocation.addressSalt || 0),
4279
+ version: toHex(invocation.version || defaultVersions.v3),
4280
+ ...restDetails
4281
+ };
4282
+ }
4283
+ throw Error("RPC buildTransaction received unknown TransactionType");
4284
+ }
4285
+ };
4286
+
4287
+ // src/utils/responseParser/rpc.ts
4288
+ var RPCResponseParser = class {
4289
+ parseGetBlockResponse(res) {
4290
+ return { status: "PENDING", ...res };
4291
+ }
4292
+ parseTransactionReceipt(res) {
4293
+ if ("actual_fee" in res && typeof res.actual_fee === "string") {
4294
+ return {
4295
+ ...res,
4296
+ actual_fee: {
4297
+ amount: res.actual_fee,
4298
+ unit: "FRI"
4299
+ }
4300
+ };
4301
+ }
4302
+ return res;
4303
+ }
4304
+ parseFeeEstimateResponse(res) {
4305
+ const val = res[0];
4306
+ return {
4307
+ overall_fee: toBigInt(val.overall_fee),
4308
+ gas_consumed: toBigInt(val.gas_consumed),
4309
+ gas_price: toBigInt(val.gas_price),
4310
+ unit: val.unit,
4311
+ suggestedMaxFee: estimatedFeeToMaxFee(val.overall_fee),
4312
+ resourceBounds: estimateFeeToBounds(val)
4313
+ };
4314
+ }
4315
+ parseFeeEstimateBulkResponse(res) {
4316
+ return res.map((val) => ({
4317
+ overall_fee: toBigInt(val.overall_fee),
4318
+ gas_consumed: toBigInt(val.gas_consumed),
4319
+ gas_price: toBigInt(val.gas_price),
4320
+ unit: val.unit,
4321
+ suggestedMaxFee: estimatedFeeToMaxFee(val.overall_fee),
4322
+ resourceBounds: estimateFeeToBounds(val)
4323
+ }));
4324
+ }
4325
+ parseSimulateTransactionResponse(res) {
4326
+ return res.map((it) => {
4327
+ return {
4328
+ ...it,
4329
+ suggestedMaxFee: estimatedFeeToMaxFee(BigInt(it.fee_estimation.overall_fee)),
4330
+ resourceBounds: estimateFeeToBounds(it.fee_estimation)
4331
+ };
4332
+ });
4333
+ }
4334
+ parseContractClassResponse(res) {
4335
+ return {
4336
+ ...res,
4337
+ abi: typeof res.abi === "string" ? JSON.parse(res.abi) : res.abi
4338
+ };
4339
+ }
4340
+ };
4341
+
4342
+ // src/provider/rpc.ts
4343
+ var RpcProvider = class {
4344
+ responseParser = new RPCResponseParser();
4345
+ channel;
4346
+ constructor(optionsOrProvider) {
4347
+ if (optionsOrProvider && "channel" in optionsOrProvider) {
4348
+ this.channel = optionsOrProvider.channel;
4349
+ } else {
4350
+ this.channel = new RpcChannel2({ ...optionsOrProvider, waitMode: false });
4351
+ }
4352
+ }
4353
+ fetch(method, params, id = 0) {
4354
+ return this.channel.fetch(method, params, id);
4355
+ }
4356
+ async getChainId() {
4357
+ return this.channel.getChainId();
4358
+ }
4359
+ async getSpecVersion() {
4360
+ return this.channel.getSpecVersion();
4361
+ }
4362
+ async getNonceForAddress(contractAddress, blockIdentifier) {
4363
+ return this.channel.getNonceForAddress(contractAddress, blockIdentifier);
4364
+ }
4365
+ async getBlock(blockIdentifier) {
4366
+ return this.channel.getBlockWithTxHashes(blockIdentifier).then(this.responseParser.parseGetBlockResponse);
4367
+ }
4368
+ /**
4369
+ * Get the most recent accepted block hash and number
4370
+ */
4371
+ async getBlockLatestAccepted() {
4372
+ return this.channel.getBlockLatestAccepted();
4373
+ }
4374
+ /**
4375
+ * Get the most recent accepted block number
4376
+ * redundant use getBlockLatestAccepted();
4377
+ * @returns Number of the latest block
4378
+ */
4379
+ async getBlockNumber() {
4380
+ return this.channel.getBlockNumber();
4381
+ }
4382
+ async getBlockWithTxHashes(blockIdentifier) {
4383
+ return this.channel.getBlockWithTxHashes(blockIdentifier);
4384
+ }
4385
+ async getBlockWithTxs(blockIdentifier) {
4386
+ return this.channel.getBlockWithTxs(blockIdentifier);
4387
+ }
4388
+ async getBlockWithReceipts(blockIdentifier) {
4389
+ if (this.channel instanceof rpc_0_6_exports.RpcChannel)
4390
+ throw new LibraryError("Unsupported method for RPC version");
4391
+ return this.channel.getBlockWithReceipts(blockIdentifier);
3728
4392
  }
3729
4393
  getStateUpdate = this.getBlockStateUpdate;
3730
4394
  async getBlockStateUpdate(blockIdentifier) {
@@ -4442,7 +5106,7 @@ var Signer = class {
4442
5106
  async signTransaction(transactions, details) {
4443
5107
  const compiledCalldata = getExecuteCalldata(transactions, details.cairoVersion);
4444
5108
  let msgHash;
4445
- if (Object.values(ETransactionVersion2).includes(details.version)) {
5109
+ if (Object.values(ETransactionVersion22).includes(details.version)) {
4446
5110
  const det = details;
4447
5111
  msgHash = calculateInvokeTransactionHash2({
4448
5112
  ...det,
@@ -4450,7 +5114,7 @@ var Signer = class {
4450
5114
  compiledCalldata,
4451
5115
  version: det.version
4452
5116
  });
4453
- } else if (Object.values(ETransactionVersion3).includes(details.version)) {
5117
+ } else if (Object.values(ETransactionVersion32).includes(details.version)) {
4454
5118
  const det = details;
4455
5119
  msgHash = calculateInvokeTransactionHash2({
4456
5120
  ...det,
@@ -4468,7 +5132,7 @@ var Signer = class {
4468
5132
  async signDeployAccountTransaction(details) {
4469
5133
  const compiledConstructorCalldata = CallData.compile(details.constructorCalldata);
4470
5134
  let msgHash;
4471
- if (Object.values(ETransactionVersion2).includes(details.version)) {
5135
+ if (Object.values(ETransactionVersion22).includes(details.version)) {
4472
5136
  const det = details;
4473
5137
  msgHash = calculateDeployAccountTransactionHash3({
4474
5138
  ...det,
@@ -4476,7 +5140,7 @@ var Signer = class {
4476
5140
  constructorCalldata: compiledConstructorCalldata,
4477
5141
  version: det.version
4478
5142
  });
4479
- } else if (Object.values(ETransactionVersion3).includes(details.version)) {
5143
+ } else if (Object.values(ETransactionVersion32).includes(details.version)) {
4480
5144
  const det = details;
4481
5145
  msgHash = calculateDeployAccountTransactionHash3({
4482
5146
  ...det,
@@ -4493,13 +5157,13 @@ var Signer = class {
4493
5157
  }
4494
5158
  async signDeclareTransaction(details) {
4495
5159
  let msgHash;
4496
- if (Object.values(ETransactionVersion2).includes(details.version)) {
5160
+ if (Object.values(ETransactionVersion22).includes(details.version)) {
4497
5161
  const det = details;
4498
5162
  msgHash = calculateDeclareTransactionHash3({
4499
5163
  ...det,
4500
5164
  version: det.version
4501
5165
  });
4502
- } else if (Object.values(ETransactionVersion3).includes(details.version)) {
5166
+ } else if (Object.values(ETransactionVersion32).includes(details.version)) {
4503
5167
  const det = details;
4504
5168
  msgHash = calculateDeclareTransactionHash3({
4505
5169
  ...det,
@@ -4547,7 +5211,7 @@ var EthSigner = class {
4547
5211
  async signTransaction(transactions, details) {
4548
5212
  const compiledCalldata = getExecuteCalldata(transactions, details.cairoVersion);
4549
5213
  let msgHash;
4550
- if (Object.values(ETransactionVersion2).includes(details.version)) {
5214
+ if (Object.values(ETransactionVersion22).includes(details.version)) {
4551
5215
  const det = details;
4552
5216
  msgHash = calculateInvokeTransactionHash2({
4553
5217
  ...det,
@@ -4555,7 +5219,7 @@ var EthSigner = class {
4555
5219
  compiledCalldata,
4556
5220
  version: det.version
4557
5221
  });
4558
- } else if (Object.values(ETransactionVersion3).includes(details.version)) {
5222
+ } else if (Object.values(ETransactionVersion32).includes(details.version)) {
4559
5223
  const det = details;
4560
5224
  msgHash = calculateInvokeTransactionHash2({
4561
5225
  ...det,
@@ -4573,7 +5237,7 @@ var EthSigner = class {
4573
5237
  async signDeployAccountTransaction(details) {
4574
5238
  const compiledConstructorCalldata = CallData.compile(details.constructorCalldata);
4575
5239
  let msgHash;
4576
- if (Object.values(ETransactionVersion2).includes(details.version)) {
5240
+ if (Object.values(ETransactionVersion22).includes(details.version)) {
4577
5241
  const det = details;
4578
5242
  msgHash = calculateDeployAccountTransactionHash3({
4579
5243
  ...det,
@@ -4581,7 +5245,7 @@ var EthSigner = class {
4581
5245
  constructorCalldata: compiledConstructorCalldata,
4582
5246
  version: det.version
4583
5247
  });
4584
- } else if (Object.values(ETransactionVersion3).includes(details.version)) {
5248
+ } else if (Object.values(ETransactionVersion32).includes(details.version)) {
4585
5249
  const det = details;
4586
5250
  msgHash = calculateDeployAccountTransactionHash3({
4587
5251
  ...det,
@@ -4598,13 +5262,13 @@ var EthSigner = class {
4598
5262
  }
4599
5263
  async signDeclareTransaction(details) {
4600
5264
  let msgHash;
4601
- if (Object.values(ETransactionVersion2).includes(details.version)) {
5265
+ if (Object.values(ETransactionVersion22).includes(details.version)) {
4602
5266
  const det = details;
4603
5267
  msgHash = calculateDeclareTransactionHash3({
4604
5268
  ...det,
4605
5269
  version: det.version
4606
5270
  });
4607
- } else if (Object.values(ETransactionVersion3).includes(details.version)) {
5271
+ } else if (Object.values(ETransactionVersion32).includes(details.version)) {
4608
5272
  const det = details;
4609
5273
  msgHash = calculateDeclareTransactionHash3({
4610
5274
  ...det,
@@ -5754,6 +6418,8 @@ var number = num_exports;
5754
6418
  Provider,
5755
6419
  ProviderInterface,
5756
6420
  RPC,
6421
+ RPC06,
6422
+ RPC07,
5757
6423
  RpcChannel,
5758
6424
  RpcProvider,
5759
6425
  SIMULATION_FLAG,