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.
@@ -12695,7 +12695,9 @@ var starknet = (() => {
12695
12695
  Provider: () => RpcProvider2,
12696
12696
  ProviderInterface: () => ProviderInterface,
12697
12697
  RPC: () => api_exports,
12698
- RpcChannel: () => RpcChannel,
12698
+ RPC06: () => rpc_0_6_exports,
12699
+ RPC07: () => rpc_0_7_exports,
12700
+ RpcChannel: () => RpcChannel2,
12699
12701
  RpcProvider: () => RpcProvider2,
12700
12702
  SIMULATION_FLAG: () => SIMULATION_FLAG,
12701
12703
  Signer: () => Signer,
@@ -12761,7 +12763,7 @@ var starknet = (() => {
12761
12763
  RPC_NODES: () => RPC_NODES,
12762
12764
  StarknetChainId: () => StarknetChainId,
12763
12765
  TEXT_TO_FELT_MAX_LEN: () => TEXT_TO_FELT_MAX_LEN,
12764
- TRANSACTION_VERSION: () => ETransactionVersion,
12766
+ TRANSACTION_VERSION: () => ETransactionVersion4,
12765
12767
  TransactionHashPrefix: () => TransactionHashPrefix,
12766
12768
  UDC: () => UDC,
12767
12769
  ZERO: () => ZERO
@@ -12770,6 +12772,30 @@ var starknet = (() => {
12770
12772
  // src/types/api/index.ts
12771
12773
  var api_exports = {};
12772
12774
  __export(api_exports, {
12775
+ EBlockTag: () => EBlockTag2,
12776
+ EDAMode: () => EDAMode2,
12777
+ EDataAvailabilityMode: () => EDataAvailabilityMode2,
12778
+ ESimulationFlag: () => ESimulationFlag2,
12779
+ ETransactionExecutionStatus: () => ETransactionExecutionStatus2,
12780
+ ETransactionFinalityStatus: () => ETransactionFinalityStatus2,
12781
+ ETransactionStatus: () => ETransactionStatus2,
12782
+ ETransactionType: () => ETransactionType2,
12783
+ ETransactionVersion: () => ETransactionVersion4,
12784
+ ETransactionVersion2: () => ETransactionVersion22,
12785
+ ETransactionVersion3: () => ETransactionVersion32,
12786
+ Errors: () => errors_exports2,
12787
+ JRPC: () => jsonrpc_exports,
12788
+ RPCSPEC06: () => rpcspec_0_6_exports,
12789
+ RPCSPEC07: () => rpcspec_0_7_exports,
12790
+ SPEC: () => components_exports2
12791
+ });
12792
+
12793
+ // src/types/api/jsonrpc/index.ts
12794
+ var jsonrpc_exports = {};
12795
+
12796
+ // src/types/api/rpcspec_0_6/index.ts
12797
+ var rpcspec_0_6_exports = {};
12798
+ __export(rpcspec_0_6_exports, {
12773
12799
  EBlockTag: () => EBlockTag,
12774
12800
  EDAMode: () => EDAMode,
12775
12801
  EDataAvailabilityMode: () => EDataAvailabilityMode,
@@ -12782,13 +12808,9 @@ var starknet = (() => {
12782
12808
  ETransactionVersion2: () => ETransactionVersion2,
12783
12809
  ETransactionVersion3: () => ETransactionVersion3,
12784
12810
  Errors: () => errors_exports,
12785
- JRPC: () => jsonrpc_exports,
12786
12811
  SPEC: () => components_exports
12787
12812
  });
12788
12813
 
12789
- // src/types/api/jsonrpc/index.ts
12790
- var jsonrpc_exports = {};
12791
-
12792
12814
  // src/types/api/rpcspec_0_6/errors.ts
12793
12815
  var errors_exports = {};
12794
12816
 
@@ -12796,77 +12818,173 @@ var starknet = (() => {
12796
12818
  var components_exports = {};
12797
12819
 
12798
12820
  // src/types/api/rpcspec_0_6/nonspec.ts
12799
- var ETransactionType = /* @__PURE__ */ ((ETransactionType2) => {
12800
- ETransactionType2["DECLARE"] = "DECLARE";
12801
- ETransactionType2["DEPLOY"] = "DEPLOY";
12802
- ETransactionType2["DEPLOY_ACCOUNT"] = "DEPLOY_ACCOUNT";
12803
- ETransactionType2["INVOKE"] = "INVOKE";
12804
- ETransactionType2["L1_HANDLER"] = "L1_HANDLER";
12805
- return ETransactionType2;
12821
+ var ETransactionType = /* @__PURE__ */ ((ETransactionType3) => {
12822
+ ETransactionType3["DECLARE"] = "DECLARE";
12823
+ ETransactionType3["DEPLOY"] = "DEPLOY";
12824
+ ETransactionType3["DEPLOY_ACCOUNT"] = "DEPLOY_ACCOUNT";
12825
+ ETransactionType3["INVOKE"] = "INVOKE";
12826
+ ETransactionType3["L1_HANDLER"] = "L1_HANDLER";
12827
+ return ETransactionType3;
12806
12828
  })(ETransactionType || {});
12807
- var ESimulationFlag = /* @__PURE__ */ ((ESimulationFlag2) => {
12808
- ESimulationFlag2["SKIP_VALIDATE"] = "SKIP_VALIDATE";
12809
- ESimulationFlag2["SKIP_FEE_CHARGE"] = "SKIP_FEE_CHARGE";
12810
- return ESimulationFlag2;
12829
+ var ESimulationFlag = /* @__PURE__ */ ((ESimulationFlag3) => {
12830
+ ESimulationFlag3["SKIP_VALIDATE"] = "SKIP_VALIDATE";
12831
+ ESimulationFlag3["SKIP_FEE_CHARGE"] = "SKIP_FEE_CHARGE";
12832
+ return ESimulationFlag3;
12811
12833
  })(ESimulationFlag || {});
12812
- var ETransactionStatus = /* @__PURE__ */ ((ETransactionStatus2) => {
12813
- ETransactionStatus2["RECEIVED"] = "RECEIVED";
12814
- ETransactionStatus2["REJECTED"] = "REJECTED";
12815
- ETransactionStatus2["ACCEPTED_ON_L2"] = "ACCEPTED_ON_L2";
12816
- ETransactionStatus2["ACCEPTED_ON_L1"] = "ACCEPTED_ON_L1";
12817
- return ETransactionStatus2;
12834
+ var ETransactionStatus = /* @__PURE__ */ ((ETransactionStatus3) => {
12835
+ ETransactionStatus3["RECEIVED"] = "RECEIVED";
12836
+ ETransactionStatus3["REJECTED"] = "REJECTED";
12837
+ ETransactionStatus3["ACCEPTED_ON_L2"] = "ACCEPTED_ON_L2";
12838
+ ETransactionStatus3["ACCEPTED_ON_L1"] = "ACCEPTED_ON_L1";
12839
+ return ETransactionStatus3;
12818
12840
  })(ETransactionStatus || {});
12819
- var ETransactionFinalityStatus = /* @__PURE__ */ ((ETransactionFinalityStatus2) => {
12820
- ETransactionFinalityStatus2["ACCEPTED_ON_L2"] = "ACCEPTED_ON_L2";
12821
- ETransactionFinalityStatus2["ACCEPTED_ON_L1"] = "ACCEPTED_ON_L1";
12822
- return ETransactionFinalityStatus2;
12841
+ var ETransactionFinalityStatus = /* @__PURE__ */ ((ETransactionFinalityStatus3) => {
12842
+ ETransactionFinalityStatus3["ACCEPTED_ON_L2"] = "ACCEPTED_ON_L2";
12843
+ ETransactionFinalityStatus3["ACCEPTED_ON_L1"] = "ACCEPTED_ON_L1";
12844
+ return ETransactionFinalityStatus3;
12823
12845
  })(ETransactionFinalityStatus || {});
12824
- var ETransactionExecutionStatus = /* @__PURE__ */ ((ETransactionExecutionStatus2) => {
12825
- ETransactionExecutionStatus2["SUCCEEDED"] = "SUCCEEDED";
12826
- ETransactionExecutionStatus2["REVERTED"] = "REVERTED";
12827
- return ETransactionExecutionStatus2;
12846
+ var ETransactionExecutionStatus = /* @__PURE__ */ ((ETransactionExecutionStatus3) => {
12847
+ ETransactionExecutionStatus3["SUCCEEDED"] = "SUCCEEDED";
12848
+ ETransactionExecutionStatus3["REVERTED"] = "REVERTED";
12849
+ return ETransactionExecutionStatus3;
12828
12850
  })(ETransactionExecutionStatus || {});
12829
- var EBlockTag = /* @__PURE__ */ ((EBlockTag2) => {
12830
- EBlockTag2["LATEST"] = "latest";
12831
- EBlockTag2["PENDING"] = "pending";
12832
- return EBlockTag2;
12851
+ var EBlockTag = /* @__PURE__ */ ((EBlockTag3) => {
12852
+ EBlockTag3["LATEST"] = "latest";
12853
+ EBlockTag3["PENDING"] = "pending";
12854
+ return EBlockTag3;
12833
12855
  })(EBlockTag || {});
12834
- var EDataAvailabilityMode = /* @__PURE__ */ ((EDataAvailabilityMode2) => {
12835
- EDataAvailabilityMode2["L1"] = "L1";
12836
- EDataAvailabilityMode2["L2"] = "L2";
12837
- return EDataAvailabilityMode2;
12856
+ var EDataAvailabilityMode = /* @__PURE__ */ ((EDataAvailabilityMode3) => {
12857
+ EDataAvailabilityMode3["L1"] = "L1";
12858
+ EDataAvailabilityMode3["L2"] = "L2";
12859
+ return EDataAvailabilityMode3;
12838
12860
  })(EDataAvailabilityMode || {});
12839
- var EDAMode = /* @__PURE__ */ ((EDAMode3) => {
12840
- EDAMode3[EDAMode3["L1"] = 0] = "L1";
12841
- EDAMode3[EDAMode3["L2"] = 1] = "L2";
12842
- return EDAMode3;
12861
+ var EDAMode = /* @__PURE__ */ ((EDAMode4) => {
12862
+ EDAMode4[EDAMode4["L1"] = 0] = "L1";
12863
+ EDAMode4[EDAMode4["L2"] = 1] = "L2";
12864
+ return EDAMode4;
12843
12865
  })(EDAMode || {});
12844
- var ETransactionVersion = /* @__PURE__ */ ((ETransactionVersion4) => {
12845
- ETransactionVersion4["V0"] = "0x0";
12846
- ETransactionVersion4["V1"] = "0x1";
12847
- ETransactionVersion4["V2"] = "0x2";
12848
- ETransactionVersion4["V3"] = "0x3";
12849
- ETransactionVersion4["F0"] = "0x100000000000000000000000000000000";
12850
- ETransactionVersion4["F1"] = "0x100000000000000000000000000000001";
12851
- ETransactionVersion4["F2"] = "0x100000000000000000000000000000002";
12852
- ETransactionVersion4["F3"] = "0x100000000000000000000000000000003";
12853
- return ETransactionVersion4;
12866
+ var ETransactionVersion = /* @__PURE__ */ ((ETransactionVersion5) => {
12867
+ ETransactionVersion5["V0"] = "0x0";
12868
+ ETransactionVersion5["V1"] = "0x1";
12869
+ ETransactionVersion5["V2"] = "0x2";
12870
+ ETransactionVersion5["V3"] = "0x3";
12871
+ ETransactionVersion5["F0"] = "0x100000000000000000000000000000000";
12872
+ ETransactionVersion5["F1"] = "0x100000000000000000000000000000001";
12873
+ ETransactionVersion5["F2"] = "0x100000000000000000000000000000002";
12874
+ ETransactionVersion5["F3"] = "0x100000000000000000000000000000003";
12875
+ return ETransactionVersion5;
12854
12876
  })(ETransactionVersion || {});
12855
- var ETransactionVersion2 = /* @__PURE__ */ ((ETransactionVersion23) => {
12856
- ETransactionVersion23["V0"] = "0x0";
12857
- ETransactionVersion23["V1"] = "0x1";
12858
- ETransactionVersion23["V2"] = "0x2";
12859
- ETransactionVersion23["F0"] = "0x100000000000000000000000000000000";
12860
- ETransactionVersion23["F1"] = "0x100000000000000000000000000000001";
12861
- ETransactionVersion23["F2"] = "0x100000000000000000000000000000002";
12862
- return ETransactionVersion23;
12877
+ var ETransactionVersion2 = /* @__PURE__ */ ((ETransactionVersion24) => {
12878
+ ETransactionVersion24["V0"] = "0x0";
12879
+ ETransactionVersion24["V1"] = "0x1";
12880
+ ETransactionVersion24["V2"] = "0x2";
12881
+ ETransactionVersion24["F0"] = "0x100000000000000000000000000000000";
12882
+ ETransactionVersion24["F1"] = "0x100000000000000000000000000000001";
12883
+ ETransactionVersion24["F2"] = "0x100000000000000000000000000000002";
12884
+ return ETransactionVersion24;
12863
12885
  })(ETransactionVersion2 || {});
12864
- var ETransactionVersion3 = /* @__PURE__ */ ((ETransactionVersion33) => {
12865
- ETransactionVersion33["V3"] = "0x3";
12866
- ETransactionVersion33["F3"] = "0x100000000000000000000000000000003";
12867
- return ETransactionVersion33;
12886
+ var ETransactionVersion3 = /* @__PURE__ */ ((ETransactionVersion34) => {
12887
+ ETransactionVersion34["V3"] = "0x3";
12888
+ ETransactionVersion34["F3"] = "0x100000000000000000000000000000003";
12889
+ return ETransactionVersion34;
12868
12890
  })(ETransactionVersion3 || {});
12869
12891
 
12892
+ // src/types/api/rpcspec_0_7/index.ts
12893
+ var rpcspec_0_7_exports = {};
12894
+ __export(rpcspec_0_7_exports, {
12895
+ EBlockTag: () => EBlockTag2,
12896
+ EDAMode: () => EDAMode2,
12897
+ EDataAvailabilityMode: () => EDataAvailabilityMode2,
12898
+ ESimulationFlag: () => ESimulationFlag2,
12899
+ ETransactionExecutionStatus: () => ETransactionExecutionStatus2,
12900
+ ETransactionFinalityStatus: () => ETransactionFinalityStatus2,
12901
+ ETransactionStatus: () => ETransactionStatus2,
12902
+ ETransactionType: () => ETransactionType2,
12903
+ ETransactionVersion: () => ETransactionVersion4,
12904
+ ETransactionVersion2: () => ETransactionVersion22,
12905
+ ETransactionVersion3: () => ETransactionVersion32,
12906
+ Errors: () => errors_exports2,
12907
+ SPEC: () => components_exports2
12908
+ });
12909
+
12910
+ // src/types/api/rpcspec_0_7/errors.ts
12911
+ var errors_exports2 = {};
12912
+
12913
+ // src/types/api/rpcspec_0_7/components.ts
12914
+ var components_exports2 = {};
12915
+
12916
+ // src/types/api/rpcspec_0_7/nonspec.ts
12917
+ var ETransactionType2 = /* @__PURE__ */ ((ETransactionType3) => {
12918
+ ETransactionType3["DECLARE"] = "DECLARE";
12919
+ ETransactionType3["DEPLOY"] = "DEPLOY";
12920
+ ETransactionType3["DEPLOY_ACCOUNT"] = "DEPLOY_ACCOUNT";
12921
+ ETransactionType3["INVOKE"] = "INVOKE";
12922
+ ETransactionType3["L1_HANDLER"] = "L1_HANDLER";
12923
+ return ETransactionType3;
12924
+ })(ETransactionType2 || {});
12925
+ var ESimulationFlag2 = /* @__PURE__ */ ((ESimulationFlag3) => {
12926
+ ESimulationFlag3["SKIP_VALIDATE"] = "SKIP_VALIDATE";
12927
+ ESimulationFlag3["SKIP_FEE_CHARGE"] = "SKIP_FEE_CHARGE";
12928
+ return ESimulationFlag3;
12929
+ })(ESimulationFlag2 || {});
12930
+ var ETransactionStatus2 = /* @__PURE__ */ ((ETransactionStatus3) => {
12931
+ ETransactionStatus3["RECEIVED"] = "RECEIVED";
12932
+ ETransactionStatus3["REJECTED"] = "REJECTED";
12933
+ ETransactionStatus3["ACCEPTED_ON_L2"] = "ACCEPTED_ON_L2";
12934
+ ETransactionStatus3["ACCEPTED_ON_L1"] = "ACCEPTED_ON_L1";
12935
+ return ETransactionStatus3;
12936
+ })(ETransactionStatus2 || {});
12937
+ var ETransactionFinalityStatus2 = /* @__PURE__ */ ((ETransactionFinalityStatus3) => {
12938
+ ETransactionFinalityStatus3["ACCEPTED_ON_L2"] = "ACCEPTED_ON_L2";
12939
+ ETransactionFinalityStatus3["ACCEPTED_ON_L1"] = "ACCEPTED_ON_L1";
12940
+ return ETransactionFinalityStatus3;
12941
+ })(ETransactionFinalityStatus2 || {});
12942
+ var ETransactionExecutionStatus2 = /* @__PURE__ */ ((ETransactionExecutionStatus3) => {
12943
+ ETransactionExecutionStatus3["SUCCEEDED"] = "SUCCEEDED";
12944
+ ETransactionExecutionStatus3["REVERTED"] = "REVERTED";
12945
+ return ETransactionExecutionStatus3;
12946
+ })(ETransactionExecutionStatus2 || {});
12947
+ var EBlockTag2 = /* @__PURE__ */ ((EBlockTag3) => {
12948
+ EBlockTag3["LATEST"] = "latest";
12949
+ EBlockTag3["PENDING"] = "pending";
12950
+ return EBlockTag3;
12951
+ })(EBlockTag2 || {});
12952
+ var EDataAvailabilityMode2 = /* @__PURE__ */ ((EDataAvailabilityMode3) => {
12953
+ EDataAvailabilityMode3["L1"] = "L1";
12954
+ EDataAvailabilityMode3["L2"] = "L2";
12955
+ return EDataAvailabilityMode3;
12956
+ })(EDataAvailabilityMode2 || {});
12957
+ var EDAMode2 = /* @__PURE__ */ ((EDAMode4) => {
12958
+ EDAMode4[EDAMode4["L1"] = 0] = "L1";
12959
+ EDAMode4[EDAMode4["L2"] = 1] = "L2";
12960
+ return EDAMode4;
12961
+ })(EDAMode2 || {});
12962
+ var ETransactionVersion4 = /* @__PURE__ */ ((ETransactionVersion5) => {
12963
+ ETransactionVersion5["V0"] = "0x0";
12964
+ ETransactionVersion5["V1"] = "0x1";
12965
+ ETransactionVersion5["V2"] = "0x2";
12966
+ ETransactionVersion5["V3"] = "0x3";
12967
+ ETransactionVersion5["F0"] = "0x100000000000000000000000000000000";
12968
+ ETransactionVersion5["F1"] = "0x100000000000000000000000000000001";
12969
+ ETransactionVersion5["F2"] = "0x100000000000000000000000000000002";
12970
+ ETransactionVersion5["F3"] = "0x100000000000000000000000000000003";
12971
+ return ETransactionVersion5;
12972
+ })(ETransactionVersion4 || {});
12973
+ var ETransactionVersion22 = /* @__PURE__ */ ((ETransactionVersion24) => {
12974
+ ETransactionVersion24["V0"] = "0x0";
12975
+ ETransactionVersion24["V1"] = "0x1";
12976
+ ETransactionVersion24["V2"] = "0x2";
12977
+ ETransactionVersion24["F0"] = "0x100000000000000000000000000000000";
12978
+ ETransactionVersion24["F1"] = "0x100000000000000000000000000000001";
12979
+ ETransactionVersion24["F2"] = "0x100000000000000000000000000000002";
12980
+ return ETransactionVersion24;
12981
+ })(ETransactionVersion22 || {});
12982
+ var ETransactionVersion32 = /* @__PURE__ */ ((ETransactionVersion34) => {
12983
+ ETransactionVersion34["V3"] = "0x3";
12984
+ ETransactionVersion34["F3"] = "0x100000000000000000000000000000003";
12985
+ return ETransactionVersion34;
12986
+ })(ETransactionVersion32 || {});
12987
+
12870
12988
  // src/utils/encode.ts
12871
12989
  var encode_exports = {};
12872
12990
  __export(encode_exports, {
@@ -13119,11 +13237,11 @@ var starknet = (() => {
13119
13237
  NetworkName2["SN_SEPOLIA"] = "SN_SEPOLIA";
13120
13238
  return NetworkName2;
13121
13239
  })(NetworkName || {});
13122
- var StarknetChainId = /* @__PURE__ */ ((StarknetChainId5) => {
13123
- StarknetChainId5["SN_MAIN"] = "0x534e5f4d41494e";
13124
- StarknetChainId5["SN_GOERLI"] = "0x534e5f474f45524c49";
13125
- StarknetChainId5["SN_SEPOLIA"] = "0x534e5f5345504f4c4941";
13126
- return StarknetChainId5;
13240
+ var StarknetChainId = /* @__PURE__ */ ((StarknetChainId6) => {
13241
+ StarknetChainId6["SN_MAIN"] = "0x534e5f4d41494e";
13242
+ StarknetChainId6["SN_GOERLI"] = "0x534e5f474f45524c49";
13243
+ StarknetChainId6["SN_SEPOLIA"] = "0x534e5f5345504f4c4941";
13244
+ return StarknetChainId6;
13127
13245
  })(StarknetChainId || {});
13128
13246
  var TransactionHashPrefix = /* @__PURE__ */ ((TransactionHashPrefix2) => {
13129
13247
  TransactionHashPrefix2["DECLARE"] = "0x6465636c617265";
@@ -13190,6 +13308,12 @@ var starknet = (() => {
13190
13308
  }
13191
13309
  };
13192
13310
 
13311
+ // src/channel/rpc_0_6.ts
13312
+ var rpc_0_6_exports = {};
13313
+ __export(rpc_0_6_exports, {
13314
+ RpcChannel: () => RpcChannel
13315
+ });
13316
+
13193
13317
  // src/types/index.ts
13194
13318
  var types_exports = {};
13195
13319
  __export(types_exports, {
@@ -22881,10 +23005,10 @@ var starknet = (() => {
22881
23005
  function toTransactionVersion(defaultVersion, providedVersion) {
22882
23006
  const providedVersion0xs = providedVersion ? toHex(providedVersion) : void 0;
22883
23007
  const defaultVersion0xs = toHex(defaultVersion);
22884
- if (providedVersion && !Object.values(ETransactionVersion).includes(providedVersion0xs)) {
23008
+ if (providedVersion && !Object.values(ETransactionVersion4).includes(providedVersion0xs)) {
22885
23009
  throw Error(`providedVersion ${providedVersion} is not ETransactionVersion`);
22886
23010
  }
22887
- if (!Object.values(ETransactionVersion).includes(defaultVersion0xs)) {
23011
+ if (!Object.values(ETransactionVersion4).includes(defaultVersion0xs)) {
22888
23012
  throw Error(`defaultVersion ${defaultVersion} is not ETransactionVersion`);
22889
23013
  }
22890
23014
  return providedVersion ? providedVersion0xs : defaultVersion0xs;
@@ -23327,11 +23451,11 @@ var starknet = (() => {
23327
23451
  requestId;
23328
23452
  blockIdentifier;
23329
23453
  chainId;
23330
- speckVersion;
23454
+ specVersion;
23331
23455
  waitMode;
23332
23456
  // behave like web2 rpc and return when tx is processed
23333
23457
  constructor(optionsOrProvider) {
23334
- const { nodeUrl, retries, headers, blockIdentifier, chainId, waitMode } = optionsOrProvider || {};
23458
+ const { nodeUrl, retries, headers, blockIdentifier, chainId, specVersion, waitMode } = optionsOrProvider || {};
23335
23459
  if (Object.values(NetworkName).includes(nodeUrl)) {
23336
23460
  this.nodeUrl = getDefaultNodeUrl(nodeUrl, optionsOrProvider?.default);
23337
23461
  } else if (nodeUrl) {
@@ -23343,6 +23467,7 @@ var starknet = (() => {
23343
23467
  this.headers = { ...defaultOptions.headers, ...headers };
23344
23468
  this.blockIdentifier = blockIdentifier || defaultOptions.blockIdentifier;
23345
23469
  this.chainId = chainId;
23470
+ this.specVersion = specVersion;
23346
23471
  this.waitMode = waitMode || false;
23347
23472
  this.requestId = 0;
23348
23473
  }
@@ -23391,8 +23516,8 @@ var starknet = (() => {
23391
23516
  return this.chainId;
23392
23517
  }
23393
23518
  async getSpecVersion() {
23394
- this.speckVersion ??= await this.fetchEndpoint("starknet_specVersion");
23395
- return this.speckVersion;
23519
+ this.specVersion ??= await this.fetchEndpoint("starknet_specVersion");
23520
+ return this.specVersion;
23396
23521
  }
23397
23522
  getNonceForAddress(contractAddress, blockIdentifier = this.blockIdentifier) {
23398
23523
  const contract_address = toHex(contractAddress);
@@ -23476,9 +23601,9 @@ var starknet = (() => {
23476
23601
  const block_id = new Block(blockIdentifier).identifier;
23477
23602
  const simulationFlags = [];
23478
23603
  if (skipValidate)
23479
- simulationFlags.push(api_exports.ESimulationFlag.SKIP_VALIDATE);
23604
+ simulationFlags.push(rpcspec_0_6_exports.ESimulationFlag.SKIP_VALIDATE);
23480
23605
  if (skipFeeCharge)
23481
- simulationFlags.push(api_exports.ESimulationFlag.SKIP_FEE_CHARGE);
23606
+ simulationFlags.push(rpcspec_0_6_exports.ESimulationFlag.SKIP_FEE_CHARGE);
23482
23607
  return this.fetchEndpoint("starknet_simulateTransactions", {
23483
23608
  block_id,
23484
23609
  transactions: invocations.map((it) => this.buildTransaction(it)),
@@ -23492,15 +23617,15 @@ var starknet = (() => {
23492
23617
  let isErrorState = false;
23493
23618
  const retryInterval = options?.retryInterval ?? 5e3;
23494
23619
  const errorStates = options?.errorStates ?? [
23495
- api_exports.ETransactionStatus.REJECTED
23620
+ rpcspec_0_6_exports.ETransactionStatus.REJECTED
23496
23621
  // TODO: commented out to preserve the long-standing behavior of "reverted" not being treated as an error by default
23497
23622
  // should decide which behavior to keep in the future
23498
23623
  // RPC.ETransactionExecutionStatus.REVERTED,
23499
23624
  ];
23500
23625
  const successStates = options?.successStates ?? [
23501
- api_exports.ETransactionExecutionStatus.SUCCEEDED,
23502
- api_exports.ETransactionStatus.ACCEPTED_ON_L2,
23503
- api_exports.ETransactionStatus.ACCEPTED_ON_L1
23626
+ rpcspec_0_6_exports.ETransactionExecutionStatus.SUCCEEDED,
23627
+ rpcspec_0_6_exports.ETransactionStatus.ACCEPTED_ON_L2,
23628
+ rpcspec_0_6_exports.ETransactionStatus.ACCEPTED_ON_L1
23504
23629
  ];
23505
23630
  let txStatus;
23506
23631
  while (!onchain) {
@@ -23583,9 +23708,9 @@ var starknet = (() => {
23583
23708
  async getEstimateFee(invocations, { blockIdentifier = this.blockIdentifier, skipValidate = true }) {
23584
23709
  const block_id = new Block(blockIdentifier).identifier;
23585
23710
  let flags = {};
23586
- if (isVersion("0.6", await this.getSpecVersion())) {
23711
+ if (!isVersion("0.5", await this.getSpecVersion())) {
23587
23712
  flags = {
23588
- simulation_flags: skipValidate ? [api_exports.ESimulationFlag.SKIP_VALIDATE] : []
23713
+ simulation_flags: skipValidate ? [rpcspec_0_6_exports.ESimulationFlag.SKIP_VALIDATE] : []
23589
23714
  };
23590
23715
  }
23591
23716
  return this.fetchEndpoint("starknet_estimateFee", {
@@ -23601,9 +23726,9 @@ var starknet = (() => {
23601
23726
  invoke_transaction: {
23602
23727
  sender_address: functionInvocation.contractAddress,
23603
23728
  calldata: CallData.toHex(functionInvocation.calldata),
23604
- type: api_exports.ETransactionType.INVOKE,
23729
+ type: rpcspec_0_6_exports.ETransactionType.INVOKE,
23605
23730
  max_fee: toHex(details.maxFee || 0),
23606
- version: "0x1" /* V1 */,
23731
+ version: rpcspec_0_6_exports.ETransactionVersion.V1,
23607
23732
  signature: signatureToHexArray(functionInvocation.signature),
23608
23733
  nonce: toHex(details.nonce)
23609
23734
  }
@@ -23611,10 +23736,10 @@ var starknet = (() => {
23611
23736
  } else {
23612
23737
  promise = this.fetchEndpoint("starknet_addInvokeTransaction", {
23613
23738
  invoke_transaction: {
23614
- type: api_exports.ETransactionType.INVOKE,
23739
+ type: rpcspec_0_6_exports.ETransactionType.INVOKE,
23615
23740
  sender_address: functionInvocation.contractAddress,
23616
23741
  calldata: CallData.toHex(functionInvocation.calldata),
23617
- version: "0x3" /* V3 */,
23742
+ version: rpcspec_0_6_exports.ETransactionVersion.V3,
23618
23743
  signature: signatureToHexArray(functionInvocation.signature),
23619
23744
  nonce: toHex(details.nonce),
23620
23745
  resource_bounds: details.resourceBounds,
@@ -23633,13 +23758,13 @@ var starknet = (() => {
23633
23758
  if (!isSierra(contract) && !isV3Tx(details)) {
23634
23759
  promise = this.fetchEndpoint("starknet_addDeclareTransaction", {
23635
23760
  declare_transaction: {
23636
- type: api_exports.ETransactionType.DECLARE,
23761
+ type: rpcspec_0_6_exports.ETransactionType.DECLARE,
23637
23762
  contract_class: {
23638
23763
  program: contract.program,
23639
23764
  entry_points_by_type: contract.entry_points_by_type,
23640
23765
  abi: contract.abi
23641
23766
  },
23642
- version: "0x1" /* V1 */,
23767
+ version: rpcspec_0_6_exports.ETransactionVersion.V1,
23643
23768
  max_fee: toHex(details.maxFee || 0),
23644
23769
  signature: signatureToHexArray(signature),
23645
23770
  sender_address: senderAddress,
@@ -23649,7 +23774,7 @@ var starknet = (() => {
23649
23774
  } else if (isSierra(contract) && !isV3Tx(details)) {
23650
23775
  promise = this.fetchEndpoint("starknet_addDeclareTransaction", {
23651
23776
  declare_transaction: {
23652
- type: api_exports.ETransactionType.DECLARE,
23777
+ type: rpcspec_0_6_exports.ETransactionType.DECLARE,
23653
23778
  contract_class: {
23654
23779
  sierra_program: decompressProgram(contract.sierra_program),
23655
23780
  contract_class_version: contract.contract_class_version,
@@ -23657,7 +23782,7 @@ var starknet = (() => {
23657
23782
  abi: contract.abi
23658
23783
  },
23659
23784
  compiled_class_hash: compiledClassHash || "",
23660
- version: "0x2" /* V2 */,
23785
+ version: rpcspec_0_6_exports.ETransactionVersion.V2,
23661
23786
  max_fee: toHex(details.maxFee || 0),
23662
23787
  signature: signatureToHexArray(signature),
23663
23788
  sender_address: senderAddress,
@@ -23667,10 +23792,10 @@ var starknet = (() => {
23667
23792
  } else if (isSierra(contract) && isV3Tx(details)) {
23668
23793
  promise = this.fetchEndpoint("starknet_addDeclareTransaction", {
23669
23794
  declare_transaction: {
23670
- type: api_exports.ETransactionType.DECLARE,
23795
+ type: rpcspec_0_6_exports.ETransactionType.DECLARE,
23671
23796
  sender_address: senderAddress,
23672
23797
  compiled_class_hash: compiledClassHash || "",
23673
- version: "0x3" /* V3 */,
23798
+ version: rpcspec_0_6_exports.ETransactionVersion.V3,
23674
23799
  signature: signatureToHexArray(signature),
23675
23800
  nonce: toHex(details.nonce),
23676
23801
  contract_class: {
@@ -23700,9 +23825,9 @@ var starknet = (() => {
23700
23825
  constructor_calldata: CallData.toHex(constructorCalldata || []),
23701
23826
  class_hash: toHex(classHash),
23702
23827
  contract_address_salt: toHex(addressSalt || 0),
23703
- type: api_exports.ETransactionType.DEPLOY_ACCOUNT,
23828
+ type: rpcspec_0_6_exports.ETransactionType.DEPLOY_ACCOUNT,
23704
23829
  max_fee: toHex(details.maxFee || 0),
23705
- version: "0x1" /* V1 */,
23830
+ version: rpcspec_0_6_exports.ETransactionVersion.V1,
23706
23831
  signature: signatureToHexArray(signature),
23707
23832
  nonce: toHex(details.nonce)
23708
23833
  }
@@ -23710,8 +23835,8 @@ var starknet = (() => {
23710
23835
  } else {
23711
23836
  promise = this.fetchEndpoint("starknet_addDeployAccountTransaction", {
23712
23837
  deploy_account_transaction: {
23713
- type: api_exports.ETransactionType.DEPLOY_ACCOUNT,
23714
- version: "0x3" /* V3 */,
23838
+ type: rpcspec_0_6_exports.ETransactionType.DEPLOY_ACCOUNT,
23839
+ version: rpcspec_0_6_exports.ETransactionVersion.V3,
23715
23840
  signature: signatureToHexArray(signature),
23716
23841
  nonce: toHex(details.nonce),
23717
23842
  contract_address_salt: toHex(addressSalt || 0),
@@ -23794,7 +23919,7 @@ var starknet = (() => {
23794
23919
  if (invocation.type === "INVOKE_FUNCTION" /* INVOKE */) {
23795
23920
  return {
23796
23921
  // v0 v1 v3
23797
- type: api_exports.ETransactionType.INVOKE,
23922
+ type: rpcspec_0_6_exports.ETransactionType.INVOKE,
23798
23923
  // TODO: Diff between sequencer and rpc invoke type
23799
23924
  sender_address: invocation.contractAddress,
23800
23925
  calldata: CallData.toHex(invocation.calldata),
@@ -23840,106 +23965,645 @@ var starknet = (() => {
23840
23965
  }
23841
23966
  };
23842
23967
 
23843
- // src/utils/responseParser/rpc.ts
23844
- var RPCResponseParser = class {
23845
- parseGetBlockResponse(res) {
23846
- return { status: "PENDING", ...res };
23847
- }
23848
- parseTransactionReceipt(res) {
23849
- if ("actual_fee" in res && typeof res.actual_fee === "string") {
23850
- return {
23851
- ...res,
23852
- actual_fee: {
23853
- amount: res.actual_fee,
23854
- unit: "FRI"
23855
- }
23856
- };
23968
+ // src/channel/rpc_0_7.ts
23969
+ var rpc_0_7_exports = {};
23970
+ __export(rpc_0_7_exports, {
23971
+ RpcChannel: () => RpcChannel2
23972
+ });
23973
+ var defaultOptions2 = {
23974
+ headers: { "Content-Type": "application/json" },
23975
+ blockIdentifier: "pending" /* pending */,
23976
+ retries: 200
23977
+ };
23978
+ var RpcChannel2 = class {
23979
+ nodeUrl;
23980
+ headers;
23981
+ retries;
23982
+ requestId;
23983
+ blockIdentifier;
23984
+ chainId;
23985
+ speckVersion;
23986
+ waitMode;
23987
+ // behave like web2 rpc and return when tx is processed
23988
+ constructor(optionsOrProvider) {
23989
+ const { nodeUrl, retries, headers, blockIdentifier, chainId, waitMode } = optionsOrProvider || {};
23990
+ if (Object.values(NetworkName).includes(nodeUrl)) {
23991
+ this.nodeUrl = getDefaultNodeUrl(nodeUrl, optionsOrProvider?.default);
23992
+ } else if (nodeUrl) {
23993
+ this.nodeUrl = nodeUrl;
23994
+ } else {
23995
+ this.nodeUrl = getDefaultNodeUrl(void 0, optionsOrProvider?.default);
23857
23996
  }
23858
- return res;
23997
+ this.retries = retries || defaultOptions2.retries;
23998
+ this.headers = { ...defaultOptions2.headers, ...headers };
23999
+ this.blockIdentifier = blockIdentifier || defaultOptions2.blockIdentifier;
24000
+ this.chainId = chainId;
24001
+ this.waitMode = waitMode || false;
24002
+ this.requestId = 0;
23859
24003
  }
23860
- parseFeeEstimateResponse(res) {
23861
- const val = res[0];
23862
- return {
23863
- overall_fee: toBigInt(val.overall_fee),
23864
- gas_consumed: toBigInt(val.gas_consumed),
23865
- gas_price: toBigInt(val.gas_price),
23866
- unit: val.unit,
23867
- suggestedMaxFee: estimatedFeeToMaxFee(val.overall_fee),
23868
- resourceBounds: estimateFeeToBounds(val)
24004
+ fetch(method, params, id = 0) {
24005
+ const rpcRequestBody = {
24006
+ id,
24007
+ jsonrpc: "2.0",
24008
+ method,
24009
+ ...params && { params }
23869
24010
  };
23870
- }
23871
- parseFeeEstimateBulkResponse(res) {
23872
- return res.map((val) => ({
23873
- overall_fee: toBigInt(val.overall_fee),
23874
- gas_consumed: toBigInt(val.gas_consumed),
23875
- gas_price: toBigInt(val.gas_price),
23876
- unit: val.unit,
23877
- suggestedMaxFee: estimatedFeeToMaxFee(val.overall_fee),
23878
- resourceBounds: estimateFeeToBounds(val)
23879
- }));
23880
- }
23881
- parseSimulateTransactionResponse(res) {
23882
- return res.map((it) => {
23883
- return {
23884
- ...it,
23885
- suggestedMaxFee: estimatedFeeToMaxFee(BigInt(it.fee_estimation.overall_fee)),
23886
- resourceBounds: estimateFeeToBounds(it.fee_estimation)
23887
- };
24011
+ return fetchPonyfill_default(this.nodeUrl, {
24012
+ method: "POST",
24013
+ body: stringify2(rpcRequestBody),
24014
+ headers: this.headers
23888
24015
  });
23889
24016
  }
23890
- parseContractClassResponse(res) {
23891
- return {
23892
- ...res,
23893
- abi: typeof res.abi === "string" ? JSON.parse(res.abi) : res.abi
23894
- };
23895
- }
23896
- };
23897
-
23898
- // src/provider/rpc.ts
23899
- var RpcProvider = class {
23900
- responseParser = new RPCResponseParser();
23901
- channel;
23902
- constructor(optionsOrProvider) {
23903
- if (optionsOrProvider && "channel" in optionsOrProvider) {
23904
- this.channel = optionsOrProvider.channel;
23905
- } else {
23906
- this.channel = new RpcChannel({ ...optionsOrProvider, waitMode: false });
24017
+ errorHandler(method, params, rpcError, otherError) {
24018
+ if (rpcError) {
24019
+ const { code, message, data } = rpcError;
24020
+ throw new LibraryError(
24021
+ `RPC: ${method} with params ${stringify2(params, null, 2)}
24022
+
24023
+ ${code}: ${message}: ${stringify2(data)}`
24024
+ );
24025
+ }
24026
+ if (otherError instanceof LibraryError) {
24027
+ throw otherError;
24028
+ }
24029
+ if (otherError) {
24030
+ throw Error(otherError.message);
23907
24031
  }
23908
24032
  }
23909
- fetch(method, params, id = 0) {
23910
- return this.channel.fetch(method, params, id);
24033
+ async fetchEndpoint(method, params) {
24034
+ try {
24035
+ const rawResult = await this.fetch(method, params, this.requestId += 1);
24036
+ const { error: error2, result } = await rawResult.json();
24037
+ this.errorHandler(method, params, error2);
24038
+ return result;
24039
+ } catch (error2) {
24040
+ this.errorHandler(method, params, error2?.response?.data, error2);
24041
+ throw error2;
24042
+ }
23911
24043
  }
23912
24044
  async getChainId() {
23913
- return this.channel.getChainId();
24045
+ this.chainId ??= await this.fetchEndpoint("starknet_chainId");
24046
+ return this.chainId;
23914
24047
  }
23915
24048
  async getSpecVersion() {
23916
- return this.channel.getSpecVersion();
23917
- }
23918
- async getNonceForAddress(contractAddress, blockIdentifier) {
23919
- return this.channel.getNonceForAddress(contractAddress, blockIdentifier);
24049
+ this.speckVersion ??= await this.fetchEndpoint("starknet_specVersion");
24050
+ return this.speckVersion;
23920
24051
  }
23921
- async getBlock(blockIdentifier) {
23922
- return this.channel.getBlockWithTxHashes(blockIdentifier).then(this.responseParser.parseGetBlockResponse);
24052
+ getNonceForAddress(contractAddress, blockIdentifier = this.blockIdentifier) {
24053
+ const contract_address = toHex(contractAddress);
24054
+ const block_id = new Block(blockIdentifier).identifier;
24055
+ return this.fetchEndpoint("starknet_getNonce", {
24056
+ contract_address,
24057
+ block_id
24058
+ });
23923
24059
  }
23924
24060
  /**
23925
24061
  * Get the most recent accepted block hash and number
23926
24062
  */
23927
- async getBlockLatestAccepted() {
23928
- return this.channel.getBlockLatestAccepted();
24063
+ getBlockLatestAccepted() {
24064
+ return this.fetchEndpoint("starknet_blockHashAndNumber");
23929
24065
  }
23930
24066
  /**
23931
24067
  * Get the most recent accepted block number
23932
24068
  * redundant use getBlockLatestAccepted();
23933
24069
  * @returns Number of the latest block
23934
24070
  */
23935
- async getBlockNumber() {
23936
- return this.channel.getBlockNumber();
24071
+ getBlockNumber() {
24072
+ return this.fetchEndpoint("starknet_blockNumber");
23937
24073
  }
23938
- async getBlockWithTxHashes(blockIdentifier) {
23939
- return this.channel.getBlockWithTxHashes(blockIdentifier);
24074
+ getBlockWithTxHashes(blockIdentifier = this.blockIdentifier) {
24075
+ const block_id = new Block(blockIdentifier).identifier;
24076
+ return this.fetchEndpoint("starknet_getBlockWithTxHashes", { block_id });
23940
24077
  }
23941
- async getBlockWithTxs(blockIdentifier) {
23942
- return this.channel.getBlockWithTxs(blockIdentifier);
24078
+ getBlockWithTxs(blockIdentifier = this.blockIdentifier) {
24079
+ const block_id = new Block(blockIdentifier).identifier;
24080
+ return this.fetchEndpoint("starknet_getBlockWithTxs", { block_id });
24081
+ }
24082
+ getBlockWithReceipts(blockIdentifier = this.blockIdentifier) {
24083
+ const block_id = new Block(blockIdentifier).identifier;
24084
+ return this.fetchEndpoint("starknet_getBlockWithReceipts", { block_id });
24085
+ }
24086
+ getBlockStateUpdate(blockIdentifier = this.blockIdentifier) {
24087
+ const block_id = new Block(blockIdentifier).identifier;
24088
+ return this.fetchEndpoint("starknet_getStateUpdate", { block_id });
24089
+ }
24090
+ getBlockTransactionsTraces(blockIdentifier = this.blockIdentifier) {
24091
+ const block_id = new Block(blockIdentifier).identifier;
24092
+ return this.fetchEndpoint("starknet_traceBlockTransactions", { block_id });
24093
+ }
24094
+ getBlockTransactionCount(blockIdentifier = this.blockIdentifier) {
24095
+ const block_id = new Block(blockIdentifier).identifier;
24096
+ return this.fetchEndpoint("starknet_getBlockTransactionCount", { block_id });
24097
+ }
24098
+ getTransactionByHash(txHash) {
24099
+ const transaction_hash = toHex(txHash);
24100
+ return this.fetchEndpoint("starknet_getTransactionByHash", {
24101
+ transaction_hash
24102
+ });
24103
+ }
24104
+ getTransactionByBlockIdAndIndex(blockIdentifier, index) {
24105
+ const block_id = new Block(blockIdentifier).identifier;
24106
+ return this.fetchEndpoint("starknet_getTransactionByBlockIdAndIndex", { block_id, index });
24107
+ }
24108
+ getTransactionReceipt(txHash) {
24109
+ const transaction_hash = toHex(txHash);
24110
+ return this.fetchEndpoint("starknet_getTransactionReceipt", { transaction_hash });
24111
+ }
24112
+ getTransactionTrace(txHash) {
24113
+ const transaction_hash = toHex(txHash);
24114
+ return this.fetchEndpoint("starknet_traceTransaction", { transaction_hash });
24115
+ }
24116
+ /**
24117
+ * Get the status of a transaction
24118
+ */
24119
+ getTransactionStatus(transactionHash) {
24120
+ const transaction_hash = toHex(transactionHash);
24121
+ return this.fetchEndpoint("starknet_getTransactionStatus", { transaction_hash });
24122
+ }
24123
+ /**
24124
+ * @param invocations AccountInvocations
24125
+ * @param simulateTransactionOptions blockIdentifier and flags to skip validation and fee charge<br/>
24126
+ * - blockIdentifier<br/>
24127
+ * - skipValidate (default false)<br/>
24128
+ * - skipFeeCharge (default true)<br/>
24129
+ */
24130
+ simulateTransaction(invocations, {
24131
+ blockIdentifier = this.blockIdentifier,
24132
+ skipValidate = true,
24133
+ skipFeeCharge = true
24134
+ } = {}) {
24135
+ const block_id = new Block(blockIdentifier).identifier;
24136
+ const simulationFlags = [];
24137
+ if (skipValidate)
24138
+ simulationFlags.push(rpcspec_0_7_exports.ESimulationFlag.SKIP_VALIDATE);
24139
+ if (skipFeeCharge)
24140
+ simulationFlags.push(rpcspec_0_7_exports.ESimulationFlag.SKIP_FEE_CHARGE);
24141
+ return this.fetchEndpoint("starknet_simulateTransactions", {
24142
+ block_id,
24143
+ transactions: invocations.map((it) => this.buildTransaction(it)),
24144
+ simulation_flags: simulationFlags
24145
+ });
24146
+ }
24147
+ async waitForTransaction(txHash, options) {
24148
+ const transactionHash = toHex(txHash);
24149
+ let { retries } = this;
24150
+ let onchain = false;
24151
+ let isErrorState = false;
24152
+ const retryInterval = options?.retryInterval ?? 5e3;
24153
+ const errorStates = options?.errorStates ?? [
24154
+ rpcspec_0_7_exports.ETransactionStatus.REJECTED
24155
+ // TODO: commented out to preserve the long-standing behavior of "reverted" not being treated as an error by default
24156
+ // should decide which behavior to keep in the future
24157
+ // RPC.ETransactionExecutionStatus.REVERTED,
24158
+ ];
24159
+ const successStates = options?.successStates ?? [
24160
+ rpcspec_0_7_exports.ETransactionExecutionStatus.SUCCEEDED,
24161
+ rpcspec_0_7_exports.ETransactionStatus.ACCEPTED_ON_L2,
24162
+ rpcspec_0_7_exports.ETransactionStatus.ACCEPTED_ON_L1
24163
+ ];
24164
+ let txStatus;
24165
+ while (!onchain) {
24166
+ await wait(retryInterval);
24167
+ try {
24168
+ txStatus = await this.getTransactionStatus(transactionHash);
24169
+ const executionStatus = txStatus.execution_status;
24170
+ const finalityStatus = txStatus.finality_status;
24171
+ if (!finalityStatus) {
24172
+ const error2 = new Error("waiting for transaction status");
24173
+ throw error2;
24174
+ }
24175
+ if (errorStates.includes(executionStatus) || errorStates.includes(finalityStatus)) {
24176
+ const message = `${executionStatus}: ${finalityStatus}`;
24177
+ const error2 = new Error(message);
24178
+ error2.response = txStatus;
24179
+ isErrorState = true;
24180
+ throw error2;
24181
+ } else if (successStates.includes(executionStatus) || successStates.includes(finalityStatus)) {
24182
+ onchain = true;
24183
+ }
24184
+ } catch (error2) {
24185
+ if (error2 instanceof Error && isErrorState) {
24186
+ throw error2;
24187
+ }
24188
+ if (retries <= 0) {
24189
+ throw new Error(`waitForTransaction timed-out with retries ${this.retries}`);
24190
+ }
24191
+ }
24192
+ retries -= 1;
24193
+ }
24194
+ let txReceipt = null;
24195
+ while (txReceipt === null) {
24196
+ try {
24197
+ txReceipt = await this.getTransactionReceipt(transactionHash);
24198
+ } catch (error2) {
24199
+ if (retries <= 0) {
24200
+ throw new Error(`waitForTransaction timed-out with retries ${this.retries}`);
24201
+ }
24202
+ }
24203
+ retries -= 1;
24204
+ await wait(retryInterval);
24205
+ }
24206
+ return txReceipt;
24207
+ }
24208
+ getStorageAt(contractAddress, key, blockIdentifier = this.blockIdentifier) {
24209
+ const contract_address = toHex(contractAddress);
24210
+ const parsedKey = toStorageKey(key);
24211
+ const block_id = new Block(blockIdentifier).identifier;
24212
+ return this.fetchEndpoint("starknet_getStorageAt", {
24213
+ contract_address,
24214
+ key: parsedKey,
24215
+ block_id
24216
+ });
24217
+ }
24218
+ getClassHashAt(contractAddress, blockIdentifier = this.blockIdentifier) {
24219
+ const contract_address = toHex(contractAddress);
24220
+ const block_id = new Block(blockIdentifier).identifier;
24221
+ return this.fetchEndpoint("starknet_getClassHashAt", {
24222
+ block_id,
24223
+ contract_address
24224
+ });
24225
+ }
24226
+ getClass(classHash, blockIdentifier = this.blockIdentifier) {
24227
+ const class_hash = toHex(classHash);
24228
+ const block_id = new Block(blockIdentifier).identifier;
24229
+ return this.fetchEndpoint("starknet_getClass", {
24230
+ class_hash,
24231
+ block_id
24232
+ });
24233
+ }
24234
+ getClassAt(contractAddress, blockIdentifier = this.blockIdentifier) {
24235
+ const contract_address = toHex(contractAddress);
24236
+ const block_id = new Block(blockIdentifier).identifier;
24237
+ return this.fetchEndpoint("starknet_getClassAt", {
24238
+ block_id,
24239
+ contract_address
24240
+ });
24241
+ }
24242
+ async getEstimateFee(invocations, { blockIdentifier = this.blockIdentifier, skipValidate = true }) {
24243
+ const block_id = new Block(blockIdentifier).identifier;
24244
+ let flags = {};
24245
+ if (!isVersion("0.5", await this.getSpecVersion())) {
24246
+ flags = {
24247
+ simulation_flags: skipValidate ? [rpcspec_0_7_exports.ESimulationFlag.SKIP_VALIDATE] : []
24248
+ };
24249
+ }
24250
+ return this.fetchEndpoint("starknet_estimateFee", {
24251
+ request: invocations.map((it) => this.buildTransaction(it, "fee")),
24252
+ block_id,
24253
+ ...flags
24254
+ });
24255
+ }
24256
+ async invoke(functionInvocation, details) {
24257
+ let promise;
24258
+ if (!isV3Tx(details)) {
24259
+ promise = this.fetchEndpoint("starknet_addInvokeTransaction", {
24260
+ invoke_transaction: {
24261
+ sender_address: functionInvocation.contractAddress,
24262
+ calldata: CallData.toHex(functionInvocation.calldata),
24263
+ type: rpcspec_0_7_exports.ETransactionType.INVOKE,
24264
+ max_fee: toHex(details.maxFee || 0),
24265
+ version: rpcspec_0_7_exports.ETransactionVersion.V1,
24266
+ signature: signatureToHexArray(functionInvocation.signature),
24267
+ nonce: toHex(details.nonce)
24268
+ }
24269
+ });
24270
+ } else {
24271
+ promise = this.fetchEndpoint("starknet_addInvokeTransaction", {
24272
+ invoke_transaction: {
24273
+ type: rpcspec_0_7_exports.ETransactionType.INVOKE,
24274
+ sender_address: functionInvocation.contractAddress,
24275
+ calldata: CallData.toHex(functionInvocation.calldata),
24276
+ version: rpcspec_0_7_exports.ETransactionVersion.V3,
24277
+ signature: signatureToHexArray(functionInvocation.signature),
24278
+ nonce: toHex(details.nonce),
24279
+ resource_bounds: details.resourceBounds,
24280
+ tip: toHex(details.tip),
24281
+ paymaster_data: details.paymasterData.map((it) => toHex(it)),
24282
+ account_deployment_data: details.accountDeploymentData.map((it) => toHex(it)),
24283
+ nonce_data_availability_mode: details.nonceDataAvailabilityMode,
24284
+ fee_data_availability_mode: details.feeDataAvailabilityMode
24285
+ }
24286
+ });
24287
+ }
24288
+ return this.waitMode ? this.waitForTransaction((await promise).transaction_hash) : promise;
24289
+ }
24290
+ async declare({ contract, signature, senderAddress, compiledClassHash }, details) {
24291
+ let promise;
24292
+ if (!isSierra(contract) && !isV3Tx(details)) {
24293
+ promise = this.fetchEndpoint("starknet_addDeclareTransaction", {
24294
+ declare_transaction: {
24295
+ type: rpcspec_0_7_exports.ETransactionType.DECLARE,
24296
+ contract_class: {
24297
+ program: contract.program,
24298
+ entry_points_by_type: contract.entry_points_by_type,
24299
+ abi: contract.abi
24300
+ },
24301
+ version: rpcspec_0_7_exports.ETransactionVersion.V1,
24302
+ max_fee: toHex(details.maxFee || 0),
24303
+ signature: signatureToHexArray(signature),
24304
+ sender_address: senderAddress,
24305
+ nonce: toHex(details.nonce)
24306
+ }
24307
+ });
24308
+ } else if (isSierra(contract) && !isV3Tx(details)) {
24309
+ promise = this.fetchEndpoint("starknet_addDeclareTransaction", {
24310
+ declare_transaction: {
24311
+ type: rpcspec_0_7_exports.ETransactionType.DECLARE,
24312
+ contract_class: {
24313
+ sierra_program: decompressProgram(contract.sierra_program),
24314
+ contract_class_version: contract.contract_class_version,
24315
+ entry_points_by_type: contract.entry_points_by_type,
24316
+ abi: contract.abi
24317
+ },
24318
+ compiled_class_hash: compiledClassHash || "",
24319
+ version: rpcspec_0_7_exports.ETransactionVersion.V2,
24320
+ max_fee: toHex(details.maxFee || 0),
24321
+ signature: signatureToHexArray(signature),
24322
+ sender_address: senderAddress,
24323
+ nonce: toHex(details.nonce)
24324
+ }
24325
+ });
24326
+ } else if (isSierra(contract) && isV3Tx(details)) {
24327
+ promise = this.fetchEndpoint("starknet_addDeclareTransaction", {
24328
+ declare_transaction: {
24329
+ type: rpcspec_0_7_exports.ETransactionType.DECLARE,
24330
+ sender_address: senderAddress,
24331
+ compiled_class_hash: compiledClassHash || "",
24332
+ version: rpcspec_0_7_exports.ETransactionVersion.V3,
24333
+ signature: signatureToHexArray(signature),
24334
+ nonce: toHex(details.nonce),
24335
+ contract_class: {
24336
+ sierra_program: decompressProgram(contract.sierra_program),
24337
+ contract_class_version: contract.contract_class_version,
24338
+ entry_points_by_type: contract.entry_points_by_type,
24339
+ abi: contract.abi
24340
+ },
24341
+ resource_bounds: details.resourceBounds,
24342
+ tip: toHex(details.tip),
24343
+ paymaster_data: details.paymasterData.map((it) => toHex(it)),
24344
+ account_deployment_data: details.accountDeploymentData.map((it) => toHex(it)),
24345
+ nonce_data_availability_mode: details.nonceDataAvailabilityMode,
24346
+ fee_data_availability_mode: details.feeDataAvailabilityMode
24347
+ }
24348
+ });
24349
+ } else {
24350
+ throw Error("declare unspotted parameters");
24351
+ }
24352
+ return this.waitMode ? this.waitForTransaction((await promise).transaction_hash) : promise;
24353
+ }
24354
+ async deployAccount({ classHash, constructorCalldata, addressSalt, signature }, details) {
24355
+ let promise;
24356
+ if (!isV3Tx(details)) {
24357
+ promise = this.fetchEndpoint("starknet_addDeployAccountTransaction", {
24358
+ deploy_account_transaction: {
24359
+ constructor_calldata: CallData.toHex(constructorCalldata || []),
24360
+ class_hash: toHex(classHash),
24361
+ contract_address_salt: toHex(addressSalt || 0),
24362
+ type: rpcspec_0_7_exports.ETransactionType.DEPLOY_ACCOUNT,
24363
+ max_fee: toHex(details.maxFee || 0),
24364
+ version: rpcspec_0_7_exports.ETransactionVersion.V1,
24365
+ signature: signatureToHexArray(signature),
24366
+ nonce: toHex(details.nonce)
24367
+ }
24368
+ });
24369
+ } else {
24370
+ promise = this.fetchEndpoint("starknet_addDeployAccountTransaction", {
24371
+ deploy_account_transaction: {
24372
+ type: rpcspec_0_7_exports.ETransactionType.DEPLOY_ACCOUNT,
24373
+ version: rpcspec_0_7_exports.ETransactionVersion.V3,
24374
+ signature: signatureToHexArray(signature),
24375
+ nonce: toHex(details.nonce),
24376
+ contract_address_salt: toHex(addressSalt || 0),
24377
+ constructor_calldata: CallData.toHex(constructorCalldata || []),
24378
+ class_hash: toHex(classHash),
24379
+ resource_bounds: details.resourceBounds,
24380
+ tip: toHex(details.tip),
24381
+ paymaster_data: details.paymasterData.map((it) => toHex(it)),
24382
+ nonce_data_availability_mode: details.nonceDataAvailabilityMode,
24383
+ fee_data_availability_mode: details.feeDataAvailabilityMode
24384
+ }
24385
+ });
24386
+ }
24387
+ return this.waitMode ? this.waitForTransaction((await promise).transaction_hash) : promise;
24388
+ }
24389
+ callContract(call, blockIdentifier = this.blockIdentifier) {
24390
+ const block_id = new Block(blockIdentifier).identifier;
24391
+ return this.fetchEndpoint("starknet_call", {
24392
+ request: {
24393
+ contract_address: call.contractAddress,
24394
+ entry_point_selector: getSelectorFromName(call.entrypoint),
24395
+ calldata: CallData.toHex(call.calldata)
24396
+ },
24397
+ block_id
24398
+ });
24399
+ }
24400
+ /**
24401
+ * NEW: Estimate the fee for a message from L1
24402
+ * @param message Message From L1
24403
+ */
24404
+ estimateMessageFee(message, blockIdentifier = this.blockIdentifier) {
24405
+ const { from_address, to_address, entry_point_selector, payload } = message;
24406
+ const formattedMessage = {
24407
+ from_address: toHex(from_address),
24408
+ to_address: toHex(to_address),
24409
+ entry_point_selector: getSelector(entry_point_selector),
24410
+ payload: getHexStringArray(payload)
24411
+ };
24412
+ const block_id = new Block(blockIdentifier).identifier;
24413
+ return this.fetchEndpoint("starknet_estimateMessageFee", {
24414
+ message: formattedMessage,
24415
+ block_id
24416
+ });
24417
+ }
24418
+ /**
24419
+ * Returns an object about the sync status, or false if the node is not synching
24420
+ * @returns Object with the stats data
24421
+ */
24422
+ getSyncingStats() {
24423
+ return this.fetchEndpoint("starknet_syncing");
24424
+ }
24425
+ /**
24426
+ * Returns all events matching the given filter
24427
+ * @returns events and the pagination of the events
24428
+ */
24429
+ getEvents(eventFilter) {
24430
+ return this.fetchEndpoint("starknet_getEvents", { filter: eventFilter });
24431
+ }
24432
+ buildTransaction(invocation, versionType) {
24433
+ const defaultVersions = getVersionsByType(versionType);
24434
+ let details;
24435
+ if (!isV3Tx(invocation)) {
24436
+ details = {
24437
+ signature: signatureToHexArray(invocation.signature),
24438
+ nonce: toHex(invocation.nonce),
24439
+ max_fee: toHex(invocation.maxFee || 0)
24440
+ };
24441
+ } else {
24442
+ details = {
24443
+ signature: signatureToHexArray(invocation.signature),
24444
+ nonce: toHex(invocation.nonce),
24445
+ resource_bounds: invocation.resourceBounds,
24446
+ tip: toHex(invocation.tip),
24447
+ paymaster_data: invocation.paymasterData.map((it) => toHex(it)),
24448
+ nonce_data_availability_mode: invocation.nonceDataAvailabilityMode,
24449
+ fee_data_availability_mode: invocation.feeDataAvailabilityMode,
24450
+ account_deployment_data: invocation.accountDeploymentData.map((it) => toHex(it))
24451
+ };
24452
+ }
24453
+ if (invocation.type === "INVOKE_FUNCTION" /* INVOKE */) {
24454
+ return {
24455
+ // v0 v1 v3
24456
+ type: rpcspec_0_7_exports.ETransactionType.INVOKE,
24457
+ // TODO: Diff between sequencer and rpc invoke type
24458
+ sender_address: invocation.contractAddress,
24459
+ calldata: CallData.toHex(invocation.calldata),
24460
+ version: toHex(invocation.version || defaultVersions.v3),
24461
+ ...details
24462
+ };
24463
+ }
24464
+ if (invocation.type === "DECLARE" /* DECLARE */) {
24465
+ if (!isSierra(invocation.contract)) {
24466
+ return {
24467
+ type: invocation.type,
24468
+ contract_class: invocation.contract,
24469
+ sender_address: invocation.senderAddress,
24470
+ version: toHex(invocation.version || defaultVersions.v1),
24471
+ ...details
24472
+ };
24473
+ }
24474
+ return {
24475
+ // Cairo 1 - v2 v3
24476
+ type: invocation.type,
24477
+ contract_class: {
24478
+ ...invocation.contract,
24479
+ sierra_program: decompressProgram(invocation.contract.sierra_program)
24480
+ },
24481
+ compiled_class_hash: invocation.compiledClassHash || "",
24482
+ sender_address: invocation.senderAddress,
24483
+ version: toHex(invocation.version || defaultVersions.v3),
24484
+ ...details
24485
+ };
24486
+ }
24487
+ if (invocation.type === "DEPLOY_ACCOUNT" /* DEPLOY_ACCOUNT */) {
24488
+ const { account_deployment_data, ...restDetails } = details;
24489
+ return {
24490
+ type: invocation.type,
24491
+ constructor_calldata: CallData.toHex(invocation.constructorCalldata || []),
24492
+ class_hash: toHex(invocation.classHash),
24493
+ contract_address_salt: toHex(invocation.addressSalt || 0),
24494
+ version: toHex(invocation.version || defaultVersions.v3),
24495
+ ...restDetails
24496
+ };
24497
+ }
24498
+ throw Error("RPC buildTransaction received unknown TransactionType");
24499
+ }
24500
+ };
24501
+
24502
+ // src/utils/responseParser/rpc.ts
24503
+ var RPCResponseParser = class {
24504
+ parseGetBlockResponse(res) {
24505
+ return { status: "PENDING", ...res };
24506
+ }
24507
+ parseTransactionReceipt(res) {
24508
+ if ("actual_fee" in res && typeof res.actual_fee === "string") {
24509
+ return {
24510
+ ...res,
24511
+ actual_fee: {
24512
+ amount: res.actual_fee,
24513
+ unit: "FRI"
24514
+ }
24515
+ };
24516
+ }
24517
+ return res;
24518
+ }
24519
+ parseFeeEstimateResponse(res) {
24520
+ const val = res[0];
24521
+ return {
24522
+ overall_fee: toBigInt(val.overall_fee),
24523
+ gas_consumed: toBigInt(val.gas_consumed),
24524
+ gas_price: toBigInt(val.gas_price),
24525
+ unit: val.unit,
24526
+ suggestedMaxFee: estimatedFeeToMaxFee(val.overall_fee),
24527
+ resourceBounds: estimateFeeToBounds(val)
24528
+ };
24529
+ }
24530
+ parseFeeEstimateBulkResponse(res) {
24531
+ return res.map((val) => ({
24532
+ overall_fee: toBigInt(val.overall_fee),
24533
+ gas_consumed: toBigInt(val.gas_consumed),
24534
+ gas_price: toBigInt(val.gas_price),
24535
+ unit: val.unit,
24536
+ suggestedMaxFee: estimatedFeeToMaxFee(val.overall_fee),
24537
+ resourceBounds: estimateFeeToBounds(val)
24538
+ }));
24539
+ }
24540
+ parseSimulateTransactionResponse(res) {
24541
+ return res.map((it) => {
24542
+ return {
24543
+ ...it,
24544
+ suggestedMaxFee: estimatedFeeToMaxFee(BigInt(it.fee_estimation.overall_fee)),
24545
+ resourceBounds: estimateFeeToBounds(it.fee_estimation)
24546
+ };
24547
+ });
24548
+ }
24549
+ parseContractClassResponse(res) {
24550
+ return {
24551
+ ...res,
24552
+ abi: typeof res.abi === "string" ? JSON.parse(res.abi) : res.abi
24553
+ };
24554
+ }
24555
+ };
24556
+
24557
+ // src/provider/rpc.ts
24558
+ var RpcProvider = class {
24559
+ responseParser = new RPCResponseParser();
24560
+ channel;
24561
+ constructor(optionsOrProvider) {
24562
+ if (optionsOrProvider && "channel" in optionsOrProvider) {
24563
+ this.channel = optionsOrProvider.channel;
24564
+ } else {
24565
+ this.channel = new RpcChannel2({ ...optionsOrProvider, waitMode: false });
24566
+ }
24567
+ }
24568
+ fetch(method, params, id = 0) {
24569
+ return this.channel.fetch(method, params, id);
24570
+ }
24571
+ async getChainId() {
24572
+ return this.channel.getChainId();
24573
+ }
24574
+ async getSpecVersion() {
24575
+ return this.channel.getSpecVersion();
24576
+ }
24577
+ async getNonceForAddress(contractAddress, blockIdentifier) {
24578
+ return this.channel.getNonceForAddress(contractAddress, blockIdentifier);
24579
+ }
24580
+ async getBlock(blockIdentifier) {
24581
+ return this.channel.getBlockWithTxHashes(blockIdentifier).then(this.responseParser.parseGetBlockResponse);
24582
+ }
24583
+ /**
24584
+ * Get the most recent accepted block hash and number
24585
+ */
24586
+ async getBlockLatestAccepted() {
24587
+ return this.channel.getBlockLatestAccepted();
24588
+ }
24589
+ /**
24590
+ * Get the most recent accepted block number
24591
+ * redundant use getBlockLatestAccepted();
24592
+ * @returns Number of the latest block
24593
+ */
24594
+ async getBlockNumber() {
24595
+ return this.channel.getBlockNumber();
24596
+ }
24597
+ async getBlockWithTxHashes(blockIdentifier) {
24598
+ return this.channel.getBlockWithTxHashes(blockIdentifier);
24599
+ }
24600
+ async getBlockWithTxs(blockIdentifier) {
24601
+ return this.channel.getBlockWithTxs(blockIdentifier);
24602
+ }
24603
+ async getBlockWithReceipts(blockIdentifier) {
24604
+ if (this.channel instanceof rpc_0_6_exports.RpcChannel)
24605
+ throw new LibraryError("Unsupported method for RPC version");
24606
+ return this.channel.getBlockWithReceipts(blockIdentifier);
23943
24607
  }
23944
24608
  getStateUpdate = this.getBlockStateUpdate;
23945
24609
  async getBlockStateUpdate(blockIdentifier) {
@@ -24878,7 +25542,7 @@ var starknet = (() => {
24878
25542
  async signTransaction(transactions, details) {
24879
25543
  const compiledCalldata = getExecuteCalldata(transactions, details.cairoVersion);
24880
25544
  let msgHash;
24881
- if (Object.values(ETransactionVersion2).includes(details.version)) {
25545
+ if (Object.values(ETransactionVersion22).includes(details.version)) {
24882
25546
  const det = details;
24883
25547
  msgHash = calculateInvokeTransactionHash2({
24884
25548
  ...det,
@@ -24886,7 +25550,7 @@ var starknet = (() => {
24886
25550
  compiledCalldata,
24887
25551
  version: det.version
24888
25552
  });
24889
- } else if (Object.values(ETransactionVersion3).includes(details.version)) {
25553
+ } else if (Object.values(ETransactionVersion32).includes(details.version)) {
24890
25554
  const det = details;
24891
25555
  msgHash = calculateInvokeTransactionHash2({
24892
25556
  ...det,
@@ -24904,7 +25568,7 @@ var starknet = (() => {
24904
25568
  async signDeployAccountTransaction(details) {
24905
25569
  const compiledConstructorCalldata = CallData.compile(details.constructorCalldata);
24906
25570
  let msgHash;
24907
- if (Object.values(ETransactionVersion2).includes(details.version)) {
25571
+ if (Object.values(ETransactionVersion22).includes(details.version)) {
24908
25572
  const det = details;
24909
25573
  msgHash = calculateDeployAccountTransactionHash3({
24910
25574
  ...det,
@@ -24912,7 +25576,7 @@ var starknet = (() => {
24912
25576
  constructorCalldata: compiledConstructorCalldata,
24913
25577
  version: det.version
24914
25578
  });
24915
- } else if (Object.values(ETransactionVersion3).includes(details.version)) {
25579
+ } else if (Object.values(ETransactionVersion32).includes(details.version)) {
24916
25580
  const det = details;
24917
25581
  msgHash = calculateDeployAccountTransactionHash3({
24918
25582
  ...det,
@@ -24929,13 +25593,13 @@ var starknet = (() => {
24929
25593
  }
24930
25594
  async signDeclareTransaction(details) {
24931
25595
  let msgHash;
24932
- if (Object.values(ETransactionVersion2).includes(details.version)) {
25596
+ if (Object.values(ETransactionVersion22).includes(details.version)) {
24933
25597
  const det = details;
24934
25598
  msgHash = calculateDeclareTransactionHash3({
24935
25599
  ...det,
24936
25600
  version: det.version
24937
25601
  });
24938
- } else if (Object.values(ETransactionVersion3).includes(details.version)) {
25602
+ } else if (Object.values(ETransactionVersion32).includes(details.version)) {
24939
25603
  const det = details;
24940
25604
  msgHash = calculateDeclareTransactionHash3({
24941
25605
  ...det,
@@ -25059,7 +25723,7 @@ var starknet = (() => {
25059
25723
  async signTransaction(transactions, details) {
25060
25724
  const compiledCalldata = getExecuteCalldata(transactions, details.cairoVersion);
25061
25725
  let msgHash;
25062
- if (Object.values(ETransactionVersion2).includes(details.version)) {
25726
+ if (Object.values(ETransactionVersion22).includes(details.version)) {
25063
25727
  const det = details;
25064
25728
  msgHash = calculateInvokeTransactionHash2({
25065
25729
  ...det,
@@ -25067,7 +25731,7 @@ var starknet = (() => {
25067
25731
  compiledCalldata,
25068
25732
  version: det.version
25069
25733
  });
25070
- } else if (Object.values(ETransactionVersion3).includes(details.version)) {
25734
+ } else if (Object.values(ETransactionVersion32).includes(details.version)) {
25071
25735
  const det = details;
25072
25736
  msgHash = calculateInvokeTransactionHash2({
25073
25737
  ...det,
@@ -25085,7 +25749,7 @@ var starknet = (() => {
25085
25749
  async signDeployAccountTransaction(details) {
25086
25750
  const compiledConstructorCalldata = CallData.compile(details.constructorCalldata);
25087
25751
  let msgHash;
25088
- if (Object.values(ETransactionVersion2).includes(details.version)) {
25752
+ if (Object.values(ETransactionVersion22).includes(details.version)) {
25089
25753
  const det = details;
25090
25754
  msgHash = calculateDeployAccountTransactionHash3({
25091
25755
  ...det,
@@ -25093,7 +25757,7 @@ var starknet = (() => {
25093
25757
  constructorCalldata: compiledConstructorCalldata,
25094
25758
  version: det.version
25095
25759
  });
25096
- } else if (Object.values(ETransactionVersion3).includes(details.version)) {
25760
+ } else if (Object.values(ETransactionVersion32).includes(details.version)) {
25097
25761
  const det = details;
25098
25762
  msgHash = calculateDeployAccountTransactionHash3({
25099
25763
  ...det,
@@ -25110,13 +25774,13 @@ var starknet = (() => {
25110
25774
  }
25111
25775
  async signDeclareTransaction(details) {
25112
25776
  let msgHash;
25113
- if (Object.values(ETransactionVersion2).includes(details.version)) {
25777
+ if (Object.values(ETransactionVersion22).includes(details.version)) {
25114
25778
  const det = details;
25115
25779
  msgHash = calculateDeclareTransactionHash3({
25116
25780
  ...det,
25117
25781
  version: det.version
25118
25782
  });
25119
- } else if (Object.values(ETransactionVersion3).includes(details.version)) {
25783
+ } else if (Object.values(ETransactionVersion32).includes(details.version)) {
25120
25784
  const det = details;
25121
25785
  msgHash = calculateDeclareTransactionHash3({
25122
25786
  ...det,