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.mjs CHANGED
@@ -19,6 +19,8 @@ __export(constants_exports, {
19
19
  MASK_250: () => MASK_250,
20
20
  MASK_251: () => MASK_251,
21
21
  NetworkName: () => NetworkName,
22
+ RPC_GOERLI_NODES: () => RPC_GOERLI_NODES,
23
+ RPC_MAINNET_NODES: () => RPC_MAINNET_NODES,
22
24
  StarknetChainId: () => StarknetChainId,
23
25
  TEXT_TO_FELT_MAX_LEN: () => TEXT_TO_FELT_MAX_LEN,
24
26
  TransactionHashPrefix: () => TransactionHashPrefix,
@@ -44,6 +46,7 @@ __export(encode_exports, {
44
46
  stringToArrayBuffer: () => stringToArrayBuffer,
45
47
  utf8ToArray: () => utf8ToArray
46
48
  });
49
+ import { base64 } from "@scure/base";
47
50
  var IS_BROWSER = typeof window !== "undefined";
48
51
  var STRING_ZERO = "0";
49
52
  function arrayBufferToString(array) {
@@ -56,10 +59,10 @@ function stringToArrayBuffer(str) {
56
59
  return utf8ToArray(str);
57
60
  }
58
61
  function atobUniversal(a) {
59
- return IS_BROWSER ? utf8ToArray(atob(a)) : Buffer.from(a, "base64");
62
+ return base64.decode(a);
60
63
  }
61
64
  function btoaUniversal(b) {
62
- return IS_BROWSER ? btoa(arrayBufferToString(b)) : Buffer.from(b).toString("base64");
65
+ return base64.encode(new Uint8Array(b));
63
66
  }
64
67
  function buf2hex(buffer) {
65
68
  return buffer.reduce((r, x) => r + x.toString(16).padStart(2, "0"), "");
@@ -139,6 +142,14 @@ var UDC = {
139
142
  ADDRESS: "0x041a78e741e5af2fec34b695679bc6891742439f7afb8484ecd7766661ad02bf",
140
143
  ENTRYPOINT: "deployContract"
141
144
  };
145
+ var RPC_GOERLI_NODES = [
146
+ "https://starknet-testnet.public.blastapi.io/rpc/v0.5",
147
+ "https://limited-rpc.nethermind.io/goerli-juno/v0_5"
148
+ ];
149
+ var RPC_MAINNET_NODES = [
150
+ "https://starknet-mainnet.public.blastapi.io/rpc/v0.5",
151
+ "https://limited-rpc.nethermind.io/mainnet-juno/v0_5"
152
+ ];
142
153
 
143
154
  // src/types/index.ts
144
155
  var types_exports = {};
@@ -159,10 +170,10 @@ __export(types_exports, {
159
170
  });
160
171
 
161
172
  // src/types/account.ts
162
- var SIMULATION_FLAG = /* @__PURE__ */ ((SIMULATION_FLAG3) => {
163
- SIMULATION_FLAG3["SKIP_VALIDATE"] = "SKIP_VALIDATE";
164
- SIMULATION_FLAG3["SKIP_EXECUTE"] = "SKIP_EXECUTE";
165
- return SIMULATION_FLAG3;
173
+ var SIMULATION_FLAG = /* @__PURE__ */ ((SIMULATION_FLAG2) => {
174
+ SIMULATION_FLAG2["SKIP_VALIDATE"] = "SKIP_VALIDATE";
175
+ SIMULATION_FLAG2["SKIP_EXECUTE"] = "SKIP_EXECUTE";
176
+ return SIMULATION_FLAG2;
166
177
  })(SIMULATION_FLAG || {});
167
178
 
168
179
  // src/types/calldata.ts
@@ -196,12 +207,12 @@ var EntryPointType = /* @__PURE__ */ ((EntryPointType2) => {
196
207
  })(EntryPointType || {});
197
208
 
198
209
  // src/types/lib/index.ts
199
- var TransactionType = /* @__PURE__ */ ((TransactionType3) => {
200
- TransactionType3["DECLARE"] = "DECLARE";
201
- TransactionType3["DEPLOY"] = "DEPLOY";
202
- TransactionType3["DEPLOY_ACCOUNT"] = "DEPLOY_ACCOUNT";
203
- TransactionType3["INVOKE"] = "INVOKE_FUNCTION";
204
- return TransactionType3;
210
+ var TransactionType = /* @__PURE__ */ ((TransactionType2) => {
211
+ TransactionType2["DECLARE"] = "DECLARE";
212
+ TransactionType2["DEPLOY"] = "DEPLOY";
213
+ TransactionType2["DEPLOY_ACCOUNT"] = "DEPLOY_ACCOUNT";
214
+ TransactionType2["INVOKE"] = "INVOKE_FUNCTION";
215
+ return TransactionType2;
205
216
  })(TransactionType || {});
206
217
  var TransactionStatus = /* @__PURE__ */ ((TransactionStatus2) => {
207
218
  TransactionStatus2["NOT_RECEIVED"] = "NOT_RECEIVED";
@@ -212,18 +223,18 @@ var TransactionStatus = /* @__PURE__ */ ((TransactionStatus2) => {
212
223
  TransactionStatus2["REVERTED"] = "REVERTED";
213
224
  return TransactionStatus2;
214
225
  })(TransactionStatus || {});
215
- var TransactionFinalityStatus = /* @__PURE__ */ ((TransactionFinalityStatus3) => {
216
- TransactionFinalityStatus3["NOT_RECEIVED"] = "NOT_RECEIVED";
217
- TransactionFinalityStatus3["RECEIVED"] = "RECEIVED";
218
- TransactionFinalityStatus3["ACCEPTED_ON_L2"] = "ACCEPTED_ON_L2";
219
- TransactionFinalityStatus3["ACCEPTED_ON_L1"] = "ACCEPTED_ON_L1";
220
- return TransactionFinalityStatus3;
226
+ var TransactionFinalityStatus = /* @__PURE__ */ ((TransactionFinalityStatus2) => {
227
+ TransactionFinalityStatus2["NOT_RECEIVED"] = "NOT_RECEIVED";
228
+ TransactionFinalityStatus2["RECEIVED"] = "RECEIVED";
229
+ TransactionFinalityStatus2["ACCEPTED_ON_L2"] = "ACCEPTED_ON_L2";
230
+ TransactionFinalityStatus2["ACCEPTED_ON_L1"] = "ACCEPTED_ON_L1";
231
+ return TransactionFinalityStatus2;
221
232
  })(TransactionFinalityStatus || {});
222
- var TransactionExecutionStatus = /* @__PURE__ */ ((TransactionExecutionStatus3) => {
223
- TransactionExecutionStatus3["REJECTED"] = "REJECTED";
224
- TransactionExecutionStatus3["REVERTED"] = "REVERTED";
225
- TransactionExecutionStatus3["SUCCEEDED"] = "SUCCEEDED";
226
- return TransactionExecutionStatus3;
233
+ var TransactionExecutionStatus = /* @__PURE__ */ ((TransactionExecutionStatus2) => {
234
+ TransactionExecutionStatus2["REJECTED"] = "REJECTED";
235
+ TransactionExecutionStatus2["REVERTED"] = "REVERTED";
236
+ TransactionExecutionStatus2["SUCCEEDED"] = "SUCCEEDED";
237
+ return TransactionExecutionStatus2;
227
238
  })(TransactionExecutionStatus || {});
228
239
  var BlockStatus = /* @__PURE__ */ ((BlockStatus2) => {
229
240
  BlockStatus2["PENDING"] = "PENDING";
@@ -241,42 +252,68 @@ var BlockTag = /* @__PURE__ */ ((BlockTag2) => {
241
252
  // src/types/api/rpc.ts
242
253
  var rpc_exports = {};
243
254
  __export(rpc_exports, {
244
- SimulationFlag: () => SimulationFlag,
245
- TransactionExecutionStatus: () => TransactionExecutionStatus2,
246
- TransactionFinalityStatus: () => TransactionFinalityStatus2,
247
- TransactionType: () => TransactionType2
255
+ EBlockTag: () => EBlockTag,
256
+ EDataAvailabilityMode: () => EDataAvailabilityMode,
257
+ ESimulationFlag: () => ESimulationFlag,
258
+ ETransactionExecutionStatus: () => ETransactionExecutionStatus,
259
+ ETransactionFinalityStatus: () => ETransactionFinalityStatus,
260
+ ETransactionStatus: () => ETransactionStatus,
261
+ ETransactionType: () => ETransactionType,
262
+ Errors: () => errors_exports,
263
+ JRPC: () => jsonrpc_exports,
264
+ SPEC: () => components_exports
248
265
  });
249
266
 
250
- // src/types/api/openrpc.ts
251
- var TXN_TYPE = /* @__PURE__ */ ((TXN_TYPE2) => {
252
- TXN_TYPE2["DECLARE"] = "DECLARE";
253
- TXN_TYPE2["DEPLOY"] = "DEPLOY";
254
- TXN_TYPE2["DEPLOY_ACCOUNT"] = "DEPLOY_ACCOUNT";
255
- TXN_TYPE2["INVOKE"] = "INVOKE";
256
- TXN_TYPE2["L1_HANDLER"] = "L1_HANDLER";
257
- return TXN_TYPE2;
258
- })(TXN_TYPE || {});
259
- var TXN_FINALITY_STATUS = /* @__PURE__ */ ((TXN_FINALITY_STATUS2) => {
260
- TXN_FINALITY_STATUS2["ACCEPTED_ON_L2"] = "ACCEPTED_ON_L2";
261
- TXN_FINALITY_STATUS2["ACCEPTED_ON_L1"] = "ACCEPTED_ON_L1";
262
- return TXN_FINALITY_STATUS2;
263
- })(TXN_FINALITY_STATUS || {});
264
- var TXN_EXECUTION_STATUS = /* @__PURE__ */ ((TXN_EXECUTION_STATUS2) => {
265
- TXN_EXECUTION_STATUS2["SUCCEEDED"] = "SUCCEEDED";
266
- TXN_EXECUTION_STATUS2["REVERTED"] = "REVERTED";
267
- return TXN_EXECUTION_STATUS2;
268
- })(TXN_EXECUTION_STATUS || {});
269
- var SIMULATION_FLAG2 = /* @__PURE__ */ ((SIMULATION_FLAG3) => {
270
- SIMULATION_FLAG3["SKIP_VALIDATE"] = "SKIP_VALIDATE";
271
- SIMULATION_FLAG3["SKIP_FEE_CHARGE"] = "SKIP_FEE_CHARGE";
272
- return SIMULATION_FLAG3;
273
- })(SIMULATION_FLAG2 || {});
267
+ // src/types/api/jsonrpc/index.ts
268
+ var jsonrpc_exports = {};
274
269
 
275
- // src/types/api/rpc.ts
276
- var TransactionType2 = TXN_TYPE;
277
- var SimulationFlag = SIMULATION_FLAG2;
278
- var TransactionFinalityStatus2 = TXN_FINALITY_STATUS;
279
- var TransactionExecutionStatus2 = TXN_EXECUTION_STATUS;
270
+ // src/types/api/rpcspec/errors.ts
271
+ var errors_exports = {};
272
+
273
+ // src/types/api/rpcspec/components.ts
274
+ var components_exports = {};
275
+
276
+ // src/types/api/rpcspec/nonspec.ts
277
+ var ETransactionType = /* @__PURE__ */ ((ETransactionType2) => {
278
+ ETransactionType2["DECLARE"] = "DECLARE";
279
+ ETransactionType2["DEPLOY"] = "DEPLOY";
280
+ ETransactionType2["DEPLOY_ACCOUNT"] = "DEPLOY_ACCOUNT";
281
+ ETransactionType2["INVOKE"] = "INVOKE";
282
+ ETransactionType2["L1_HANDLER"] = "L1_HANDLER";
283
+ return ETransactionType2;
284
+ })(ETransactionType || {});
285
+ var ESimulationFlag = /* @__PURE__ */ ((ESimulationFlag2) => {
286
+ ESimulationFlag2["SKIP_VALIDATE"] = "SKIP_VALIDATE";
287
+ ESimulationFlag2["SKIP_FEE_CHARGE"] = "SKIP_FEE_CHARGE";
288
+ return ESimulationFlag2;
289
+ })(ESimulationFlag || {});
290
+ var ETransactionStatus = /* @__PURE__ */ ((ETransactionStatus2) => {
291
+ ETransactionStatus2["RECEIVED"] = "RECEIVED";
292
+ ETransactionStatus2["REJECTED"] = "REJECTED";
293
+ ETransactionStatus2["ACCEPTED_ON_L2"] = "ACCEPTED_ON_L2";
294
+ ETransactionStatus2["ACCEPTED_ON_L1"] = "ACCEPTED_ON_L1";
295
+ return ETransactionStatus2;
296
+ })(ETransactionStatus || {});
297
+ var ETransactionFinalityStatus = /* @__PURE__ */ ((ETransactionFinalityStatus2) => {
298
+ ETransactionFinalityStatus2["ACCEPTED_ON_L2"] = "ACCEPTED_ON_L2";
299
+ ETransactionFinalityStatus2["ACCEPTED_ON_L1"] = "ACCEPTED_ON_L1";
300
+ return ETransactionFinalityStatus2;
301
+ })(ETransactionFinalityStatus || {});
302
+ var ETransactionExecutionStatus = /* @__PURE__ */ ((ETransactionExecutionStatus2) => {
303
+ ETransactionExecutionStatus2["SUCCEEDED"] = "SUCCEEDED";
304
+ ETransactionExecutionStatus2["REVERTED"] = "REVERTED";
305
+ return ETransactionExecutionStatus2;
306
+ })(ETransactionExecutionStatus || {});
307
+ var EBlockTag = /* @__PURE__ */ ((EBlockTag2) => {
308
+ EBlockTag2["LATEST"] = "latest";
309
+ EBlockTag2["PENDING"] = "pending";
310
+ return EBlockTag2;
311
+ })(EBlockTag || {});
312
+ var EDataAvailabilityMode = /* @__PURE__ */ ((EDataAvailabilityMode2) => {
313
+ EDataAvailabilityMode2["L1"] = "L1";
314
+ EDataAvailabilityMode2["L2"] = "L2";
315
+ return EDataAvailabilityMode2;
316
+ })(EDataAvailabilityMode || {});
280
317
 
281
318
  // src/types/api/sequencer.ts
282
319
  var sequencer_exports = {};
@@ -2144,10 +2181,10 @@ function compressProgram(jsonProgram) {
2144
2181
  const compressedProgram = gzip(stringified);
2145
2182
  return btoaUniversal(compressedProgram);
2146
2183
  }
2147
- function decompressProgram(base64) {
2148
- if (Array.isArray(base64))
2149
- return base64;
2150
- const decompressed = arrayBufferToString(ungzip(atobUniversal(base64)));
2184
+ function decompressProgram(base642) {
2185
+ if (Array.isArray(base642))
2186
+ return base642;
2187
+ const decompressed = arrayBufferToString(ungzip(atobUniversal(base642)));
2151
2188
  return parse2(decompressed);
2152
2189
  }
2153
2190
  function randomAddress() {
@@ -2252,22 +2289,22 @@ var RPCResponseParser = class {
2252
2289
  parseGetBlockResponse(res) {
2253
2290
  return {
2254
2291
  timestamp: res.timestamp,
2255
- block_hash: res.block_hash,
2256
- block_number: res.block_number,
2257
- new_root: res.new_root,
2292
+ block_hash: "block_hash" in res ? res.block_hash : "",
2293
+ block_number: "block_number" in res ? res.block_number : -1,
2294
+ new_root: "new_root" in res ? res.new_root : "",
2258
2295
  parent_hash: res.parent_hash,
2259
- status: res.status,
2296
+ status: "status" in res ? res.status : "PENDING" /* PENDING */,
2260
2297
  transactions: res.transactions
2261
2298
  };
2262
2299
  }
2263
2300
  parseGetTransactionResponse(res) {
2264
2301
  return {
2265
- calldata: res.calldata || [],
2266
- contract_address: res.contract_address,
2267
- sender_address: res.contract_address,
2268
- max_fee: res.max_fee,
2269
- nonce: res.nonce,
2270
- signature: res.signature || [],
2302
+ calldata: "calldata" in res ? res.calldata : [],
2303
+ contract_address: "contract_address" in res ? res.contract_address : "",
2304
+ sender_address: "sender_address" in res ? res.sender_address : "",
2305
+ max_fee: "max_fee" in res ? res.max_fee : "",
2306
+ nonce: "nonce" in res ? res.nonce : "",
2307
+ signature: "signature" in res ? res.signature : [],
2271
2308
  transaction_hash: res.transaction_hash,
2272
2309
  version: res.version
2273
2310
  };
@@ -2543,6 +2580,13 @@ var Block = class {
2543
2580
  };
2544
2581
 
2545
2582
  // src/provider/rpc.ts
2583
+ var getDefaultNodeUrl = (networkName, mute = false) => {
2584
+ if (!mute)
2585
+ console.warn("Using default public node url, please provide nodeUrl in provider options!");
2586
+ const nodes = networkName === "SN_MAIN" /* SN_MAIN */ ? RPC_MAINNET_NODES : RPC_GOERLI_NODES;
2587
+ const randIdx = Math.floor(Math.random() * nodes.length);
2588
+ return nodes[randIdx];
2589
+ };
2546
2590
  var defaultOptions = {
2547
2591
  headers: { "Content-Type": "application/json" },
2548
2592
  blockIdentifier: "pending" /* pending */,
@@ -2551,52 +2595,126 @@ var defaultOptions = {
2551
2595
  var RpcProvider = class {
2552
2596
  constructor(optionsOrProvider) {
2553
2597
  this.responseParser = new RPCResponseParser();
2554
- const { nodeUrl, retries, headers, blockIdentifier, chainId } = optionsOrProvider;
2555
- this.nodeUrl = nodeUrl;
2598
+ /**
2599
+ * @deprecated renamed to getBlockLatestAccepted(); (will be removed in next minor version)
2600
+ */
2601
+ this.getBlockHashAndNumber = this.getBlockLatestAccepted;
2602
+ /**
2603
+ * @deprecated renamed to getBlockStateUpdate();
2604
+ */
2605
+ this.getStateUpdate = this.getBlockStateUpdate;
2606
+ /**
2607
+ * Returns the execution traces of all transactions included in the given block
2608
+ * @deprecated renamed to getBlockTransactionsTraces()
2609
+ */
2610
+ this.traceBlockTransactions = this.getBlockTransactionsTraces;
2611
+ /**
2612
+ * Get the number of transactions in a block given a block id
2613
+ * @deprecated renamed to getBlockTransactionCount()
2614
+ * @returns Number of transactions
2615
+ */
2616
+ this.getTransactionCount = this.getBlockTransactionCount;
2617
+ /**
2618
+ * @deprecated renamed to getTransactionTrace();
2619
+ * For a given executed transaction, return the trace of its execution, including internal calls
2620
+ */
2621
+ this.traceTransaction = this.getTransactionTrace;
2622
+ /**
2623
+ * @deprecated renamed to simulateTransaction();
2624
+ */
2625
+ this.getSimulateTransaction = this.simulateTransaction;
2626
+ const { nodeUrl, retries, headers, blockIdentifier, chainId } = optionsOrProvider || {};
2627
+ if (Object.values(NetworkName).includes(nodeUrl)) {
2628
+ this.nodeUrl = getDefaultNodeUrl(nodeUrl, optionsOrProvider?.default);
2629
+ } else if (nodeUrl) {
2630
+ this.nodeUrl = nodeUrl;
2631
+ } else {
2632
+ this.nodeUrl = getDefaultNodeUrl(void 0, optionsOrProvider?.default);
2633
+ }
2556
2634
  this.retries = retries || defaultOptions.retries;
2557
2635
  this.headers = { ...defaultOptions.headers, ...headers };
2558
2636
  this.blockIdentifier = blockIdentifier || defaultOptions.blockIdentifier;
2559
2637
  this.chainId = chainId;
2560
- this.getChainId();
2561
2638
  }
2562
- fetch(method, params) {
2563
- const body = stringify2({ method, jsonrpc: "2.0", params, id: 0 });
2639
+ fetch(method, params, id = 0) {
2640
+ const rpcRequestBody = {
2641
+ id,
2642
+ jsonrpc: "2.0",
2643
+ method,
2644
+ ...params && { params }
2645
+ };
2564
2646
  return fetchPonyfill_default(this.nodeUrl, {
2565
2647
  method: "POST",
2566
- body,
2648
+ body: stringify2(rpcRequestBody),
2567
2649
  headers: this.headers
2568
2650
  });
2569
2651
  }
2570
- errorHandler(error) {
2571
- if (error) {
2572
- const { code, message } = error;
2573
- throw new LibraryError(`${code}: ${message}`);
2652
+ errorHandler(method, params, rpcError, otherError) {
2653
+ if (rpcError) {
2654
+ const { code, message, data } = rpcError;
2655
+ throw new LibraryError(
2656
+ `RPC: ${method} with params ${JSON.stringify(params)}
2657
+ ${code}: ${message}: ${data}`
2658
+ );
2659
+ }
2660
+ if (otherError instanceof LibraryError) {
2661
+ throw otherError;
2662
+ }
2663
+ if (otherError) {
2664
+ throw Error(otherError.message);
2574
2665
  }
2575
2666
  }
2576
2667
  async fetchEndpoint(method, params) {
2577
2668
  try {
2578
2669
  const rawResult = await this.fetch(method, params);
2579
2670
  const { error, result } = await rawResult.json();
2580
- this.errorHandler(error);
2671
+ this.errorHandler(method, params, error);
2581
2672
  return result;
2582
2673
  } catch (error) {
2583
- this.errorHandler(error?.response?.data);
2674
+ this.errorHandler(method, params, error?.response?.data, error);
2584
2675
  throw error;
2585
2676
  }
2586
2677
  }
2587
- // Methods from Interface
2588
2678
  async getChainId() {
2589
2679
  this.chainId ?? (this.chainId = await this.fetchEndpoint("starknet_chainId"));
2590
2680
  return this.chainId;
2591
2681
  }
2682
+ /**
2683
+ * NEW: Returns the version of the Starknet JSON-RPC specification being used
2684
+ */
2685
+ async getSpecVersion() {
2686
+ return this.fetchEndpoint("starknet_specVersion");
2687
+ }
2688
+ async getNonceForAddress(contractAddress, blockIdentifier = this.blockIdentifier) {
2689
+ const contract_address = toHex(contractAddress);
2690
+ const block_id = new Block(blockIdentifier).identifier;
2691
+ return this.fetchEndpoint("starknet_getNonce", {
2692
+ contract_address,
2693
+ block_id
2694
+ });
2695
+ }
2696
+ /**
2697
+ * @deprecated use getBlockWithTxHashes or getBlockWithTxs (will be removed on sequencer deprecation)
2698
+ */
2592
2699
  async getBlock(blockIdentifier = this.blockIdentifier) {
2593
2700
  return this.getBlockWithTxHashes(blockIdentifier).then(
2594
2701
  this.responseParser.parseGetBlockResponse
2595
2702
  );
2596
2703
  }
2597
- async getBlockHashAndNumber() {
2704
+ /**
2705
+ * Get the most recent accepted block hash and number
2706
+ */
2707
+ async getBlockLatestAccepted() {
2598
2708
  return this.fetchEndpoint("starknet_blockHashAndNumber");
2599
2709
  }
2710
+ /**
2711
+ * @deprecated redundant use getBlockLatestAccepted();
2712
+ * Get the most recent accepted block number
2713
+ * @returns Number of the latest block
2714
+ */
2715
+ async getBlockNumber() {
2716
+ return this.fetchEndpoint("starknet_blockNumber");
2717
+ }
2600
2718
  async getBlockWithTxHashes(blockIdentifier = this.blockIdentifier) {
2601
2719
  const block_id = new Block(blockIdentifier).identifier;
2602
2720
  return this.fetchEndpoint("starknet_getBlockWithTxHashes", { block_id });
@@ -2605,68 +2723,175 @@ var RpcProvider = class {
2605
2723
  const block_id = new Block(blockIdentifier).identifier;
2606
2724
  return this.fetchEndpoint("starknet_getBlockWithTxs", { block_id });
2607
2725
  }
2608
- async getClassHashAt(contractAddress, blockIdentifier = this.blockIdentifier) {
2726
+ async getBlockStateUpdate(blockIdentifier = this.blockIdentifier) {
2609
2727
  const block_id = new Block(blockIdentifier).identifier;
2610
- return this.fetchEndpoint("starknet_getClassHashAt", {
2611
- block_id,
2612
- contract_address: contractAddress
2613
- });
2728
+ return this.fetchEndpoint("starknet_getStateUpdate", { block_id });
2614
2729
  }
2615
- async getNonceForAddress(contractAddress, blockIdentifier = this.blockIdentifier) {
2730
+ async getBlockTransactionsTraces(blockIdentifier = this.blockIdentifier) {
2616
2731
  const block_id = new Block(blockIdentifier).identifier;
2617
- return this.fetchEndpoint("starknet_getNonce", {
2618
- contract_address: contractAddress,
2619
- block_id
2620
- });
2732
+ return this.fetchEndpoint("starknet_traceBlockTransactions", { block_id });
2621
2733
  }
2734
+ async getBlockTransactionCount(blockIdentifier = this.blockIdentifier) {
2735
+ const block_id = new Block(blockIdentifier).identifier;
2736
+ return this.fetchEndpoint("starknet_getBlockTransactionCount", { block_id });
2737
+ }
2738
+ /**
2739
+ * Return transactions from pending block
2740
+ * @deprecated Instead use getBlock(BlockTag.pending); (will be removed in next minor version)
2741
+ */
2622
2742
  async getPendingTransactions() {
2623
- return this.fetchEndpoint("starknet_pendingTransactions");
2743
+ const { transactions } = await this.getBlock("pending" /* pending */);
2744
+ return Promise.all(transactions.map((it) => this.getTransactionByHash(it)));
2624
2745
  }
2625
- async getProtocolVersion() {
2626
- throw new Error("Pathfinder does not implement this rpc 0.1.0 method");
2746
+ /**
2747
+ * @deprecated use getTransactionByHash or getTransactionByBlockIdAndIndex (will be removed on sequencer deprecation)
2748
+ */
2749
+ async getTransaction(txHash) {
2750
+ return this.getTransactionByHash(txHash).then(this.responseParser.parseGetTransactionResponse);
2627
2751
  }
2628
- async getStateUpdate(blockIdentifier = this.blockIdentifier) {
2752
+ async getTransactionByHash(txHash) {
2753
+ const transaction_hash = toHex(txHash);
2754
+ return this.fetchEndpoint("starknet_getTransactionByHash", {
2755
+ transaction_hash
2756
+ });
2757
+ }
2758
+ async getTransactionByBlockIdAndIndex(blockIdentifier, index) {
2629
2759
  const block_id = new Block(blockIdentifier).identifier;
2630
- return this.fetchEndpoint("starknet_getStateUpdate", { block_id });
2760
+ return this.fetchEndpoint("starknet_getTransactionByBlockIdAndIndex", { block_id, index });
2761
+ }
2762
+ async getTransactionReceipt(txHash) {
2763
+ const transaction_hash = toHex(txHash);
2764
+ return this.fetchEndpoint("starknet_getTransactionReceipt", { transaction_hash });
2765
+ }
2766
+ async getTransactionTrace(txHash) {
2767
+ const transaction_hash = toHex(txHash);
2768
+ return this.fetchEndpoint("starknet_traceTransaction", { transaction_hash });
2769
+ }
2770
+ /**
2771
+ * NEW: Get the status of a transaction
2772
+ */
2773
+ async getTransactionStatus(transactionHash) {
2774
+ const transaction_hash = toHex(transactionHash);
2775
+ return this.fetchEndpoint("starknet_getTransactionStatus", { transaction_hash });
2776
+ }
2777
+ /**
2778
+ * @param invocations AccountInvocations
2779
+ * @param simulateTransactionOptions blockIdentifier and flags to skip validation and fee charge<br/>
2780
+ * - blockIdentifier<br/>
2781
+ * - skipValidate (default false)<br/>
2782
+ * - skipFeeCharge (default true)<br/>
2783
+ */
2784
+ async simulateTransaction(invocations, {
2785
+ blockIdentifier = this.blockIdentifier,
2786
+ skipValidate = false,
2787
+ skipFeeCharge = true
2788
+ }) {
2789
+ const block_id = new Block(blockIdentifier).identifier;
2790
+ const simulationFlags = [];
2791
+ if (skipValidate)
2792
+ simulationFlags.push(rpc_exports.ESimulationFlag.SKIP_VALIDATE);
2793
+ if (skipFeeCharge)
2794
+ simulationFlags.push(rpc_exports.ESimulationFlag.SKIP_FEE_CHARGE);
2795
+ return this.fetchEndpoint("starknet_simulateTransactions", {
2796
+ block_id,
2797
+ transactions: invocations.map((it) => this.buildTransaction(it)),
2798
+ simulation_flags: simulationFlags
2799
+ }).then(this.responseParser.parseSimulateTransactionResponse);
2800
+ }
2801
+ async waitForTransaction(txHash, options) {
2802
+ const transactionHash = toHex(txHash);
2803
+ let { retries } = this;
2804
+ let onchain = false;
2805
+ let isErrorState = false;
2806
+ const retryInterval = options?.retryInterval ?? 5e3;
2807
+ const errorStates = options?.errorStates ?? [
2808
+ rpc_exports.ETransactionStatus.REJECTED,
2809
+ rpc_exports.ETransactionExecutionStatus.REVERTED
2810
+ ];
2811
+ const successStates = options?.successStates ?? [
2812
+ rpc_exports.ETransactionExecutionStatus.SUCCEEDED,
2813
+ rpc_exports.ETransactionStatus.ACCEPTED_ON_L2,
2814
+ rpc_exports.ETransactionStatus.ACCEPTED_ON_L1
2815
+ ];
2816
+ let txStatus;
2817
+ while (!onchain) {
2818
+ await wait(retryInterval);
2819
+ try {
2820
+ txStatus = await this.getTransactionStatus(transactionHash);
2821
+ const executionStatus = txStatus.execution_status;
2822
+ const finalityStatus = txStatus.finality_status;
2823
+ if (!finalityStatus) {
2824
+ const error = new Error("waiting for transaction status");
2825
+ throw error;
2826
+ }
2827
+ if (successStates.includes(executionStatus) || successStates.includes(finalityStatus)) {
2828
+ onchain = true;
2829
+ } else if (errorStates.includes(executionStatus) || errorStates.includes(finalityStatus)) {
2830
+ const message = `${executionStatus}: ${finalityStatus}`;
2831
+ const error = new Error(message);
2832
+ error.response = txStatus;
2833
+ isErrorState = true;
2834
+ throw error;
2835
+ }
2836
+ } catch (error) {
2837
+ if (error instanceof Error && isErrorState) {
2838
+ throw error;
2839
+ }
2840
+ if (retries <= 0) {
2841
+ throw new Error(`waitForTransaction timed-out with retries ${this.retries}`);
2842
+ }
2843
+ }
2844
+ retries -= 1;
2845
+ }
2846
+ let txReceipt = null;
2847
+ while (txReceipt === null) {
2848
+ try {
2849
+ txReceipt = await this.getTransactionReceipt(transactionHash);
2850
+ } catch (error) {
2851
+ if (retries <= 0) {
2852
+ throw new Error(`waitForTransaction timed-out with retries ${this.retries}`);
2853
+ }
2854
+ }
2855
+ retries -= 1;
2856
+ await wait(retryInterval);
2857
+ }
2858
+ return txReceipt;
2631
2859
  }
2632
2860
  async getStorageAt(contractAddress, key, blockIdentifier = this.blockIdentifier) {
2861
+ const contract_address = toHex(contractAddress);
2633
2862
  const parsedKey = toStorageKey(key);
2634
2863
  const block_id = new Block(blockIdentifier).identifier;
2635
2864
  return this.fetchEndpoint("starknet_getStorageAt", {
2636
- contract_address: contractAddress,
2865
+ contract_address,
2637
2866
  key: parsedKey,
2638
2867
  block_id
2639
2868
  });
2640
2869
  }
2641
- // Methods from Interface
2642
- async getTransaction(txHash) {
2643
- return this.getTransactionByHash(txHash).then(this.responseParser.parseGetTransactionResponse);
2644
- }
2645
- async getTransactionByHash(txHash) {
2646
- return this.fetchEndpoint("starknet_getTransactionByHash", { transaction_hash: txHash });
2647
- }
2648
- async getTransactionByBlockIdAndIndex(blockIdentifier, index) {
2870
+ async getClassHashAt(contractAddress, blockIdentifier = this.blockIdentifier) {
2871
+ const contract_address = toHex(contractAddress);
2649
2872
  const block_id = new Block(blockIdentifier).identifier;
2650
- return this.fetchEndpoint("starknet_getTransactionByBlockIdAndIndex", { block_id, index });
2651
- }
2652
- async getTransactionReceipt(txHash) {
2653
- return this.fetchEndpoint("starknet_getTransactionReceipt", { transaction_hash: txHash });
2873
+ return this.fetchEndpoint("starknet_getClassHashAt", {
2874
+ block_id,
2875
+ contract_address
2876
+ });
2654
2877
  }
2655
2878
  async getClassByHash(classHash) {
2656
2879
  return this.getClass(classHash);
2657
2880
  }
2658
2881
  async getClass(classHash, blockIdentifier = this.blockIdentifier) {
2882
+ const class_hash = toHex(classHash);
2659
2883
  const block_id = new Block(blockIdentifier).identifier;
2660
2884
  return this.fetchEndpoint("starknet_getClass", {
2661
- class_hash: classHash,
2885
+ class_hash,
2662
2886
  block_id
2663
2887
  }).then(this.responseParser.parseContractClassResponse);
2664
2888
  }
2665
2889
  async getClassAt(contractAddress, blockIdentifier = this.blockIdentifier) {
2890
+ const contract_address = toHex(contractAddress);
2666
2891
  const block_id = new Block(blockIdentifier).identifier;
2667
2892
  return this.fetchEndpoint("starknet_getClassAt", {
2668
2893
  block_id,
2669
- contract_address: contractAddress
2894
+ contract_address
2670
2895
  }).then(this.responseParser.parseContractClassResponse);
2671
2896
  }
2672
2897
  async getCode(_contractAddress, _blockIdentifier) {
@@ -2690,6 +2915,9 @@ var RpcProvider = class {
2690
2915
  }
2691
2916
  return { cairo: "0", compiler: "0" };
2692
2917
  }
2918
+ /**
2919
+ * @deprecated use get*type*EstimateFee (will be refactored based on type after sequencer deprecation)
2920
+ */
2693
2921
  async getEstimateFee(invocation, invocationDetails, blockIdentifier = this.blockIdentifier) {
2694
2922
  return this.getInvokeEstimateFee(invocation, invocationDetails, blockIdentifier);
2695
2923
  }
@@ -2748,11 +2976,24 @@ var RpcProvider = class {
2748
2976
  block_id
2749
2977
  }).then(this.responseParser.parseFeeEstimateBulkResponse);
2750
2978
  }
2979
+ async invokeFunction(functionInvocation, details) {
2980
+ return this.fetchEndpoint("starknet_addInvokeTransaction", {
2981
+ invoke_transaction: {
2982
+ sender_address: functionInvocation.contractAddress,
2983
+ calldata: CallData.toHex(functionInvocation.calldata),
2984
+ type: rpc_exports.ETransactionType.INVOKE,
2985
+ max_fee: toHex(details.maxFee || 0),
2986
+ version: "0x1",
2987
+ signature: signatureToHexArray(functionInvocation.signature),
2988
+ nonce: toHex(details.nonce)
2989
+ }
2990
+ });
2991
+ }
2751
2992
  async declareContract({ contract, signature, senderAddress, compiledClassHash }, details) {
2752
2993
  if (!isSierra(contract)) {
2753
2994
  return this.fetchEndpoint("starknet_addDeclareTransaction", {
2754
2995
  declare_transaction: {
2755
- type: rpc_exports.TransactionType.DECLARE,
2996
+ type: rpc_exports.ETransactionType.DECLARE,
2756
2997
  contract_class: {
2757
2998
  program: contract.program,
2758
2999
  entry_points_by_type: contract.entry_points_by_type,
@@ -2768,7 +3009,7 @@ var RpcProvider = class {
2768
3009
  }
2769
3010
  return this.fetchEndpoint("starknet_addDeclareTransaction", {
2770
3011
  declare_transaction: {
2771
- type: rpc_exports.TransactionType.DECLARE,
3012
+ type: rpc_exports.ETransactionType.DECLARE,
2772
3013
  contract_class: {
2773
3014
  sierra_program: decompressProgram(contract.sierra_program),
2774
3015
  contract_class_version: contract.contract_class_version,
@@ -2790,7 +3031,7 @@ var RpcProvider = class {
2790
3031
  constructor_calldata: CallData.toHex(constructorCalldata || []),
2791
3032
  class_hash: toHex(classHash),
2792
3033
  contract_address_salt: toHex(addressSalt || 0),
2793
- type: rpc_exports.TransactionType.DEPLOY_ACCOUNT,
3034
+ type: rpc_exports.ETransactionType.DEPLOY_ACCOUNT,
2794
3035
  max_fee: toHex(details.maxFee || 0),
2795
3036
  version: toHex(details.version || 0),
2796
3037
  signature: signatureToHexArray(signature),
@@ -2798,20 +3039,6 @@ var RpcProvider = class {
2798
3039
  }
2799
3040
  });
2800
3041
  }
2801
- async invokeFunction(functionInvocation, details) {
2802
- return this.fetchEndpoint("starknet_addInvokeTransaction", {
2803
- invoke_transaction: {
2804
- sender_address: functionInvocation.contractAddress,
2805
- calldata: CallData.toHex(functionInvocation.calldata),
2806
- type: rpc_exports.TransactionType.INVOKE,
2807
- max_fee: toHex(details.maxFee || 0),
2808
- version: "0x1",
2809
- signature: signatureToHexArray(functionInvocation.signature),
2810
- nonce: toHex(details.nonce)
2811
- }
2812
- });
2813
- }
2814
- // Methods from Interface
2815
3042
  async callContract(call, blockIdentifier = this.blockIdentifier) {
2816
3043
  const block_id = new Block(blockIdentifier).identifier;
2817
3044
  const result = await this.fetchEndpoint("starknet_call", {
@@ -2824,117 +3051,47 @@ var RpcProvider = class {
2824
3051
  });
2825
3052
  return this.responseParser.parseCallContractResponse(result);
2826
3053
  }
2827
- async traceTransaction(transactionHash) {
2828
- return this.fetchEndpoint("starknet_traceTransaction", { transaction_hash: transactionHash });
2829
- }
2830
- async traceBlockTransactions(blockHash) {
2831
- return this.fetchEndpoint("starknet_traceBlockTransactions", { block_hash: blockHash });
2832
- }
2833
- async waitForTransaction(txHash, options) {
2834
- let { retries } = this;
2835
- let onchain = false;
2836
- let isErrorState = false;
2837
- let txReceipt = {};
2838
- const retryInterval = options?.retryInterval ?? 5e3;
2839
- const errorStates = options?.errorStates ?? [TransactionExecutionStatus2.REVERTED];
2840
- const successStates = options?.successStates ?? [
2841
- TransactionExecutionStatus2.SUCCEEDED,
2842
- TransactionFinalityStatus2.ACCEPTED_ON_L1,
2843
- TransactionFinalityStatus2.ACCEPTED_ON_L2
2844
- ];
2845
- while (!onchain) {
2846
- await wait(retryInterval);
2847
- try {
2848
- txReceipt = await this.getTransactionReceipt(txHash);
2849
- const executionStatus = pascalToSnake(txReceipt.execution_status);
2850
- const finalityStatus = pascalToSnake(txReceipt.finality_status);
2851
- if (!executionStatus || !finalityStatus) {
2852
- const error = new Error("waiting for transaction status");
2853
- throw error;
2854
- }
2855
- if (successStates.includes(executionStatus) || successStates.includes(finalityStatus)) {
2856
- onchain = true;
2857
- } else if (errorStates.includes(executionStatus) || errorStates.includes(finalityStatus)) {
2858
- const message = `${executionStatus}: ${finalityStatus}: ${txReceipt.revert_reason}`;
2859
- const error = new Error(message);
2860
- error.response = txReceipt;
2861
- isErrorState = true;
2862
- throw error;
2863
- }
2864
- } catch (error) {
2865
- if (error instanceof Error && isErrorState) {
2866
- throw error;
2867
- }
2868
- if (retries === 0) {
2869
- throw new Error(`waitForTransaction timed-out with retries ${this.retries}`);
2870
- }
2871
- }
2872
- retries -= 1;
2873
- }
2874
- await wait(retryInterval);
2875
- return txReceipt;
2876
- }
2877
3054
  /**
2878
- * Gets the transaction count from a block.
2879
- *
2880
- *
2881
- * @param blockIdentifier
2882
- * @returns Number of transactions
3055
+ * NEW: Estimate the fee for a message from L1
3056
+ * @param message Message From L1
2883
3057
  */
2884
- async getTransactionCount(blockIdentifier = this.blockIdentifier) {
3058
+ async estimateMessageFee(message, blockIdentifier = this.blockIdentifier) {
3059
+ const { from_address, to_address, entry_point_selector, payload } = message;
3060
+ const formattedMessage = {
3061
+ from_address: toHex(from_address),
3062
+ to_address: toHex(to_address),
3063
+ entry_point_selector: getSelector(entry_point_selector),
3064
+ payload: getHexStringArray(payload)
3065
+ };
2885
3066
  const block_id = new Block(blockIdentifier).identifier;
2886
- return this.fetchEndpoint("starknet_getBlockTransactionCount", { block_id });
2887
- }
2888
- /**
2889
- * Gets the latest block number
2890
- *
2891
- *
2892
- * @returns Number of the latest block
2893
- */
2894
- async getBlockNumber() {
2895
- return this.fetchEndpoint("starknet_blockNumber");
3067
+ return this.fetchEndpoint("starknet_estimateMessageFee", {
3068
+ message: formattedMessage,
3069
+ block_id
3070
+ });
2896
3071
  }
2897
3072
  /**
2898
- * Gets syncing status of the node
2899
- *
2900
- *
3073
+ * Returns an object about the sync status, or false if the node is not synching
2901
3074
  * @returns Object with the stats data
2902
3075
  */
2903
3076
  async getSyncingStats() {
2904
3077
  return this.fetchEndpoint("starknet_syncing");
2905
3078
  }
2906
3079
  /**
2907
- * Gets all the events filtered
2908
- *
2909
- *
3080
+ * Returns all events matching the given filter
2910
3081
  * @returns events and the pagination of the events
2911
3082
  */
2912
3083
  async getEvents(eventFilter) {
2913
3084
  return this.fetchEndpoint("starknet_getEvents", { filter: eventFilter });
2914
3085
  }
2915
- async getSimulateTransaction(invocations, {
2916
- blockIdentifier = this.blockIdentifier,
2917
- skipValidate = false,
2918
- skipExecute = false,
2919
- // @deprecated
2920
- skipFeeCharge = true
2921
- // Pathfinder currently does not support `starknet_simulateTransactions` without `SKIP_FEE_CHARGE` simulation flag being set. This will become supported in a future release
2922
- }) {
2923
- const block_id = new Block(blockIdentifier).identifier;
2924
- const simulationFlags = [];
2925
- if (skipValidate)
2926
- simulationFlags.push(SimulationFlag.SKIP_VALIDATE);
2927
- if (skipExecute || skipFeeCharge)
2928
- simulationFlags.push(SimulationFlag.SKIP_FEE_CHARGE);
2929
- return this.fetchEndpoint("starknet_simulateTransactions", {
2930
- block_id,
2931
- transactions: invocations.map((it) => this.buildTransaction(it)),
2932
- simulation_flags: simulationFlags
2933
- }).then(this.responseParser.parseSimulateTransactionResponse);
2934
- }
3086
+ /**
3087
+ * StarknetId Endpoint (get name from address)
3088
+ */
2935
3089
  async getStarkName(address, StarknetIdContract2) {
2936
3090
  return getStarkName(this, address, StarknetIdContract2);
2937
3091
  }
3092
+ /**
3093
+ * StarknetId Endpoint (get address from name)
3094
+ */
2938
3095
  async getAddressFromStarkName(name, StarknetIdContract2) {
2939
3096
  return getAddressFromStarkName(this, name, StarknetIdContract2);
2940
3097
  }
@@ -2947,12 +3104,11 @@ var RpcProvider = class {
2947
3104
  };
2948
3105
  if (invocation.type === "INVOKE_FUNCTION" /* INVOKE */) {
2949
3106
  return {
2950
- type: rpc_exports.TransactionType.INVOKE,
3107
+ type: rpc_exports.ETransactionType.INVOKE,
2951
3108
  // Diff between sequencer and rpc invoke type
2952
3109
  sender_address: invocation.contractAddress,
2953
3110
  calldata: CallData.toHex(invocation.calldata),
2954
3111
  version: toHex(invocation.version || defaultVersions.v1),
2955
- // HEX_STR_TRANSACTION_VERSION_1, // as any HOTFIX TODO: Resolve spec version
2956
3112
  ...details
2957
3113
  };
2958
3114
  }
@@ -2963,7 +3119,6 @@ var RpcProvider = class {
2963
3119
  contract_class: invocation.contract,
2964
3120
  sender_address: invocation.senderAddress,
2965
3121
  version: toHex(invocation.version || defaultVersions.v1),
2966
- // HEX_STR_TRANSACTION_VERSION_1, // as any HOTFIX TODO: Resolve spec version
2967
3122
  ...details
2968
3123
  };
2969
3124
  }
@@ -2977,7 +3132,6 @@ var RpcProvider = class {
2977
3132
  compiled_class_hash: invocation.compiledClassHash || "",
2978
3133
  sender_address: invocation.senderAddress,
2979
3134
  version: toHex(invocation.version || defaultVersions.v2),
2980
- // HEX_STR_TRANSACTION_VERSION_2, // as any HOTFIX TODO: Resolve spec version
2981
3135
  ...details
2982
3136
  };
2983
3137
  }
@@ -3661,7 +3815,7 @@ var Provider = class {
3661
3815
  } else if (providerOrOptions && "sequencer" in providerOrOptions) {
3662
3816
  this.provider = new SequencerProvider(providerOrOptions.sequencer);
3663
3817
  } else {
3664
- this.provider = new SequencerProvider();
3818
+ this.provider = new RpcProvider();
3665
3819
  }
3666
3820
  }
3667
3821
  async getChainId() {
@@ -4111,7 +4265,7 @@ var Signer = class {
4111
4265
  // src/utils/events.ts
4112
4266
  function parseUDCEvent(txReceipt) {
4113
4267
  if (!txReceipt.events) {
4114
- throw new Error("UDC emited event is empty");
4268
+ throw new Error("UDC emitted event is empty");
4115
4269
  }
4116
4270
  const event = txReceipt.events.find(
4117
4271
  (it) => cleanHex(it.from_address) === cleanHex(UDC.ADDRESS)
@@ -4650,7 +4804,7 @@ var ProviderInterface = class {
4650
4804
  };
4651
4805
 
4652
4806
  // src/provider/index.ts
4653
- var defaultProvider = new Provider();
4807
+ var defaultProvider = new Provider({ rpc: { default: true } });
4654
4808
 
4655
4809
  // src/account/interface.ts
4656
4810
  var AccountInterface = class extends ProviderInterface {
@@ -5107,6 +5261,7 @@ export {
5107
5261
  fixStack,
5108
5262
  getCalldata,
5109
5263
  getChecksumAddress,
5264
+ getDefaultNodeUrl,
5110
5265
  hash_exports as hash,
5111
5266
  isSierra,
5112
5267
  isUrl,