starknet 5.22.0 → 5.23.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,127 @@ 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
2638
  this.getChainId();
2561
2639
  }
2562
- fetch(method, params) {
2563
- const body = stringify2({ method, jsonrpc: "2.0", params, id: 0 });
2640
+ fetch(method, params, id = 0) {
2641
+ const rpcRequestBody = {
2642
+ id,
2643
+ jsonrpc: "2.0",
2644
+ method,
2645
+ ...params && { params }
2646
+ };
2564
2647
  return fetchPonyfill_default(this.nodeUrl, {
2565
2648
  method: "POST",
2566
- body,
2649
+ body: stringify2(rpcRequestBody),
2567
2650
  headers: this.headers
2568
2651
  });
2569
2652
  }
2570
- errorHandler(error) {
2571
- if (error) {
2572
- const { code, message } = error;
2573
- throw new LibraryError(`${code}: ${message}`);
2653
+ errorHandler(method, params, rpcError, otherError) {
2654
+ if (rpcError) {
2655
+ const { code, message, data } = rpcError;
2656
+ throw new LibraryError(
2657
+ `RPC: ${method} with params ${JSON.stringify(params)}
2658
+ ${code}: ${message}: ${data}`
2659
+ );
2660
+ }
2661
+ if (otherError instanceof LibraryError) {
2662
+ throw otherError;
2663
+ }
2664
+ if (otherError) {
2665
+ throw Error(otherError.message);
2574
2666
  }
2575
2667
  }
2576
2668
  async fetchEndpoint(method, params) {
2577
2669
  try {
2578
2670
  const rawResult = await this.fetch(method, params);
2579
2671
  const { error, result } = await rawResult.json();
2580
- this.errorHandler(error);
2672
+ this.errorHandler(method, params, error);
2581
2673
  return result;
2582
2674
  } catch (error) {
2583
- this.errorHandler(error?.response?.data);
2675
+ this.errorHandler(method, params, error?.response?.data, error);
2584
2676
  throw error;
2585
2677
  }
2586
2678
  }
2587
- // Methods from Interface
2588
2679
  async getChainId() {
2589
2680
  this.chainId ?? (this.chainId = await this.fetchEndpoint("starknet_chainId"));
2590
2681
  return this.chainId;
2591
2682
  }
2683
+ /**
2684
+ * NEW: Returns the version of the Starknet JSON-RPC specification being used
2685
+ */
2686
+ async getSpecVersion() {
2687
+ return this.fetchEndpoint("starknet_specVersion");
2688
+ }
2689
+ async getNonceForAddress(contractAddress, blockIdentifier = this.blockIdentifier) {
2690
+ const contract_address = toHex(contractAddress);
2691
+ const block_id = new Block(blockIdentifier).identifier;
2692
+ return this.fetchEndpoint("starknet_getNonce", {
2693
+ contract_address,
2694
+ block_id
2695
+ });
2696
+ }
2697
+ /**
2698
+ * @deprecated use getBlockWithTxHashes or getBlockWithTxs (will be removed on sequencer deprecation)
2699
+ */
2592
2700
  async getBlock(blockIdentifier = this.blockIdentifier) {
2593
2701
  return this.getBlockWithTxHashes(blockIdentifier).then(
2594
2702
  this.responseParser.parseGetBlockResponse
2595
2703
  );
2596
2704
  }
2597
- async getBlockHashAndNumber() {
2705
+ /**
2706
+ * Get the most recent accepted block hash and number
2707
+ */
2708
+ async getBlockLatestAccepted() {
2598
2709
  return this.fetchEndpoint("starknet_blockHashAndNumber");
2599
2710
  }
2711
+ /**
2712
+ * @deprecated redundant use getBlockLatestAccepted();
2713
+ * Get the most recent accepted block number
2714
+ * @returns Number of the latest block
2715
+ */
2716
+ async getBlockNumber() {
2717
+ return this.fetchEndpoint("starknet_blockNumber");
2718
+ }
2600
2719
  async getBlockWithTxHashes(blockIdentifier = this.blockIdentifier) {
2601
2720
  const block_id = new Block(blockIdentifier).identifier;
2602
2721
  return this.fetchEndpoint("starknet_getBlockWithTxHashes", { block_id });
@@ -2605,68 +2724,176 @@ var RpcProvider = class {
2605
2724
  const block_id = new Block(blockIdentifier).identifier;
2606
2725
  return this.fetchEndpoint("starknet_getBlockWithTxs", { block_id });
2607
2726
  }
2608
- async getClassHashAt(contractAddress, blockIdentifier = this.blockIdentifier) {
2727
+ async getBlockStateUpdate(blockIdentifier = this.blockIdentifier) {
2609
2728
  const block_id = new Block(blockIdentifier).identifier;
2610
- return this.fetchEndpoint("starknet_getClassHashAt", {
2611
- block_id,
2612
- contract_address: contractAddress
2613
- });
2729
+ return this.fetchEndpoint("starknet_getStateUpdate", { block_id });
2614
2730
  }
2615
- async getNonceForAddress(contractAddress, blockIdentifier = this.blockIdentifier) {
2731
+ async getBlockTransactionsTraces(blockIdentifier = this.blockIdentifier) {
2616
2732
  const block_id = new Block(blockIdentifier).identifier;
2617
- return this.fetchEndpoint("starknet_getNonce", {
2618
- contract_address: contractAddress,
2619
- block_id
2620
- });
2733
+ return this.fetchEndpoint("starknet_traceBlockTransactions", { block_id });
2621
2734
  }
2735
+ async getBlockTransactionCount(blockIdentifier = this.blockIdentifier) {
2736
+ const block_id = new Block(blockIdentifier).identifier;
2737
+ return this.fetchEndpoint("starknet_getBlockTransactionCount", { block_id });
2738
+ }
2739
+ /**
2740
+ * Return transactions from pending block
2741
+ * @deprecated Instead use getBlock(BlockTag.pending); (will be removed in next minor version)
2742
+ */
2622
2743
  async getPendingTransactions() {
2623
- return this.fetchEndpoint("starknet_pendingTransactions");
2744
+ const { transactions } = await this.getBlock("pending" /* pending */);
2745
+ return Promise.all(transactions.map((it) => this.getTransactionByHash(it)));
2624
2746
  }
2625
- async getProtocolVersion() {
2626
- throw new Error("Pathfinder does not implement this rpc 0.1.0 method");
2747
+ /**
2748
+ * @deprecated use getTransactionByHash or getTransactionByBlockIdAndIndex (will be removed on sequencer deprecation)
2749
+ */
2750
+ async getTransaction(txHash) {
2751
+ return this.getTransactionByHash(txHash).then(this.responseParser.parseGetTransactionResponse);
2627
2752
  }
2628
- async getStateUpdate(blockIdentifier = this.blockIdentifier) {
2753
+ async getTransactionByHash(txHash) {
2754
+ const transaction_hash = toHex(txHash);
2755
+ return this.fetchEndpoint("starknet_getTransactionByHash", {
2756
+ transaction_hash
2757
+ });
2758
+ }
2759
+ async getTransactionByBlockIdAndIndex(blockIdentifier, index) {
2629
2760
  const block_id = new Block(blockIdentifier).identifier;
2630
- return this.fetchEndpoint("starknet_getStateUpdate", { block_id });
2761
+ return this.fetchEndpoint("starknet_getTransactionByBlockIdAndIndex", { block_id, index });
2762
+ }
2763
+ async getTransactionReceipt(txHash) {
2764
+ const transaction_hash = toHex(txHash);
2765
+ return this.fetchEndpoint("starknet_getTransactionReceipt", { transaction_hash });
2766
+ }
2767
+ async getTransactionTrace(txHash) {
2768
+ const transaction_hash = toHex(txHash);
2769
+ return this.fetchEndpoint("starknet_traceTransaction", { transaction_hash });
2770
+ }
2771
+ // TODO: implement in waitforTransaction, add add tests, when RPC 0.5 become standard /
2772
+ /**
2773
+ * NEW: Get the status of a transaction
2774
+ */
2775
+ async getTransactionStatus(transactionHash) {
2776
+ const transaction_hash = toHex(transactionHash);
2777
+ return this.fetchEndpoint("starknet_getTransactionStatus", { transaction_hash });
2778
+ }
2779
+ /**
2780
+ * @param invocations AccountInvocations
2781
+ * @param simulateTransactionOptions blockIdentifier and flags to skip validation and fee charge<br/>
2782
+ * - blockIdentifier<br/>
2783
+ * - skipValidate (default false)<br/>
2784
+ * - skipFeeCharge (default true)<br/>
2785
+ */
2786
+ async simulateTransaction(invocations, {
2787
+ blockIdentifier = this.blockIdentifier,
2788
+ skipValidate = false,
2789
+ skipFeeCharge = true
2790
+ }) {
2791
+ const block_id = new Block(blockIdentifier).identifier;
2792
+ const simulationFlags = [];
2793
+ if (skipValidate)
2794
+ simulationFlags.push(rpc_exports.ESimulationFlag.SKIP_VALIDATE);
2795
+ if (skipFeeCharge)
2796
+ simulationFlags.push(rpc_exports.ESimulationFlag.SKIP_FEE_CHARGE);
2797
+ return this.fetchEndpoint("starknet_simulateTransactions", {
2798
+ block_id,
2799
+ transactions: invocations.map((it) => this.buildTransaction(it)),
2800
+ simulation_flags: simulationFlags
2801
+ }).then(this.responseParser.parseSimulateTransactionResponse);
2802
+ }
2803
+ async waitForTransaction(txHash, options) {
2804
+ const transactionHash = toHex(txHash);
2805
+ let { retries } = this;
2806
+ let onchain = false;
2807
+ let isErrorState = false;
2808
+ const retryInterval = options?.retryInterval ?? 5e3;
2809
+ const errorStates = options?.errorStates ?? [
2810
+ rpc_exports.ETransactionStatus.REJECTED,
2811
+ rpc_exports.ETransactionExecutionStatus.REVERTED
2812
+ ];
2813
+ const successStates = options?.successStates ?? [
2814
+ rpc_exports.ETransactionExecutionStatus.SUCCEEDED,
2815
+ rpc_exports.ETransactionStatus.ACCEPTED_ON_L2,
2816
+ rpc_exports.ETransactionStatus.ACCEPTED_ON_L1
2817
+ ];
2818
+ let txStatus;
2819
+ while (!onchain) {
2820
+ await wait(retryInterval);
2821
+ try {
2822
+ txStatus = await this.getTransactionStatus(transactionHash);
2823
+ const executionStatus = txStatus.execution_status;
2824
+ const finalityStatus = txStatus.finality_status;
2825
+ if (!finalityStatus) {
2826
+ const error = new Error("waiting for transaction status");
2827
+ throw error;
2828
+ }
2829
+ if (successStates.includes(executionStatus) || successStates.includes(finalityStatus)) {
2830
+ onchain = true;
2831
+ } else if (errorStates.includes(executionStatus) || errorStates.includes(finalityStatus)) {
2832
+ const message = `${executionStatus}: ${finalityStatus}`;
2833
+ const error = new Error(message);
2834
+ error.response = txStatus;
2835
+ isErrorState = true;
2836
+ throw error;
2837
+ }
2838
+ } catch (error) {
2839
+ if (error instanceof Error && isErrorState) {
2840
+ throw error;
2841
+ }
2842
+ if (retries <= 0) {
2843
+ throw new Error(`waitForTransaction timed-out with retries ${this.retries}`);
2844
+ }
2845
+ }
2846
+ retries -= 1;
2847
+ }
2848
+ let txReceipt = null;
2849
+ while (txReceipt === null) {
2850
+ try {
2851
+ txReceipt = await this.getTransactionReceipt(transactionHash);
2852
+ } catch (error) {
2853
+ if (retries <= 0) {
2854
+ throw new Error(`waitForTransaction timed-out with retries ${this.retries}`);
2855
+ }
2856
+ }
2857
+ retries -= 1;
2858
+ await wait(retryInterval);
2859
+ }
2860
+ return txReceipt;
2631
2861
  }
2632
2862
  async getStorageAt(contractAddress, key, blockIdentifier = this.blockIdentifier) {
2863
+ const contract_address = toHex(contractAddress);
2633
2864
  const parsedKey = toStorageKey(key);
2634
2865
  const block_id = new Block(blockIdentifier).identifier;
2635
2866
  return this.fetchEndpoint("starknet_getStorageAt", {
2636
- contract_address: contractAddress,
2867
+ contract_address,
2637
2868
  key: parsedKey,
2638
2869
  block_id
2639
2870
  });
2640
2871
  }
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) {
2872
+ async getClassHashAt(contractAddress, blockIdentifier = this.blockIdentifier) {
2873
+ const contract_address = toHex(contractAddress);
2649
2874
  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 });
2875
+ return this.fetchEndpoint("starknet_getClassHashAt", {
2876
+ block_id,
2877
+ contract_address
2878
+ });
2654
2879
  }
2655
2880
  async getClassByHash(classHash) {
2656
2881
  return this.getClass(classHash);
2657
2882
  }
2658
2883
  async getClass(classHash, blockIdentifier = this.blockIdentifier) {
2884
+ const class_hash = toHex(classHash);
2659
2885
  const block_id = new Block(blockIdentifier).identifier;
2660
2886
  return this.fetchEndpoint("starknet_getClass", {
2661
- class_hash: classHash,
2887
+ class_hash,
2662
2888
  block_id
2663
2889
  }).then(this.responseParser.parseContractClassResponse);
2664
2890
  }
2665
2891
  async getClassAt(contractAddress, blockIdentifier = this.blockIdentifier) {
2892
+ const contract_address = toHex(contractAddress);
2666
2893
  const block_id = new Block(blockIdentifier).identifier;
2667
2894
  return this.fetchEndpoint("starknet_getClassAt", {
2668
2895
  block_id,
2669
- contract_address: contractAddress
2896
+ contract_address
2670
2897
  }).then(this.responseParser.parseContractClassResponse);
2671
2898
  }
2672
2899
  async getCode(_contractAddress, _blockIdentifier) {
@@ -2690,6 +2917,9 @@ var RpcProvider = class {
2690
2917
  }
2691
2918
  return { cairo: "0", compiler: "0" };
2692
2919
  }
2920
+ /**
2921
+ * @deprecated use get*type*EstimateFee (will be refactored based on type after sequencer deprecation)
2922
+ */
2693
2923
  async getEstimateFee(invocation, invocationDetails, blockIdentifier = this.blockIdentifier) {
2694
2924
  return this.getInvokeEstimateFee(invocation, invocationDetails, blockIdentifier);
2695
2925
  }
@@ -2748,11 +2978,24 @@ var RpcProvider = class {
2748
2978
  block_id
2749
2979
  }).then(this.responseParser.parseFeeEstimateBulkResponse);
2750
2980
  }
2981
+ async invokeFunction(functionInvocation, details) {
2982
+ return this.fetchEndpoint("starknet_addInvokeTransaction", {
2983
+ invoke_transaction: {
2984
+ sender_address: functionInvocation.contractAddress,
2985
+ calldata: CallData.toHex(functionInvocation.calldata),
2986
+ type: rpc_exports.ETransactionType.INVOKE,
2987
+ max_fee: toHex(details.maxFee || 0),
2988
+ version: "0x1",
2989
+ signature: signatureToHexArray(functionInvocation.signature),
2990
+ nonce: toHex(details.nonce)
2991
+ }
2992
+ });
2993
+ }
2751
2994
  async declareContract({ contract, signature, senderAddress, compiledClassHash }, details) {
2752
2995
  if (!isSierra(contract)) {
2753
2996
  return this.fetchEndpoint("starknet_addDeclareTransaction", {
2754
2997
  declare_transaction: {
2755
- type: rpc_exports.TransactionType.DECLARE,
2998
+ type: rpc_exports.ETransactionType.DECLARE,
2756
2999
  contract_class: {
2757
3000
  program: contract.program,
2758
3001
  entry_points_by_type: contract.entry_points_by_type,
@@ -2768,7 +3011,7 @@ var RpcProvider = class {
2768
3011
  }
2769
3012
  return this.fetchEndpoint("starknet_addDeclareTransaction", {
2770
3013
  declare_transaction: {
2771
- type: rpc_exports.TransactionType.DECLARE,
3014
+ type: rpc_exports.ETransactionType.DECLARE,
2772
3015
  contract_class: {
2773
3016
  sierra_program: decompressProgram(contract.sierra_program),
2774
3017
  contract_class_version: contract.contract_class_version,
@@ -2790,7 +3033,7 @@ var RpcProvider = class {
2790
3033
  constructor_calldata: CallData.toHex(constructorCalldata || []),
2791
3034
  class_hash: toHex(classHash),
2792
3035
  contract_address_salt: toHex(addressSalt || 0),
2793
- type: rpc_exports.TransactionType.DEPLOY_ACCOUNT,
3036
+ type: rpc_exports.ETransactionType.DEPLOY_ACCOUNT,
2794
3037
  max_fee: toHex(details.maxFee || 0),
2795
3038
  version: toHex(details.version || 0),
2796
3039
  signature: signatureToHexArray(signature),
@@ -2798,20 +3041,6 @@ var RpcProvider = class {
2798
3041
  }
2799
3042
  });
2800
3043
  }
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
3044
  async callContract(call, blockIdentifier = this.blockIdentifier) {
2816
3045
  const block_id = new Block(blockIdentifier).identifier;
2817
3046
  const result = await this.fetchEndpoint("starknet_call", {
@@ -2824,117 +3053,47 @@ var RpcProvider = class {
2824
3053
  });
2825
3054
  return this.responseParser.parseCallContractResponse(result);
2826
3055
  }
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
3056
  /**
2878
- * Gets the transaction count from a block.
2879
- *
2880
- *
2881
- * @param blockIdentifier
2882
- * @returns Number of transactions
3057
+ * NEW: Estimate the fee for a message from L1
3058
+ * @param message Message From L1
2883
3059
  */
2884
- async getTransactionCount(blockIdentifier = this.blockIdentifier) {
3060
+ async estimateMessageFee(message, blockIdentifier = this.blockIdentifier) {
3061
+ const { from_address, to_address, entry_point_selector, payload } = message;
3062
+ const formattedMessage = {
3063
+ from_address: toHex(from_address),
3064
+ to_address: toHex(to_address),
3065
+ entry_point_selector: getSelector(entry_point_selector),
3066
+ payload: getHexStringArray(payload)
3067
+ };
2885
3068
  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");
3069
+ return this.fetchEndpoint("starknet_estimateMessageFee", {
3070
+ message: formattedMessage,
3071
+ block_id
3072
+ });
2896
3073
  }
2897
3074
  /**
2898
- * Gets syncing status of the node
2899
- *
2900
- *
3075
+ * Returns an object about the sync status, or false if the node is not synching
2901
3076
  * @returns Object with the stats data
2902
3077
  */
2903
3078
  async getSyncingStats() {
2904
3079
  return this.fetchEndpoint("starknet_syncing");
2905
3080
  }
2906
3081
  /**
2907
- * Gets all the events filtered
2908
- *
2909
- *
3082
+ * Returns all events matching the given filter
2910
3083
  * @returns events and the pagination of the events
2911
3084
  */
2912
3085
  async getEvents(eventFilter) {
2913
3086
  return this.fetchEndpoint("starknet_getEvents", { filter: eventFilter });
2914
3087
  }
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
- }
3088
+ /**
3089
+ * StarknetId Endpoint (get name from address)
3090
+ */
2935
3091
  async getStarkName(address, StarknetIdContract2) {
2936
3092
  return getStarkName(this, address, StarknetIdContract2);
2937
3093
  }
3094
+ /**
3095
+ * StarknetId Endpoint (get address from name)
3096
+ */
2938
3097
  async getAddressFromStarkName(name, StarknetIdContract2) {
2939
3098
  return getAddressFromStarkName(this, name, StarknetIdContract2);
2940
3099
  }
@@ -2947,12 +3106,11 @@ var RpcProvider = class {
2947
3106
  };
2948
3107
  if (invocation.type === "INVOKE_FUNCTION" /* INVOKE */) {
2949
3108
  return {
2950
- type: rpc_exports.TransactionType.INVOKE,
3109
+ type: rpc_exports.ETransactionType.INVOKE,
2951
3110
  // Diff between sequencer and rpc invoke type
2952
3111
  sender_address: invocation.contractAddress,
2953
3112
  calldata: CallData.toHex(invocation.calldata),
2954
3113
  version: toHex(invocation.version || defaultVersions.v1),
2955
- // HEX_STR_TRANSACTION_VERSION_1, // as any HOTFIX TODO: Resolve spec version
2956
3114
  ...details
2957
3115
  };
2958
3116
  }
@@ -2963,7 +3121,6 @@ var RpcProvider = class {
2963
3121
  contract_class: invocation.contract,
2964
3122
  sender_address: invocation.senderAddress,
2965
3123
  version: toHex(invocation.version || defaultVersions.v1),
2966
- // HEX_STR_TRANSACTION_VERSION_1, // as any HOTFIX TODO: Resolve spec version
2967
3124
  ...details
2968
3125
  };
2969
3126
  }
@@ -2977,7 +3134,6 @@ var RpcProvider = class {
2977
3134
  compiled_class_hash: invocation.compiledClassHash || "",
2978
3135
  sender_address: invocation.senderAddress,
2979
3136
  version: toHex(invocation.version || defaultVersions.v2),
2980
- // HEX_STR_TRANSACTION_VERSION_2, // as any HOTFIX TODO: Resolve spec version
2981
3137
  ...details
2982
3138
  };
2983
3139
  }
@@ -3661,7 +3817,7 @@ var Provider = class {
3661
3817
  } else if (providerOrOptions && "sequencer" in providerOrOptions) {
3662
3818
  this.provider = new SequencerProvider(providerOrOptions.sequencer);
3663
3819
  } else {
3664
- this.provider = new SequencerProvider();
3820
+ this.provider = new RpcProvider();
3665
3821
  }
3666
3822
  }
3667
3823
  async getChainId() {
@@ -4111,7 +4267,7 @@ var Signer = class {
4111
4267
  // src/utils/events.ts
4112
4268
  function parseUDCEvent(txReceipt) {
4113
4269
  if (!txReceipt.events) {
4114
- throw new Error("UDC emited event is empty");
4270
+ throw new Error("UDC emitted event is empty");
4115
4271
  }
4116
4272
  const event = txReceipt.events.find(
4117
4273
  (it) => cleanHex(it.from_address) === cleanHex(UDC.ADDRESS)
@@ -4650,7 +4806,7 @@ var ProviderInterface = class {
4650
4806
  };
4651
4807
 
4652
4808
  // src/provider/index.ts
4653
- var defaultProvider = new Provider();
4809
+ var defaultProvider = new Provider({ rpc: { default: true } });
4654
4810
 
4655
4811
  // src/account/interface.ts
4656
4812
  var AccountInterface = class extends ProviderInterface {
@@ -5107,6 +5263,7 @@ export {
5107
5263
  fixStack,
5108
5264
  getCalldata,
5109
5265
  getChecksumAddress,
5266
+ getDefaultNodeUrl,
5110
5267
  hash_exports as hash,
5111
5268
  isSierra,
5112
5269
  isUrl,