starknet 6.1.5 → 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;
@@ -3262,9 +3386,9 @@ var RpcChannel = class {
3262
3386
  const block_id = new Block(blockIdentifier).identifier;
3263
3387
  const simulationFlags = [];
3264
3388
  if (skipValidate)
3265
- simulationFlags.push(api_exports.ESimulationFlag.SKIP_VALIDATE);
3389
+ simulationFlags.push(rpcspec_0_6_exports.ESimulationFlag.SKIP_VALIDATE);
3266
3390
  if (skipFeeCharge)
3267
- simulationFlags.push(api_exports.ESimulationFlag.SKIP_FEE_CHARGE);
3391
+ simulationFlags.push(rpcspec_0_6_exports.ESimulationFlag.SKIP_FEE_CHARGE);
3268
3392
  return this.fetchEndpoint("starknet_simulateTransactions", {
3269
3393
  block_id,
3270
3394
  transactions: invocations.map((it) => this.buildTransaction(it)),
@@ -3278,15 +3402,15 @@ var RpcChannel = class {
3278
3402
  let isErrorState = false;
3279
3403
  const retryInterval = options?.retryInterval ?? 5e3;
3280
3404
  const errorStates = options?.errorStates ?? [
3281
- api_exports.ETransactionStatus.REJECTED
3405
+ rpcspec_0_6_exports.ETransactionStatus.REJECTED
3282
3406
  // TODO: commented out to preserve the long-standing behavior of "reverted" not being treated as an error by default
3283
3407
  // should decide which behavior to keep in the future
3284
3408
  // RPC.ETransactionExecutionStatus.REVERTED,
3285
3409
  ];
3286
3410
  const successStates = options?.successStates ?? [
3287
- api_exports.ETransactionExecutionStatus.SUCCEEDED,
3288
- api_exports.ETransactionStatus.ACCEPTED_ON_L2,
3289
- 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
3290
3414
  ];
3291
3415
  let txStatus;
3292
3416
  while (!onchain) {
@@ -3369,9 +3493,9 @@ var RpcChannel = class {
3369
3493
  async getEstimateFee(invocations, { blockIdentifier = this.blockIdentifier, skipValidate = true }) {
3370
3494
  const block_id = new Block(blockIdentifier).identifier;
3371
3495
  let flags = {};
3372
- if (isVersion("0.6", await this.getSpecVersion())) {
3496
+ if (!isVersion("0.5", await this.getSpecVersion())) {
3373
3497
  flags = {
3374
- simulation_flags: skipValidate ? [api_exports.ESimulationFlag.SKIP_VALIDATE] : []
3498
+ simulation_flags: skipValidate ? [rpcspec_0_6_exports.ESimulationFlag.SKIP_VALIDATE] : []
3375
3499
  };
3376
3500
  }
3377
3501
  return this.fetchEndpoint("starknet_estimateFee", {
@@ -3387,9 +3511,9 @@ var RpcChannel = class {
3387
3511
  invoke_transaction: {
3388
3512
  sender_address: functionInvocation.contractAddress,
3389
3513
  calldata: CallData.toHex(functionInvocation.calldata),
3390
- type: api_exports.ETransactionType.INVOKE,
3514
+ type: rpcspec_0_6_exports.ETransactionType.INVOKE,
3391
3515
  max_fee: toHex(details.maxFee || 0),
3392
- version: "0x1" /* V1 */,
3516
+ version: rpcspec_0_6_exports.ETransactionVersion.V1,
3393
3517
  signature: signatureToHexArray(functionInvocation.signature),
3394
3518
  nonce: toHex(details.nonce)
3395
3519
  }
@@ -3397,10 +3521,10 @@ var RpcChannel = class {
3397
3521
  } else {
3398
3522
  promise = this.fetchEndpoint("starknet_addInvokeTransaction", {
3399
3523
  invoke_transaction: {
3400
- type: api_exports.ETransactionType.INVOKE,
3524
+ type: rpcspec_0_6_exports.ETransactionType.INVOKE,
3401
3525
  sender_address: functionInvocation.contractAddress,
3402
3526
  calldata: CallData.toHex(functionInvocation.calldata),
3403
- version: "0x3" /* V3 */,
3527
+ version: rpcspec_0_6_exports.ETransactionVersion.V3,
3404
3528
  signature: signatureToHexArray(functionInvocation.signature),
3405
3529
  nonce: toHex(details.nonce),
3406
3530
  resource_bounds: details.resourceBounds,
@@ -3419,13 +3543,13 @@ var RpcChannel = class {
3419
3543
  if (!isSierra(contract) && !isV3Tx(details)) {
3420
3544
  promise = this.fetchEndpoint("starknet_addDeclareTransaction", {
3421
3545
  declare_transaction: {
3422
- type: api_exports.ETransactionType.DECLARE,
3546
+ type: rpcspec_0_6_exports.ETransactionType.DECLARE,
3423
3547
  contract_class: {
3424
3548
  program: contract.program,
3425
3549
  entry_points_by_type: contract.entry_points_by_type,
3426
3550
  abi: contract.abi
3427
3551
  },
3428
- version: "0x1" /* V1 */,
3552
+ version: rpcspec_0_6_exports.ETransactionVersion.V1,
3429
3553
  max_fee: toHex(details.maxFee || 0),
3430
3554
  signature: signatureToHexArray(signature),
3431
3555
  sender_address: senderAddress,
@@ -3435,7 +3559,7 @@ var RpcChannel = class {
3435
3559
  } else if (isSierra(contract) && !isV3Tx(details)) {
3436
3560
  promise = this.fetchEndpoint("starknet_addDeclareTransaction", {
3437
3561
  declare_transaction: {
3438
- type: api_exports.ETransactionType.DECLARE,
3562
+ type: rpcspec_0_6_exports.ETransactionType.DECLARE,
3439
3563
  contract_class: {
3440
3564
  sierra_program: decompressProgram(contract.sierra_program),
3441
3565
  contract_class_version: contract.contract_class_version,
@@ -3443,7 +3567,7 @@ var RpcChannel = class {
3443
3567
  abi: contract.abi
3444
3568
  },
3445
3569
  compiled_class_hash: compiledClassHash || "",
3446
- version: "0x2" /* V2 */,
3570
+ version: rpcspec_0_6_exports.ETransactionVersion.V2,
3447
3571
  max_fee: toHex(details.maxFee || 0),
3448
3572
  signature: signatureToHexArray(signature),
3449
3573
  sender_address: senderAddress,
@@ -3453,10 +3577,10 @@ var RpcChannel = class {
3453
3577
  } else if (isSierra(contract) && isV3Tx(details)) {
3454
3578
  promise = this.fetchEndpoint("starknet_addDeclareTransaction", {
3455
3579
  declare_transaction: {
3456
- type: api_exports.ETransactionType.DECLARE,
3580
+ type: rpcspec_0_6_exports.ETransactionType.DECLARE,
3457
3581
  sender_address: senderAddress,
3458
3582
  compiled_class_hash: compiledClassHash || "",
3459
- version: "0x3" /* V3 */,
3583
+ version: rpcspec_0_6_exports.ETransactionVersion.V3,
3460
3584
  signature: signatureToHexArray(signature),
3461
3585
  nonce: toHex(details.nonce),
3462
3586
  contract_class: {
@@ -3486,9 +3610,9 @@ var RpcChannel = class {
3486
3610
  constructor_calldata: CallData.toHex(constructorCalldata || []),
3487
3611
  class_hash: toHex(classHash),
3488
3612
  contract_address_salt: toHex(addressSalt || 0),
3489
- type: api_exports.ETransactionType.DEPLOY_ACCOUNT,
3613
+ type: rpcspec_0_6_exports.ETransactionType.DEPLOY_ACCOUNT,
3490
3614
  max_fee: toHex(details.maxFee || 0),
3491
- version: "0x1" /* V1 */,
3615
+ version: rpcspec_0_6_exports.ETransactionVersion.V1,
3492
3616
  signature: signatureToHexArray(signature),
3493
3617
  nonce: toHex(details.nonce)
3494
3618
  }
@@ -3496,8 +3620,8 @@ var RpcChannel = class {
3496
3620
  } else {
3497
3621
  promise = this.fetchEndpoint("starknet_addDeployAccountTransaction", {
3498
3622
  deploy_account_transaction: {
3499
- type: api_exports.ETransactionType.DEPLOY_ACCOUNT,
3500
- version: "0x3" /* V3 */,
3623
+ type: rpcspec_0_6_exports.ETransactionType.DEPLOY_ACCOUNT,
3624
+ version: rpcspec_0_6_exports.ETransactionVersion.V3,
3501
3625
  signature: signatureToHexArray(signature),
3502
3626
  nonce: toHex(details.nonce),
3503
3627
  contract_address_salt: toHex(addressSalt || 0),
@@ -3580,7 +3704,7 @@ var RpcChannel = class {
3580
3704
  if (invocation.type === "INVOKE_FUNCTION" /* INVOKE */) {
3581
3705
  return {
3582
3706
  // v0 v1 v3
3583
- type: api_exports.ETransactionType.INVOKE,
3707
+ type: rpcspec_0_6_exports.ETransactionType.INVOKE,
3584
3708
  // TODO: Diff between sequencer and rpc invoke type
3585
3709
  sender_address: invocation.contractAddress,
3586
3710
  calldata: CallData.toHex(invocation.calldata),
@@ -3626,106 +3750,645 @@ var RpcChannel = class {
3626
3750
  }
3627
3751
  };
3628
3752
 
3629
- // src/utils/responseParser/rpc.ts
3630
- var RPCResponseParser = class {
3631
- parseGetBlockResponse(res) {
3632
- return { status: "PENDING", ...res };
3633
- }
3634
- parseTransactionReceipt(res) {
3635
- if ("actual_fee" in res && typeof res.actual_fee === "string") {
3636
- return {
3637
- ...res,
3638
- actual_fee: {
3639
- amount: res.actual_fee,
3640
- unit: "FRI"
3641
- }
3642
- };
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);
3643
3781
  }
3644
- 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;
3645
3788
  }
3646
- parseFeeEstimateResponse(res) {
3647
- const val = res[0];
3648
- return {
3649
- overall_fee: toBigInt(val.overall_fee),
3650
- gas_consumed: toBigInt(val.gas_consumed),
3651
- gas_price: toBigInt(val.gas_price),
3652
- unit: val.unit,
3653
- suggestedMaxFee: estimatedFeeToMaxFee(val.overall_fee),
3654
- resourceBounds: estimateFeeToBounds(val)
3789
+ fetch(method, params, id = 0) {
3790
+ const rpcRequestBody = {
3791
+ id,
3792
+ jsonrpc: "2.0",
3793
+ method,
3794
+ ...params && { params }
3655
3795
  };
3656
- }
3657
- parseFeeEstimateBulkResponse(res) {
3658
- return res.map((val) => ({
3659
- overall_fee: toBigInt(val.overall_fee),
3660
- gas_consumed: toBigInt(val.gas_consumed),
3661
- gas_price: toBigInt(val.gas_price),
3662
- unit: val.unit,
3663
- suggestedMaxFee: estimatedFeeToMaxFee(val.overall_fee),
3664
- resourceBounds: estimateFeeToBounds(val)
3665
- }));
3666
- }
3667
- parseSimulateTransactionResponse(res) {
3668
- return res.map((it) => {
3669
- return {
3670
- ...it,
3671
- suggestedMaxFee: estimatedFeeToMaxFee(BigInt(it.fee_estimation.overall_fee)),
3672
- resourceBounds: estimateFeeToBounds(it.fee_estimation)
3673
- };
3796
+ return fetchPonyfill_default(this.nodeUrl, {
3797
+ method: "POST",
3798
+ body: stringify2(rpcRequestBody),
3799
+ headers: this.headers
3674
3800
  });
3675
3801
  }
3676
- parseContractClassResponse(res) {
3677
- return {
3678
- ...res,
3679
- abi: typeof res.abi === "string" ? JSON.parse(res.abi) : res.abi
3680
- };
3681
- }
3682
- };
3683
-
3684
- // src/provider/rpc.ts
3685
- var RpcProvider = class {
3686
- responseParser = new RPCResponseParser();
3687
- channel;
3688
- constructor(optionsOrProvider) {
3689
- if (optionsOrProvider && "channel" in optionsOrProvider) {
3690
- this.channel = optionsOrProvider.channel;
3691
- } else {
3692
- 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);
3693
3816
  }
3694
3817
  }
3695
- fetch(method, params, id = 0) {
3696
- 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
+ }
3697
3828
  }
3698
3829
  async getChainId() {
3699
- return this.channel.getChainId();
3830
+ this.chainId ??= await this.fetchEndpoint("starknet_chainId");
3831
+ return this.chainId;
3700
3832
  }
3701
3833
  async getSpecVersion() {
3702
- return this.channel.getSpecVersion();
3703
- }
3704
- async getNonceForAddress(contractAddress, blockIdentifier) {
3705
- return this.channel.getNonceForAddress(contractAddress, blockIdentifier);
3834
+ this.speckVersion ??= await this.fetchEndpoint("starknet_specVersion");
3835
+ return this.speckVersion;
3706
3836
  }
3707
- async getBlock(blockIdentifier) {
3708
- 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
+ });
3709
3844
  }
3710
3845
  /**
3711
3846
  * Get the most recent accepted block hash and number
3712
3847
  */
3713
- async getBlockLatestAccepted() {
3714
- return this.channel.getBlockLatestAccepted();
3848
+ getBlockLatestAccepted() {
3849
+ return this.fetchEndpoint("starknet_blockHashAndNumber");
3715
3850
  }
3716
3851
  /**
3717
3852
  * Get the most recent accepted block number
3718
3853
  * redundant use getBlockLatestAccepted();
3719
3854
  * @returns Number of the latest block
3720
3855
  */
3721
- async getBlockNumber() {
3722
- return this.channel.getBlockNumber();
3856
+ getBlockNumber() {
3857
+ return this.fetchEndpoint("starknet_blockNumber");
3723
3858
  }
3724
- async getBlockWithTxHashes(blockIdentifier) {
3725
- 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 });
3726
3862
  }
3727
- async getBlockWithTxs(blockIdentifier) {
3728
- 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);
3729
4392
  }
3730
4393
  getStateUpdate = this.getBlockStateUpdate;
3731
4394
  async getBlockStateUpdate(blockIdentifier) {
@@ -4443,7 +5106,7 @@ var Signer = class {
4443
5106
  async signTransaction(transactions, details) {
4444
5107
  const compiledCalldata = getExecuteCalldata(transactions, details.cairoVersion);
4445
5108
  let msgHash;
4446
- if (Object.values(ETransactionVersion2).includes(details.version)) {
5109
+ if (Object.values(ETransactionVersion22).includes(details.version)) {
4447
5110
  const det = details;
4448
5111
  msgHash = calculateInvokeTransactionHash2({
4449
5112
  ...det,
@@ -4451,7 +5114,7 @@ var Signer = class {
4451
5114
  compiledCalldata,
4452
5115
  version: det.version
4453
5116
  });
4454
- } else if (Object.values(ETransactionVersion3).includes(details.version)) {
5117
+ } else if (Object.values(ETransactionVersion32).includes(details.version)) {
4455
5118
  const det = details;
4456
5119
  msgHash = calculateInvokeTransactionHash2({
4457
5120
  ...det,
@@ -4469,7 +5132,7 @@ var Signer = class {
4469
5132
  async signDeployAccountTransaction(details) {
4470
5133
  const compiledConstructorCalldata = CallData.compile(details.constructorCalldata);
4471
5134
  let msgHash;
4472
- if (Object.values(ETransactionVersion2).includes(details.version)) {
5135
+ if (Object.values(ETransactionVersion22).includes(details.version)) {
4473
5136
  const det = details;
4474
5137
  msgHash = calculateDeployAccountTransactionHash3({
4475
5138
  ...det,
@@ -4477,7 +5140,7 @@ var Signer = class {
4477
5140
  constructorCalldata: compiledConstructorCalldata,
4478
5141
  version: det.version
4479
5142
  });
4480
- } else if (Object.values(ETransactionVersion3).includes(details.version)) {
5143
+ } else if (Object.values(ETransactionVersion32).includes(details.version)) {
4481
5144
  const det = details;
4482
5145
  msgHash = calculateDeployAccountTransactionHash3({
4483
5146
  ...det,
@@ -4494,13 +5157,13 @@ var Signer = class {
4494
5157
  }
4495
5158
  async signDeclareTransaction(details) {
4496
5159
  let msgHash;
4497
- if (Object.values(ETransactionVersion2).includes(details.version)) {
5160
+ if (Object.values(ETransactionVersion22).includes(details.version)) {
4498
5161
  const det = details;
4499
5162
  msgHash = calculateDeclareTransactionHash3({
4500
5163
  ...det,
4501
5164
  version: det.version
4502
5165
  });
4503
- } else if (Object.values(ETransactionVersion3).includes(details.version)) {
5166
+ } else if (Object.values(ETransactionVersion32).includes(details.version)) {
4504
5167
  const det = details;
4505
5168
  msgHash = calculateDeclareTransactionHash3({
4506
5169
  ...det,
@@ -4548,7 +5211,7 @@ var EthSigner = class {
4548
5211
  async signTransaction(transactions, details) {
4549
5212
  const compiledCalldata = getExecuteCalldata(transactions, details.cairoVersion);
4550
5213
  let msgHash;
4551
- if (Object.values(ETransactionVersion2).includes(details.version)) {
5214
+ if (Object.values(ETransactionVersion22).includes(details.version)) {
4552
5215
  const det = details;
4553
5216
  msgHash = calculateInvokeTransactionHash2({
4554
5217
  ...det,
@@ -4556,7 +5219,7 @@ var EthSigner = class {
4556
5219
  compiledCalldata,
4557
5220
  version: det.version
4558
5221
  });
4559
- } else if (Object.values(ETransactionVersion3).includes(details.version)) {
5222
+ } else if (Object.values(ETransactionVersion32).includes(details.version)) {
4560
5223
  const det = details;
4561
5224
  msgHash = calculateInvokeTransactionHash2({
4562
5225
  ...det,
@@ -4574,7 +5237,7 @@ var EthSigner = class {
4574
5237
  async signDeployAccountTransaction(details) {
4575
5238
  const compiledConstructorCalldata = CallData.compile(details.constructorCalldata);
4576
5239
  let msgHash;
4577
- if (Object.values(ETransactionVersion2).includes(details.version)) {
5240
+ if (Object.values(ETransactionVersion22).includes(details.version)) {
4578
5241
  const det = details;
4579
5242
  msgHash = calculateDeployAccountTransactionHash3({
4580
5243
  ...det,
@@ -4582,7 +5245,7 @@ var EthSigner = class {
4582
5245
  constructorCalldata: compiledConstructorCalldata,
4583
5246
  version: det.version
4584
5247
  });
4585
- } else if (Object.values(ETransactionVersion3).includes(details.version)) {
5248
+ } else if (Object.values(ETransactionVersion32).includes(details.version)) {
4586
5249
  const det = details;
4587
5250
  msgHash = calculateDeployAccountTransactionHash3({
4588
5251
  ...det,
@@ -4599,13 +5262,13 @@ var EthSigner = class {
4599
5262
  }
4600
5263
  async signDeclareTransaction(details) {
4601
5264
  let msgHash;
4602
- if (Object.values(ETransactionVersion2).includes(details.version)) {
5265
+ if (Object.values(ETransactionVersion22).includes(details.version)) {
4603
5266
  const det = details;
4604
5267
  msgHash = calculateDeclareTransactionHash3({
4605
5268
  ...det,
4606
5269
  version: det.version
4607
5270
  });
4608
- } else if (Object.values(ETransactionVersion3).includes(details.version)) {
5271
+ } else if (Object.values(ETransactionVersion32).includes(details.version)) {
4609
5272
  const det = details;
4610
5273
  msgHash = calculateDeclareTransactionHash3({
4611
5274
  ...det,
@@ -5755,6 +6418,8 @@ var number = num_exports;
5755
6418
  Provider,
5756
6419
  ProviderInterface,
5757
6420
  RPC,
6421
+ RPC06,
6422
+ RPC07,
5758
6423
  RpcChannel,
5759
6424
  RpcProvider,
5760
6425
  SIMULATION_FLAG,