starknet 5.22.0 → 5.24.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
@@ -78,6 +78,7 @@ __export(src_exports, {
78
78
  fixStack: () => fixStack,
79
79
  getCalldata: () => getCalldata,
80
80
  getChecksumAddress: () => getChecksumAddress,
81
+ getDefaultNodeUrl: () => getDefaultNodeUrl,
81
82
  hash: () => hash_exports,
82
83
  isSierra: () => isSierra,
83
84
  isUrl: () => isUrl,
@@ -116,6 +117,8 @@ __export(constants_exports, {
116
117
  MASK_250: () => MASK_250,
117
118
  MASK_251: () => MASK_251,
118
119
  NetworkName: () => NetworkName,
120
+ RPC_GOERLI_NODES: () => RPC_GOERLI_NODES,
121
+ RPC_MAINNET_NODES: () => RPC_MAINNET_NODES,
119
122
  StarknetChainId: () => StarknetChainId,
120
123
  TEXT_TO_FELT_MAX_LEN: () => TEXT_TO_FELT_MAX_LEN,
121
124
  TransactionHashPrefix: () => TransactionHashPrefix,
@@ -141,6 +144,7 @@ __export(encode_exports, {
141
144
  stringToArrayBuffer: () => stringToArrayBuffer,
142
145
  utf8ToArray: () => utf8ToArray
143
146
  });
147
+ var import_base = require("@scure/base");
144
148
  var IS_BROWSER = typeof window !== "undefined";
145
149
  var STRING_ZERO = "0";
146
150
  function arrayBufferToString(array) {
@@ -153,10 +157,10 @@ function stringToArrayBuffer(str) {
153
157
  return utf8ToArray(str);
154
158
  }
155
159
  function atobUniversal(a) {
156
- return IS_BROWSER ? utf8ToArray(atob(a)) : Buffer.from(a, "base64");
160
+ return import_base.base64.decode(a);
157
161
  }
158
162
  function btoaUniversal(b) {
159
- return IS_BROWSER ? btoa(arrayBufferToString(b)) : Buffer.from(b).toString("base64");
163
+ return import_base.base64.encode(new Uint8Array(b));
160
164
  }
161
165
  function buf2hex(buffer) {
162
166
  return buffer.reduce((r, x) => r + x.toString(16).padStart(2, "0"), "");
@@ -236,6 +240,14 @@ var UDC = {
236
240
  ADDRESS: "0x041a78e741e5af2fec34b695679bc6891742439f7afb8484ecd7766661ad02bf",
237
241
  ENTRYPOINT: "deployContract"
238
242
  };
243
+ var RPC_GOERLI_NODES = [
244
+ "https://starknet-testnet.public.blastapi.io/rpc/v0.5",
245
+ "https://limited-rpc.nethermind.io/goerli-juno/v0_5"
246
+ ];
247
+ var RPC_MAINNET_NODES = [
248
+ "https://starknet-mainnet.public.blastapi.io/rpc/v0.5",
249
+ "https://limited-rpc.nethermind.io/mainnet-juno/v0_5"
250
+ ];
239
251
 
240
252
  // src/types/index.ts
241
253
  var types_exports = {};
@@ -256,10 +268,10 @@ __export(types_exports, {
256
268
  });
257
269
 
258
270
  // src/types/account.ts
259
- var SIMULATION_FLAG = /* @__PURE__ */ ((SIMULATION_FLAG3) => {
260
- SIMULATION_FLAG3["SKIP_VALIDATE"] = "SKIP_VALIDATE";
261
- SIMULATION_FLAG3["SKIP_EXECUTE"] = "SKIP_EXECUTE";
262
- return SIMULATION_FLAG3;
271
+ var SIMULATION_FLAG = /* @__PURE__ */ ((SIMULATION_FLAG2) => {
272
+ SIMULATION_FLAG2["SKIP_VALIDATE"] = "SKIP_VALIDATE";
273
+ SIMULATION_FLAG2["SKIP_EXECUTE"] = "SKIP_EXECUTE";
274
+ return SIMULATION_FLAG2;
263
275
  })(SIMULATION_FLAG || {});
264
276
 
265
277
  // src/types/calldata.ts
@@ -293,12 +305,12 @@ var EntryPointType = /* @__PURE__ */ ((EntryPointType2) => {
293
305
  })(EntryPointType || {});
294
306
 
295
307
  // src/types/lib/index.ts
296
- var TransactionType = /* @__PURE__ */ ((TransactionType3) => {
297
- TransactionType3["DECLARE"] = "DECLARE";
298
- TransactionType3["DEPLOY"] = "DEPLOY";
299
- TransactionType3["DEPLOY_ACCOUNT"] = "DEPLOY_ACCOUNT";
300
- TransactionType3["INVOKE"] = "INVOKE_FUNCTION";
301
- return TransactionType3;
308
+ var TransactionType = /* @__PURE__ */ ((TransactionType2) => {
309
+ TransactionType2["DECLARE"] = "DECLARE";
310
+ TransactionType2["DEPLOY"] = "DEPLOY";
311
+ TransactionType2["DEPLOY_ACCOUNT"] = "DEPLOY_ACCOUNT";
312
+ TransactionType2["INVOKE"] = "INVOKE_FUNCTION";
313
+ return TransactionType2;
302
314
  })(TransactionType || {});
303
315
  var TransactionStatus = /* @__PURE__ */ ((TransactionStatus2) => {
304
316
  TransactionStatus2["NOT_RECEIVED"] = "NOT_RECEIVED";
@@ -309,18 +321,18 @@ var TransactionStatus = /* @__PURE__ */ ((TransactionStatus2) => {
309
321
  TransactionStatus2["REVERTED"] = "REVERTED";
310
322
  return TransactionStatus2;
311
323
  })(TransactionStatus || {});
312
- var TransactionFinalityStatus = /* @__PURE__ */ ((TransactionFinalityStatus3) => {
313
- TransactionFinalityStatus3["NOT_RECEIVED"] = "NOT_RECEIVED";
314
- TransactionFinalityStatus3["RECEIVED"] = "RECEIVED";
315
- TransactionFinalityStatus3["ACCEPTED_ON_L2"] = "ACCEPTED_ON_L2";
316
- TransactionFinalityStatus3["ACCEPTED_ON_L1"] = "ACCEPTED_ON_L1";
317
- return TransactionFinalityStatus3;
324
+ var TransactionFinalityStatus = /* @__PURE__ */ ((TransactionFinalityStatus2) => {
325
+ TransactionFinalityStatus2["NOT_RECEIVED"] = "NOT_RECEIVED";
326
+ TransactionFinalityStatus2["RECEIVED"] = "RECEIVED";
327
+ TransactionFinalityStatus2["ACCEPTED_ON_L2"] = "ACCEPTED_ON_L2";
328
+ TransactionFinalityStatus2["ACCEPTED_ON_L1"] = "ACCEPTED_ON_L1";
329
+ return TransactionFinalityStatus2;
318
330
  })(TransactionFinalityStatus || {});
319
- var TransactionExecutionStatus = /* @__PURE__ */ ((TransactionExecutionStatus3) => {
320
- TransactionExecutionStatus3["REJECTED"] = "REJECTED";
321
- TransactionExecutionStatus3["REVERTED"] = "REVERTED";
322
- TransactionExecutionStatus3["SUCCEEDED"] = "SUCCEEDED";
323
- return TransactionExecutionStatus3;
331
+ var TransactionExecutionStatus = /* @__PURE__ */ ((TransactionExecutionStatus2) => {
332
+ TransactionExecutionStatus2["REJECTED"] = "REJECTED";
333
+ TransactionExecutionStatus2["REVERTED"] = "REVERTED";
334
+ TransactionExecutionStatus2["SUCCEEDED"] = "SUCCEEDED";
335
+ return TransactionExecutionStatus2;
324
336
  })(TransactionExecutionStatus || {});
325
337
  var BlockStatus = /* @__PURE__ */ ((BlockStatus2) => {
326
338
  BlockStatus2["PENDING"] = "PENDING";
@@ -338,42 +350,68 @@ var BlockTag = /* @__PURE__ */ ((BlockTag2) => {
338
350
  // src/types/api/rpc.ts
339
351
  var rpc_exports = {};
340
352
  __export(rpc_exports, {
341
- SimulationFlag: () => SimulationFlag,
342
- TransactionExecutionStatus: () => TransactionExecutionStatus2,
343
- TransactionFinalityStatus: () => TransactionFinalityStatus2,
344
- TransactionType: () => TransactionType2
353
+ EBlockTag: () => EBlockTag,
354
+ EDataAvailabilityMode: () => EDataAvailabilityMode,
355
+ ESimulationFlag: () => ESimulationFlag,
356
+ ETransactionExecutionStatus: () => ETransactionExecutionStatus,
357
+ ETransactionFinalityStatus: () => ETransactionFinalityStatus,
358
+ ETransactionStatus: () => ETransactionStatus,
359
+ ETransactionType: () => ETransactionType,
360
+ Errors: () => errors_exports,
361
+ JRPC: () => jsonrpc_exports,
362
+ SPEC: () => components_exports
345
363
  });
346
364
 
347
- // src/types/api/openrpc.ts
348
- var TXN_TYPE = /* @__PURE__ */ ((TXN_TYPE2) => {
349
- TXN_TYPE2["DECLARE"] = "DECLARE";
350
- TXN_TYPE2["DEPLOY"] = "DEPLOY";
351
- TXN_TYPE2["DEPLOY_ACCOUNT"] = "DEPLOY_ACCOUNT";
352
- TXN_TYPE2["INVOKE"] = "INVOKE";
353
- TXN_TYPE2["L1_HANDLER"] = "L1_HANDLER";
354
- return TXN_TYPE2;
355
- })(TXN_TYPE || {});
356
- var TXN_FINALITY_STATUS = /* @__PURE__ */ ((TXN_FINALITY_STATUS2) => {
357
- TXN_FINALITY_STATUS2["ACCEPTED_ON_L2"] = "ACCEPTED_ON_L2";
358
- TXN_FINALITY_STATUS2["ACCEPTED_ON_L1"] = "ACCEPTED_ON_L1";
359
- return TXN_FINALITY_STATUS2;
360
- })(TXN_FINALITY_STATUS || {});
361
- var TXN_EXECUTION_STATUS = /* @__PURE__ */ ((TXN_EXECUTION_STATUS2) => {
362
- TXN_EXECUTION_STATUS2["SUCCEEDED"] = "SUCCEEDED";
363
- TXN_EXECUTION_STATUS2["REVERTED"] = "REVERTED";
364
- return TXN_EXECUTION_STATUS2;
365
- })(TXN_EXECUTION_STATUS || {});
366
- var SIMULATION_FLAG2 = /* @__PURE__ */ ((SIMULATION_FLAG3) => {
367
- SIMULATION_FLAG3["SKIP_VALIDATE"] = "SKIP_VALIDATE";
368
- SIMULATION_FLAG3["SKIP_FEE_CHARGE"] = "SKIP_FEE_CHARGE";
369
- return SIMULATION_FLAG3;
370
- })(SIMULATION_FLAG2 || {});
365
+ // src/types/api/jsonrpc/index.ts
366
+ var jsonrpc_exports = {};
371
367
 
372
- // src/types/api/rpc.ts
373
- var TransactionType2 = TXN_TYPE;
374
- var SimulationFlag = SIMULATION_FLAG2;
375
- var TransactionFinalityStatus2 = TXN_FINALITY_STATUS;
376
- var TransactionExecutionStatus2 = TXN_EXECUTION_STATUS;
368
+ // src/types/api/rpcspec/errors.ts
369
+ var errors_exports = {};
370
+
371
+ // src/types/api/rpcspec/components.ts
372
+ var components_exports = {};
373
+
374
+ // src/types/api/rpcspec/nonspec.ts
375
+ var ETransactionType = /* @__PURE__ */ ((ETransactionType2) => {
376
+ ETransactionType2["DECLARE"] = "DECLARE";
377
+ ETransactionType2["DEPLOY"] = "DEPLOY";
378
+ ETransactionType2["DEPLOY_ACCOUNT"] = "DEPLOY_ACCOUNT";
379
+ ETransactionType2["INVOKE"] = "INVOKE";
380
+ ETransactionType2["L1_HANDLER"] = "L1_HANDLER";
381
+ return ETransactionType2;
382
+ })(ETransactionType || {});
383
+ var ESimulationFlag = /* @__PURE__ */ ((ESimulationFlag2) => {
384
+ ESimulationFlag2["SKIP_VALIDATE"] = "SKIP_VALIDATE";
385
+ ESimulationFlag2["SKIP_FEE_CHARGE"] = "SKIP_FEE_CHARGE";
386
+ return ESimulationFlag2;
387
+ })(ESimulationFlag || {});
388
+ var ETransactionStatus = /* @__PURE__ */ ((ETransactionStatus2) => {
389
+ ETransactionStatus2["RECEIVED"] = "RECEIVED";
390
+ ETransactionStatus2["REJECTED"] = "REJECTED";
391
+ ETransactionStatus2["ACCEPTED_ON_L2"] = "ACCEPTED_ON_L2";
392
+ ETransactionStatus2["ACCEPTED_ON_L1"] = "ACCEPTED_ON_L1";
393
+ return ETransactionStatus2;
394
+ })(ETransactionStatus || {});
395
+ var ETransactionFinalityStatus = /* @__PURE__ */ ((ETransactionFinalityStatus2) => {
396
+ ETransactionFinalityStatus2["ACCEPTED_ON_L2"] = "ACCEPTED_ON_L2";
397
+ ETransactionFinalityStatus2["ACCEPTED_ON_L1"] = "ACCEPTED_ON_L1";
398
+ return ETransactionFinalityStatus2;
399
+ })(ETransactionFinalityStatus || {});
400
+ var ETransactionExecutionStatus = /* @__PURE__ */ ((ETransactionExecutionStatus2) => {
401
+ ETransactionExecutionStatus2["SUCCEEDED"] = "SUCCEEDED";
402
+ ETransactionExecutionStatus2["REVERTED"] = "REVERTED";
403
+ return ETransactionExecutionStatus2;
404
+ })(ETransactionExecutionStatus || {});
405
+ var EBlockTag = /* @__PURE__ */ ((EBlockTag2) => {
406
+ EBlockTag2["LATEST"] = "latest";
407
+ EBlockTag2["PENDING"] = "pending";
408
+ return EBlockTag2;
409
+ })(EBlockTag || {});
410
+ var EDataAvailabilityMode = /* @__PURE__ */ ((EDataAvailabilityMode2) => {
411
+ EDataAvailabilityMode2["L1"] = "L1";
412
+ EDataAvailabilityMode2["L2"] = "L2";
413
+ return EDataAvailabilityMode2;
414
+ })(EDataAvailabilityMode || {});
377
415
 
378
416
  // src/types/api/sequencer.ts
379
417
  var sequencer_exports = {};
@@ -2241,10 +2279,10 @@ function compressProgram(jsonProgram) {
2241
2279
  const compressedProgram = (0, import_pako.gzip)(stringified);
2242
2280
  return btoaUniversal(compressedProgram);
2243
2281
  }
2244
- function decompressProgram(base64) {
2245
- if (Array.isArray(base64))
2246
- return base64;
2247
- const decompressed = arrayBufferToString((0, import_pako.ungzip)(atobUniversal(base64)));
2282
+ function decompressProgram(base642) {
2283
+ if (Array.isArray(base642))
2284
+ return base642;
2285
+ const decompressed = arrayBufferToString((0, import_pako.ungzip)(atobUniversal(base642)));
2248
2286
  return parse2(decompressed);
2249
2287
  }
2250
2288
  function randomAddress() {
@@ -2349,22 +2387,22 @@ var RPCResponseParser = class {
2349
2387
  parseGetBlockResponse(res) {
2350
2388
  return {
2351
2389
  timestamp: res.timestamp,
2352
- block_hash: res.block_hash,
2353
- block_number: res.block_number,
2354
- new_root: res.new_root,
2390
+ block_hash: "block_hash" in res ? res.block_hash : "",
2391
+ block_number: "block_number" in res ? res.block_number : -1,
2392
+ new_root: "new_root" in res ? res.new_root : "",
2355
2393
  parent_hash: res.parent_hash,
2356
- status: res.status,
2394
+ status: "status" in res ? res.status : "PENDING" /* PENDING */,
2357
2395
  transactions: res.transactions
2358
2396
  };
2359
2397
  }
2360
2398
  parseGetTransactionResponse(res) {
2361
2399
  return {
2362
- calldata: res.calldata || [],
2363
- contract_address: res.contract_address,
2364
- sender_address: res.contract_address,
2365
- max_fee: res.max_fee,
2366
- nonce: res.nonce,
2367
- signature: res.signature || [],
2400
+ calldata: "calldata" in res ? res.calldata : [],
2401
+ contract_address: "contract_address" in res ? res.contract_address : "",
2402
+ sender_address: "sender_address" in res ? res.sender_address : "",
2403
+ max_fee: "max_fee" in res ? res.max_fee : "",
2404
+ nonce: "nonce" in res ? res.nonce : "",
2405
+ signature: "signature" in res ? res.signature : [],
2368
2406
  transaction_hash: res.transaction_hash,
2369
2407
  version: res.version
2370
2408
  };
@@ -2640,6 +2678,13 @@ var Block = class {
2640
2678
  };
2641
2679
 
2642
2680
  // src/provider/rpc.ts
2681
+ var getDefaultNodeUrl = (networkName, mute = false) => {
2682
+ if (!mute)
2683
+ console.warn("Using default public node url, please provide nodeUrl in provider options!");
2684
+ const nodes = networkName === "SN_MAIN" /* SN_MAIN */ ? RPC_MAINNET_NODES : RPC_GOERLI_NODES;
2685
+ const randIdx = Math.floor(Math.random() * nodes.length);
2686
+ return nodes[randIdx];
2687
+ };
2643
2688
  var defaultOptions = {
2644
2689
  headers: { "Content-Type": "application/json" },
2645
2690
  blockIdentifier: "pending" /* pending */,
@@ -2648,52 +2693,126 @@ var defaultOptions = {
2648
2693
  var RpcProvider = class {
2649
2694
  constructor(optionsOrProvider) {
2650
2695
  this.responseParser = new RPCResponseParser();
2651
- const { nodeUrl, retries, headers, blockIdentifier, chainId } = optionsOrProvider;
2652
- this.nodeUrl = nodeUrl;
2696
+ /**
2697
+ * @deprecated renamed to getBlockLatestAccepted(); (will be removed in next minor version)
2698
+ */
2699
+ this.getBlockHashAndNumber = this.getBlockLatestAccepted;
2700
+ /**
2701
+ * @deprecated renamed to getBlockStateUpdate();
2702
+ */
2703
+ this.getStateUpdate = this.getBlockStateUpdate;
2704
+ /**
2705
+ * Returns the execution traces of all transactions included in the given block
2706
+ * @deprecated renamed to getBlockTransactionsTraces()
2707
+ */
2708
+ this.traceBlockTransactions = this.getBlockTransactionsTraces;
2709
+ /**
2710
+ * Get the number of transactions in a block given a block id
2711
+ * @deprecated renamed to getBlockTransactionCount()
2712
+ * @returns Number of transactions
2713
+ */
2714
+ this.getTransactionCount = this.getBlockTransactionCount;
2715
+ /**
2716
+ * @deprecated renamed to getTransactionTrace();
2717
+ * For a given executed transaction, return the trace of its execution, including internal calls
2718
+ */
2719
+ this.traceTransaction = this.getTransactionTrace;
2720
+ /**
2721
+ * @deprecated renamed to simulateTransaction();
2722
+ */
2723
+ this.getSimulateTransaction = this.simulateTransaction;
2724
+ const { nodeUrl, retries, headers, blockIdentifier, chainId } = optionsOrProvider || {};
2725
+ if (Object.values(NetworkName).includes(nodeUrl)) {
2726
+ this.nodeUrl = getDefaultNodeUrl(nodeUrl, optionsOrProvider?.default);
2727
+ } else if (nodeUrl) {
2728
+ this.nodeUrl = nodeUrl;
2729
+ } else {
2730
+ this.nodeUrl = getDefaultNodeUrl(void 0, optionsOrProvider?.default);
2731
+ }
2653
2732
  this.retries = retries || defaultOptions.retries;
2654
2733
  this.headers = { ...defaultOptions.headers, ...headers };
2655
2734
  this.blockIdentifier = blockIdentifier || defaultOptions.blockIdentifier;
2656
2735
  this.chainId = chainId;
2657
- this.getChainId();
2658
2736
  }
2659
- fetch(method, params) {
2660
- const body = stringify2({ method, jsonrpc: "2.0", params, id: 0 });
2737
+ fetch(method, params, id = 0) {
2738
+ const rpcRequestBody = {
2739
+ id,
2740
+ jsonrpc: "2.0",
2741
+ method,
2742
+ ...params && { params }
2743
+ };
2661
2744
  return fetchPonyfill_default(this.nodeUrl, {
2662
2745
  method: "POST",
2663
- body,
2746
+ body: stringify2(rpcRequestBody),
2664
2747
  headers: this.headers
2665
2748
  });
2666
2749
  }
2667
- errorHandler(error) {
2668
- if (error) {
2669
- const { code, message } = error;
2670
- throw new LibraryError(`${code}: ${message}`);
2750
+ errorHandler(method, params, rpcError, otherError) {
2751
+ if (rpcError) {
2752
+ const { code, message, data } = rpcError;
2753
+ throw new LibraryError(
2754
+ `RPC: ${method} with params ${JSON.stringify(params)}
2755
+ ${code}: ${message}: ${data}`
2756
+ );
2757
+ }
2758
+ if (otherError instanceof LibraryError) {
2759
+ throw otherError;
2760
+ }
2761
+ if (otherError) {
2762
+ throw Error(otherError.message);
2671
2763
  }
2672
2764
  }
2673
2765
  async fetchEndpoint(method, params) {
2674
2766
  try {
2675
2767
  const rawResult = await this.fetch(method, params);
2676
2768
  const { error, result } = await rawResult.json();
2677
- this.errorHandler(error);
2769
+ this.errorHandler(method, params, error);
2678
2770
  return result;
2679
2771
  } catch (error) {
2680
- this.errorHandler(error?.response?.data);
2772
+ this.errorHandler(method, params, error?.response?.data, error);
2681
2773
  throw error;
2682
2774
  }
2683
2775
  }
2684
- // Methods from Interface
2685
2776
  async getChainId() {
2686
2777
  this.chainId ?? (this.chainId = await this.fetchEndpoint("starknet_chainId"));
2687
2778
  return this.chainId;
2688
2779
  }
2780
+ /**
2781
+ * NEW: Returns the version of the Starknet JSON-RPC specification being used
2782
+ */
2783
+ async getSpecVersion() {
2784
+ return this.fetchEndpoint("starknet_specVersion");
2785
+ }
2786
+ async getNonceForAddress(contractAddress, blockIdentifier = this.blockIdentifier) {
2787
+ const contract_address = toHex(contractAddress);
2788
+ const block_id = new Block(blockIdentifier).identifier;
2789
+ return this.fetchEndpoint("starknet_getNonce", {
2790
+ contract_address,
2791
+ block_id
2792
+ });
2793
+ }
2794
+ /**
2795
+ * @deprecated use getBlockWithTxHashes or getBlockWithTxs (will be removed on sequencer deprecation)
2796
+ */
2689
2797
  async getBlock(blockIdentifier = this.blockIdentifier) {
2690
2798
  return this.getBlockWithTxHashes(blockIdentifier).then(
2691
2799
  this.responseParser.parseGetBlockResponse
2692
2800
  );
2693
2801
  }
2694
- async getBlockHashAndNumber() {
2802
+ /**
2803
+ * Get the most recent accepted block hash and number
2804
+ */
2805
+ async getBlockLatestAccepted() {
2695
2806
  return this.fetchEndpoint("starknet_blockHashAndNumber");
2696
2807
  }
2808
+ /**
2809
+ * @deprecated redundant use getBlockLatestAccepted();
2810
+ * Get the most recent accepted block number
2811
+ * @returns Number of the latest block
2812
+ */
2813
+ async getBlockNumber() {
2814
+ return this.fetchEndpoint("starknet_blockNumber");
2815
+ }
2697
2816
  async getBlockWithTxHashes(blockIdentifier = this.blockIdentifier) {
2698
2817
  const block_id = new Block(blockIdentifier).identifier;
2699
2818
  return this.fetchEndpoint("starknet_getBlockWithTxHashes", { block_id });
@@ -2702,68 +2821,175 @@ var RpcProvider = class {
2702
2821
  const block_id = new Block(blockIdentifier).identifier;
2703
2822
  return this.fetchEndpoint("starknet_getBlockWithTxs", { block_id });
2704
2823
  }
2705
- async getClassHashAt(contractAddress, blockIdentifier = this.blockIdentifier) {
2824
+ async getBlockStateUpdate(blockIdentifier = this.blockIdentifier) {
2706
2825
  const block_id = new Block(blockIdentifier).identifier;
2707
- return this.fetchEndpoint("starknet_getClassHashAt", {
2708
- block_id,
2709
- contract_address: contractAddress
2710
- });
2826
+ return this.fetchEndpoint("starknet_getStateUpdate", { block_id });
2711
2827
  }
2712
- async getNonceForAddress(contractAddress, blockIdentifier = this.blockIdentifier) {
2828
+ async getBlockTransactionsTraces(blockIdentifier = this.blockIdentifier) {
2713
2829
  const block_id = new Block(blockIdentifier).identifier;
2714
- return this.fetchEndpoint("starknet_getNonce", {
2715
- contract_address: contractAddress,
2716
- block_id
2717
- });
2830
+ return this.fetchEndpoint("starknet_traceBlockTransactions", { block_id });
2718
2831
  }
2832
+ async getBlockTransactionCount(blockIdentifier = this.blockIdentifier) {
2833
+ const block_id = new Block(blockIdentifier).identifier;
2834
+ return this.fetchEndpoint("starknet_getBlockTransactionCount", { block_id });
2835
+ }
2836
+ /**
2837
+ * Return transactions from pending block
2838
+ * @deprecated Instead use getBlock(BlockTag.pending); (will be removed in next minor version)
2839
+ */
2719
2840
  async getPendingTransactions() {
2720
- return this.fetchEndpoint("starknet_pendingTransactions");
2841
+ const { transactions } = await this.getBlock("pending" /* pending */);
2842
+ return Promise.all(transactions.map((it) => this.getTransactionByHash(it)));
2721
2843
  }
2722
- async getProtocolVersion() {
2723
- throw new Error("Pathfinder does not implement this rpc 0.1.0 method");
2844
+ /**
2845
+ * @deprecated use getTransactionByHash or getTransactionByBlockIdAndIndex (will be removed on sequencer deprecation)
2846
+ */
2847
+ async getTransaction(txHash) {
2848
+ return this.getTransactionByHash(txHash).then(this.responseParser.parseGetTransactionResponse);
2724
2849
  }
2725
- async getStateUpdate(blockIdentifier = this.blockIdentifier) {
2850
+ async getTransactionByHash(txHash) {
2851
+ const transaction_hash = toHex(txHash);
2852
+ return this.fetchEndpoint("starknet_getTransactionByHash", {
2853
+ transaction_hash
2854
+ });
2855
+ }
2856
+ async getTransactionByBlockIdAndIndex(blockIdentifier, index) {
2726
2857
  const block_id = new Block(blockIdentifier).identifier;
2727
- return this.fetchEndpoint("starknet_getStateUpdate", { block_id });
2858
+ return this.fetchEndpoint("starknet_getTransactionByBlockIdAndIndex", { block_id, index });
2859
+ }
2860
+ async getTransactionReceipt(txHash) {
2861
+ const transaction_hash = toHex(txHash);
2862
+ return this.fetchEndpoint("starknet_getTransactionReceipt", { transaction_hash });
2863
+ }
2864
+ async getTransactionTrace(txHash) {
2865
+ const transaction_hash = toHex(txHash);
2866
+ return this.fetchEndpoint("starknet_traceTransaction", { transaction_hash });
2867
+ }
2868
+ /**
2869
+ * NEW: Get the status of a transaction
2870
+ */
2871
+ async getTransactionStatus(transactionHash) {
2872
+ const transaction_hash = toHex(transactionHash);
2873
+ return this.fetchEndpoint("starknet_getTransactionStatus", { transaction_hash });
2874
+ }
2875
+ /**
2876
+ * @param invocations AccountInvocations
2877
+ * @param simulateTransactionOptions blockIdentifier and flags to skip validation and fee charge<br/>
2878
+ * - blockIdentifier<br/>
2879
+ * - skipValidate (default false)<br/>
2880
+ * - skipFeeCharge (default true)<br/>
2881
+ */
2882
+ async simulateTransaction(invocations, {
2883
+ blockIdentifier = this.blockIdentifier,
2884
+ skipValidate = false,
2885
+ skipFeeCharge = true
2886
+ }) {
2887
+ const block_id = new Block(blockIdentifier).identifier;
2888
+ const simulationFlags = [];
2889
+ if (skipValidate)
2890
+ simulationFlags.push(rpc_exports.ESimulationFlag.SKIP_VALIDATE);
2891
+ if (skipFeeCharge)
2892
+ simulationFlags.push(rpc_exports.ESimulationFlag.SKIP_FEE_CHARGE);
2893
+ return this.fetchEndpoint("starknet_simulateTransactions", {
2894
+ block_id,
2895
+ transactions: invocations.map((it) => this.buildTransaction(it)),
2896
+ simulation_flags: simulationFlags
2897
+ }).then(this.responseParser.parseSimulateTransactionResponse);
2898
+ }
2899
+ async waitForTransaction(txHash, options) {
2900
+ const transactionHash = toHex(txHash);
2901
+ let { retries } = this;
2902
+ let onchain = false;
2903
+ let isErrorState = false;
2904
+ const retryInterval = options?.retryInterval ?? 5e3;
2905
+ const errorStates = options?.errorStates ?? [
2906
+ rpc_exports.ETransactionStatus.REJECTED,
2907
+ rpc_exports.ETransactionExecutionStatus.REVERTED
2908
+ ];
2909
+ const successStates = options?.successStates ?? [
2910
+ rpc_exports.ETransactionExecutionStatus.SUCCEEDED,
2911
+ rpc_exports.ETransactionStatus.ACCEPTED_ON_L2,
2912
+ rpc_exports.ETransactionStatus.ACCEPTED_ON_L1
2913
+ ];
2914
+ let txStatus;
2915
+ while (!onchain) {
2916
+ await wait(retryInterval);
2917
+ try {
2918
+ txStatus = await this.getTransactionStatus(transactionHash);
2919
+ const executionStatus = txStatus.execution_status;
2920
+ const finalityStatus = txStatus.finality_status;
2921
+ if (!finalityStatus) {
2922
+ const error = new Error("waiting for transaction status");
2923
+ throw error;
2924
+ }
2925
+ if (successStates.includes(executionStatus) || successStates.includes(finalityStatus)) {
2926
+ onchain = true;
2927
+ } else if (errorStates.includes(executionStatus) || errorStates.includes(finalityStatus)) {
2928
+ const message = `${executionStatus}: ${finalityStatus}`;
2929
+ const error = new Error(message);
2930
+ error.response = txStatus;
2931
+ isErrorState = true;
2932
+ throw error;
2933
+ }
2934
+ } catch (error) {
2935
+ if (error instanceof Error && isErrorState) {
2936
+ throw error;
2937
+ }
2938
+ if (retries <= 0) {
2939
+ throw new Error(`waitForTransaction timed-out with retries ${this.retries}`);
2940
+ }
2941
+ }
2942
+ retries -= 1;
2943
+ }
2944
+ let txReceipt = null;
2945
+ while (txReceipt === null) {
2946
+ try {
2947
+ txReceipt = await this.getTransactionReceipt(transactionHash);
2948
+ } catch (error) {
2949
+ if (retries <= 0) {
2950
+ throw new Error(`waitForTransaction timed-out with retries ${this.retries}`);
2951
+ }
2952
+ }
2953
+ retries -= 1;
2954
+ await wait(retryInterval);
2955
+ }
2956
+ return txReceipt;
2728
2957
  }
2729
2958
  async getStorageAt(contractAddress, key, blockIdentifier = this.blockIdentifier) {
2959
+ const contract_address = toHex(contractAddress);
2730
2960
  const parsedKey = toStorageKey(key);
2731
2961
  const block_id = new Block(blockIdentifier).identifier;
2732
2962
  return this.fetchEndpoint("starknet_getStorageAt", {
2733
- contract_address: contractAddress,
2963
+ contract_address,
2734
2964
  key: parsedKey,
2735
2965
  block_id
2736
2966
  });
2737
2967
  }
2738
- // Methods from Interface
2739
- async getTransaction(txHash) {
2740
- return this.getTransactionByHash(txHash).then(this.responseParser.parseGetTransactionResponse);
2741
- }
2742
- async getTransactionByHash(txHash) {
2743
- return this.fetchEndpoint("starknet_getTransactionByHash", { transaction_hash: txHash });
2744
- }
2745
- async getTransactionByBlockIdAndIndex(blockIdentifier, index) {
2968
+ async getClassHashAt(contractAddress, blockIdentifier = this.blockIdentifier) {
2969
+ const contract_address = toHex(contractAddress);
2746
2970
  const block_id = new Block(blockIdentifier).identifier;
2747
- return this.fetchEndpoint("starknet_getTransactionByBlockIdAndIndex", { block_id, index });
2748
- }
2749
- async getTransactionReceipt(txHash) {
2750
- return this.fetchEndpoint("starknet_getTransactionReceipt", { transaction_hash: txHash });
2971
+ return this.fetchEndpoint("starknet_getClassHashAt", {
2972
+ block_id,
2973
+ contract_address
2974
+ });
2751
2975
  }
2752
2976
  async getClassByHash(classHash) {
2753
2977
  return this.getClass(classHash);
2754
2978
  }
2755
2979
  async getClass(classHash, blockIdentifier = this.blockIdentifier) {
2980
+ const class_hash = toHex(classHash);
2756
2981
  const block_id = new Block(blockIdentifier).identifier;
2757
2982
  return this.fetchEndpoint("starknet_getClass", {
2758
- class_hash: classHash,
2983
+ class_hash,
2759
2984
  block_id
2760
2985
  }).then(this.responseParser.parseContractClassResponse);
2761
2986
  }
2762
2987
  async getClassAt(contractAddress, blockIdentifier = this.blockIdentifier) {
2988
+ const contract_address = toHex(contractAddress);
2763
2989
  const block_id = new Block(blockIdentifier).identifier;
2764
2990
  return this.fetchEndpoint("starknet_getClassAt", {
2765
2991
  block_id,
2766
- contract_address: contractAddress
2992
+ contract_address
2767
2993
  }).then(this.responseParser.parseContractClassResponse);
2768
2994
  }
2769
2995
  async getCode(_contractAddress, _blockIdentifier) {
@@ -2787,6 +3013,9 @@ var RpcProvider = class {
2787
3013
  }
2788
3014
  return { cairo: "0", compiler: "0" };
2789
3015
  }
3016
+ /**
3017
+ * @deprecated use get*type*EstimateFee (will be refactored based on type after sequencer deprecation)
3018
+ */
2790
3019
  async getEstimateFee(invocation, invocationDetails, blockIdentifier = this.blockIdentifier) {
2791
3020
  return this.getInvokeEstimateFee(invocation, invocationDetails, blockIdentifier);
2792
3021
  }
@@ -2845,11 +3074,24 @@ var RpcProvider = class {
2845
3074
  block_id
2846
3075
  }).then(this.responseParser.parseFeeEstimateBulkResponse);
2847
3076
  }
3077
+ async invokeFunction(functionInvocation, details) {
3078
+ return this.fetchEndpoint("starknet_addInvokeTransaction", {
3079
+ invoke_transaction: {
3080
+ sender_address: functionInvocation.contractAddress,
3081
+ calldata: CallData.toHex(functionInvocation.calldata),
3082
+ type: rpc_exports.ETransactionType.INVOKE,
3083
+ max_fee: toHex(details.maxFee || 0),
3084
+ version: "0x1",
3085
+ signature: signatureToHexArray(functionInvocation.signature),
3086
+ nonce: toHex(details.nonce)
3087
+ }
3088
+ });
3089
+ }
2848
3090
  async declareContract({ contract, signature, senderAddress, compiledClassHash }, details) {
2849
3091
  if (!isSierra(contract)) {
2850
3092
  return this.fetchEndpoint("starknet_addDeclareTransaction", {
2851
3093
  declare_transaction: {
2852
- type: rpc_exports.TransactionType.DECLARE,
3094
+ type: rpc_exports.ETransactionType.DECLARE,
2853
3095
  contract_class: {
2854
3096
  program: contract.program,
2855
3097
  entry_points_by_type: contract.entry_points_by_type,
@@ -2865,7 +3107,7 @@ var RpcProvider = class {
2865
3107
  }
2866
3108
  return this.fetchEndpoint("starknet_addDeclareTransaction", {
2867
3109
  declare_transaction: {
2868
- type: rpc_exports.TransactionType.DECLARE,
3110
+ type: rpc_exports.ETransactionType.DECLARE,
2869
3111
  contract_class: {
2870
3112
  sierra_program: decompressProgram(contract.sierra_program),
2871
3113
  contract_class_version: contract.contract_class_version,
@@ -2887,7 +3129,7 @@ var RpcProvider = class {
2887
3129
  constructor_calldata: CallData.toHex(constructorCalldata || []),
2888
3130
  class_hash: toHex(classHash),
2889
3131
  contract_address_salt: toHex(addressSalt || 0),
2890
- type: rpc_exports.TransactionType.DEPLOY_ACCOUNT,
3132
+ type: rpc_exports.ETransactionType.DEPLOY_ACCOUNT,
2891
3133
  max_fee: toHex(details.maxFee || 0),
2892
3134
  version: toHex(details.version || 0),
2893
3135
  signature: signatureToHexArray(signature),
@@ -2895,20 +3137,6 @@ var RpcProvider = class {
2895
3137
  }
2896
3138
  });
2897
3139
  }
2898
- async invokeFunction(functionInvocation, details) {
2899
- return this.fetchEndpoint("starknet_addInvokeTransaction", {
2900
- invoke_transaction: {
2901
- sender_address: functionInvocation.contractAddress,
2902
- calldata: CallData.toHex(functionInvocation.calldata),
2903
- type: rpc_exports.TransactionType.INVOKE,
2904
- max_fee: toHex(details.maxFee || 0),
2905
- version: "0x1",
2906
- signature: signatureToHexArray(functionInvocation.signature),
2907
- nonce: toHex(details.nonce)
2908
- }
2909
- });
2910
- }
2911
- // Methods from Interface
2912
3140
  async callContract(call, blockIdentifier = this.blockIdentifier) {
2913
3141
  const block_id = new Block(blockIdentifier).identifier;
2914
3142
  const result = await this.fetchEndpoint("starknet_call", {
@@ -2921,117 +3149,47 @@ var RpcProvider = class {
2921
3149
  });
2922
3150
  return this.responseParser.parseCallContractResponse(result);
2923
3151
  }
2924
- async traceTransaction(transactionHash) {
2925
- return this.fetchEndpoint("starknet_traceTransaction", { transaction_hash: transactionHash });
2926
- }
2927
- async traceBlockTransactions(blockHash) {
2928
- return this.fetchEndpoint("starknet_traceBlockTransactions", { block_hash: blockHash });
2929
- }
2930
- async waitForTransaction(txHash, options) {
2931
- let { retries } = this;
2932
- let onchain = false;
2933
- let isErrorState = false;
2934
- let txReceipt = {};
2935
- const retryInterval = options?.retryInterval ?? 5e3;
2936
- const errorStates = options?.errorStates ?? [TransactionExecutionStatus2.REVERTED];
2937
- const successStates = options?.successStates ?? [
2938
- TransactionExecutionStatus2.SUCCEEDED,
2939
- TransactionFinalityStatus2.ACCEPTED_ON_L1,
2940
- TransactionFinalityStatus2.ACCEPTED_ON_L2
2941
- ];
2942
- while (!onchain) {
2943
- await wait(retryInterval);
2944
- try {
2945
- txReceipt = await this.getTransactionReceipt(txHash);
2946
- const executionStatus = pascalToSnake(txReceipt.execution_status);
2947
- const finalityStatus = pascalToSnake(txReceipt.finality_status);
2948
- if (!executionStatus || !finalityStatus) {
2949
- const error = new Error("waiting for transaction status");
2950
- throw error;
2951
- }
2952
- if (successStates.includes(executionStatus) || successStates.includes(finalityStatus)) {
2953
- onchain = true;
2954
- } else if (errorStates.includes(executionStatus) || errorStates.includes(finalityStatus)) {
2955
- const message = `${executionStatus}: ${finalityStatus}: ${txReceipt.revert_reason}`;
2956
- const error = new Error(message);
2957
- error.response = txReceipt;
2958
- isErrorState = true;
2959
- throw error;
2960
- }
2961
- } catch (error) {
2962
- if (error instanceof Error && isErrorState) {
2963
- throw error;
2964
- }
2965
- if (retries === 0) {
2966
- throw new Error(`waitForTransaction timed-out with retries ${this.retries}`);
2967
- }
2968
- }
2969
- retries -= 1;
2970
- }
2971
- await wait(retryInterval);
2972
- return txReceipt;
2973
- }
2974
3152
  /**
2975
- * Gets the transaction count from a block.
2976
- *
2977
- *
2978
- * @param blockIdentifier
2979
- * @returns Number of transactions
3153
+ * NEW: Estimate the fee for a message from L1
3154
+ * @param message Message From L1
2980
3155
  */
2981
- async getTransactionCount(blockIdentifier = this.blockIdentifier) {
3156
+ async estimateMessageFee(message, blockIdentifier = this.blockIdentifier) {
3157
+ const { from_address, to_address, entry_point_selector, payload } = message;
3158
+ const formattedMessage = {
3159
+ from_address: toHex(from_address),
3160
+ to_address: toHex(to_address),
3161
+ entry_point_selector: getSelector(entry_point_selector),
3162
+ payload: getHexStringArray(payload)
3163
+ };
2982
3164
  const block_id = new Block(blockIdentifier).identifier;
2983
- return this.fetchEndpoint("starknet_getBlockTransactionCount", { block_id });
2984
- }
2985
- /**
2986
- * Gets the latest block number
2987
- *
2988
- *
2989
- * @returns Number of the latest block
2990
- */
2991
- async getBlockNumber() {
2992
- return this.fetchEndpoint("starknet_blockNumber");
3165
+ return this.fetchEndpoint("starknet_estimateMessageFee", {
3166
+ message: formattedMessage,
3167
+ block_id
3168
+ });
2993
3169
  }
2994
3170
  /**
2995
- * Gets syncing status of the node
2996
- *
2997
- *
3171
+ * Returns an object about the sync status, or false if the node is not synching
2998
3172
  * @returns Object with the stats data
2999
3173
  */
3000
3174
  async getSyncingStats() {
3001
3175
  return this.fetchEndpoint("starknet_syncing");
3002
3176
  }
3003
3177
  /**
3004
- * Gets all the events filtered
3005
- *
3006
- *
3178
+ * Returns all events matching the given filter
3007
3179
  * @returns events and the pagination of the events
3008
3180
  */
3009
3181
  async getEvents(eventFilter) {
3010
3182
  return this.fetchEndpoint("starknet_getEvents", { filter: eventFilter });
3011
3183
  }
3012
- async getSimulateTransaction(invocations, {
3013
- blockIdentifier = this.blockIdentifier,
3014
- skipValidate = false,
3015
- skipExecute = false,
3016
- // @deprecated
3017
- skipFeeCharge = true
3018
- // Pathfinder currently does not support `starknet_simulateTransactions` without `SKIP_FEE_CHARGE` simulation flag being set. This will become supported in a future release
3019
- }) {
3020
- const block_id = new Block(blockIdentifier).identifier;
3021
- const simulationFlags = [];
3022
- if (skipValidate)
3023
- simulationFlags.push(SimulationFlag.SKIP_VALIDATE);
3024
- if (skipExecute || skipFeeCharge)
3025
- simulationFlags.push(SimulationFlag.SKIP_FEE_CHARGE);
3026
- return this.fetchEndpoint("starknet_simulateTransactions", {
3027
- block_id,
3028
- transactions: invocations.map((it) => this.buildTransaction(it)),
3029
- simulation_flags: simulationFlags
3030
- }).then(this.responseParser.parseSimulateTransactionResponse);
3031
- }
3184
+ /**
3185
+ * StarknetId Endpoint (get name from address)
3186
+ */
3032
3187
  async getStarkName(address, StarknetIdContract2) {
3033
3188
  return getStarkName(this, address, StarknetIdContract2);
3034
3189
  }
3190
+ /**
3191
+ * StarknetId Endpoint (get address from name)
3192
+ */
3035
3193
  async getAddressFromStarkName(name, StarknetIdContract2) {
3036
3194
  return getAddressFromStarkName(this, name, StarknetIdContract2);
3037
3195
  }
@@ -3044,12 +3202,11 @@ var RpcProvider = class {
3044
3202
  };
3045
3203
  if (invocation.type === "INVOKE_FUNCTION" /* INVOKE */) {
3046
3204
  return {
3047
- type: rpc_exports.TransactionType.INVOKE,
3205
+ type: rpc_exports.ETransactionType.INVOKE,
3048
3206
  // Diff between sequencer and rpc invoke type
3049
3207
  sender_address: invocation.contractAddress,
3050
3208
  calldata: CallData.toHex(invocation.calldata),
3051
3209
  version: toHex(invocation.version || defaultVersions.v1),
3052
- // HEX_STR_TRANSACTION_VERSION_1, // as any HOTFIX TODO: Resolve spec version
3053
3210
  ...details
3054
3211
  };
3055
3212
  }
@@ -3060,7 +3217,6 @@ var RpcProvider = class {
3060
3217
  contract_class: invocation.contract,
3061
3218
  sender_address: invocation.senderAddress,
3062
3219
  version: toHex(invocation.version || defaultVersions.v1),
3063
- // HEX_STR_TRANSACTION_VERSION_1, // as any HOTFIX TODO: Resolve spec version
3064
3220
  ...details
3065
3221
  };
3066
3222
  }
@@ -3074,7 +3230,6 @@ var RpcProvider = class {
3074
3230
  compiled_class_hash: invocation.compiledClassHash || "",
3075
3231
  sender_address: invocation.senderAddress,
3076
3232
  version: toHex(invocation.version || defaultVersions.v2),
3077
- // HEX_STR_TRANSACTION_VERSION_2, // as any HOTFIX TODO: Resolve spec version
3078
3233
  ...details
3079
3234
  };
3080
3235
  }
@@ -3758,7 +3913,7 @@ var Provider = class {
3758
3913
  } else if (providerOrOptions && "sequencer" in providerOrOptions) {
3759
3914
  this.provider = new SequencerProvider(providerOrOptions.sequencer);
3760
3915
  } else {
3761
- this.provider = new SequencerProvider();
3916
+ this.provider = new RpcProvider();
3762
3917
  }
3763
3918
  }
3764
3919
  async getChainId() {
@@ -4208,7 +4363,7 @@ var Signer = class {
4208
4363
  // src/utils/events.ts
4209
4364
  function parseUDCEvent(txReceipt) {
4210
4365
  if (!txReceipt.events) {
4211
- throw new Error("UDC emited event is empty");
4366
+ throw new Error("UDC emitted event is empty");
4212
4367
  }
4213
4368
  const event = txReceipt.events.find(
4214
4369
  (it) => cleanHex(it.from_address) === cleanHex(UDC.ADDRESS)
@@ -4747,7 +4902,7 @@ var ProviderInterface = class {
4747
4902
  };
4748
4903
 
4749
4904
  // src/provider/index.ts
4750
- var defaultProvider = new Provider();
4905
+ var defaultProvider = new Provider({ rpc: { default: true } });
4751
4906
 
4752
4907
  // src/account/interface.ts
4753
4908
  var AccountInterface = class extends ProviderInterface {
@@ -5205,6 +5360,7 @@ var number = num_exports;
5205
5360
  fixStack,
5206
5361
  getCalldata,
5207
5362
  getChecksumAddress,
5363
+ getDefaultNodeUrl,
5208
5364
  hash,
5209
5365
  isSierra,
5210
5366
  isUrl,