@solana/web3.js 1.45.0 → 1.47.1

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/src/connection.ts CHANGED
@@ -26,7 +26,7 @@ import RpcClient from 'jayson/lib/client/browser';
26
26
 
27
27
  import {AgentManager} from './agent-manager';
28
28
  import {EpochSchedule} from './epoch-schedule';
29
- import {SendTransactionError} from './errors';
29
+ import {SendTransactionError, SolanaJSONRPCError} from './errors';
30
30
  import fetchImpl, {Response} from './fetch-impl';
31
31
  import {NonceAccount} from './nonce-account';
32
32
  import {PublicKey} from './publickey';
@@ -228,6 +228,8 @@ export type SendOptions = {
228
228
  preflightCommitment?: Commitment;
229
229
  /** Maximum number of times for the RPC node to retry sending the transaction to the leader. */
230
230
  maxRetries?: number;
231
+ /** The minimum slot that the request can be evaluated at */
232
+ minContextSlot?: number;
231
233
  };
232
234
 
233
235
  /**
@@ -242,6 +244,8 @@ export type ConfirmOptions = {
242
244
  preflightCommitment?: Commitment;
243
245
  /** Maximum number of times for the RPC node to retry sending the transaction to the leader. */
244
246
  maxRetries?: number;
247
+ /** The minimum slot that the request can be evaluated at */
248
+ minContextSlot?: number;
245
249
  };
246
250
 
247
251
  /**
@@ -272,6 +276,8 @@ export type SignaturesForAddressOptions = {
272
276
  until?: TransactionSignature;
273
277
  /** Maximum transaction signatures to return (between 1 and 1,000, default: 1,000). */
274
278
  limit?: number;
279
+ /** The minimum slot that the request can be evaluated at */
280
+ minContextSlot?: number;
275
281
  };
276
282
 
277
283
  /**
@@ -297,6 +303,23 @@ export type BlockheightBasedTransactionConfirmationStrategy = {
297
303
  signature: TransactionSignature;
298
304
  } & BlockhashWithExpiryBlockHeight;
299
305
 
306
+ /** @internal */
307
+ function extractCommitmentFromConfig<TConfig>(
308
+ commitmentOrConfig?: Commitment | ({commitment?: Commitment} & TConfig),
309
+ ) {
310
+ let commitment: Commitment | undefined;
311
+ let config: Omit<TConfig, 'commitment'> | undefined;
312
+ if (typeof commitmentOrConfig === 'string') {
313
+ commitment = commitmentOrConfig;
314
+ } else if (commitmentOrConfig) {
315
+ const {commitment: specifiedCommitment, ...specifiedConfig} =
316
+ commitmentOrConfig;
317
+ commitment = specifiedCommitment;
318
+ config = specifiedConfig;
319
+ }
320
+ return {commitment, config};
321
+ }
322
+
300
323
  /**
301
324
  * @internal
302
325
  */
@@ -399,6 +422,88 @@ export type Finality = 'confirmed' | 'finalized';
399
422
  */
400
423
  export type LargestAccountsFilter = 'circulating' | 'nonCirculating';
401
424
 
425
+ /**
426
+ * Configuration object for changing `getAccountInfo` query behavior
427
+ */
428
+ export type GetAccountInfoConfig = {
429
+ /** The level of commitment desired */
430
+ commitment?: Commitment;
431
+ /** The minimum slot that the request can be evaluated at */
432
+ minContextSlot?: number;
433
+ };
434
+
435
+ /**
436
+ * Configuration object for changing `getBalance` query behavior
437
+ */
438
+ export type GetBalanceConfig = {
439
+ /** The level of commitment desired */
440
+ commitment?: Commitment;
441
+ /** The minimum slot that the request can be evaluated at */
442
+ minContextSlot?: number;
443
+ };
444
+
445
+ /**
446
+ * Configuration object for changing `getBlockHeight` query behavior
447
+ */
448
+ export type GetBlockHeightConfig = {
449
+ /** The level of commitment desired */
450
+ commitment?: Commitment;
451
+ /** The minimum slot that the request can be evaluated at */
452
+ minContextSlot?: number;
453
+ };
454
+
455
+ /**
456
+ * Configuration object for changing `getEpochInfo` query behavior
457
+ */
458
+ export type GetEpochInfoConfig = {
459
+ /** The level of commitment desired */
460
+ commitment?: Commitment;
461
+ /** The minimum slot that the request can be evaluated at */
462
+ minContextSlot?: number;
463
+ };
464
+
465
+ /**
466
+ * Configuration object for changing `getInflationReward` query behavior
467
+ */
468
+ export type GetInflationRewardConfig = {
469
+ /** The level of commitment desired */
470
+ commitment?: Commitment;
471
+ /** An epoch for which the reward occurs. If omitted, the previous epoch will be used */
472
+ epoch?: number;
473
+ /** The minimum slot that the request can be evaluated at */
474
+ minContextSlot?: number;
475
+ };
476
+
477
+ /**
478
+ * Configuration object for changing `getLatestBlockhash` query behavior
479
+ */
480
+ export type GetLatestBlockhashConfig = {
481
+ /** The level of commitment desired */
482
+ commitment?: Commitment;
483
+ /** The minimum slot that the request can be evaluated at */
484
+ minContextSlot?: number;
485
+ };
486
+
487
+ /**
488
+ * Configuration object for changing `getSlot` query behavior
489
+ */
490
+ export type GetSlotConfig = {
491
+ /** The level of commitment desired */
492
+ commitment?: Commitment;
493
+ /** The minimum slot that the request can be evaluated at */
494
+ minContextSlot?: number;
495
+ };
496
+
497
+ /**
498
+ * Configuration object for changing `getSlotLeader` query behavior
499
+ */
500
+ export type GetSlotLeaderConfig = {
501
+ /** The level of commitment desired */
502
+ commitment?: Commitment;
503
+ /** The minimum slot that the request can be evaluated at */
504
+ minContextSlot?: number;
505
+ };
506
+
402
507
  /**
403
508
  * Configuration object for changing `getLargestAccounts` query behavior
404
509
  */
@@ -1949,6 +2054,8 @@ export type GetProgramAccountsConfig = {
1949
2054
  dataSlice?: DataSlice;
1950
2055
  /** Optional array of filters to apply to accounts */
1951
2056
  filters?: GetProgramAccountsFilter[];
2057
+ /** The minimum slot that the request can be evaluated at */
2058
+ minContextSlot?: number;
1952
2059
  };
1953
2060
 
1954
2061
  /**
@@ -1959,6 +2066,8 @@ export type GetParsedProgramAccountsConfig = {
1959
2066
  commitment?: Commitment;
1960
2067
  /** Optional array of filters to apply to accounts */
1961
2068
  filters?: GetProgramAccountsFilter[];
2069
+ /** The minimum slot that the request can be evaluated at */
2070
+ minContextSlot?: number;
1962
2071
  };
1963
2072
 
1964
2073
  /**
@@ -1967,8 +2076,40 @@ export type GetParsedProgramAccountsConfig = {
1967
2076
  export type GetMultipleAccountsConfig = {
1968
2077
  /** Optional commitment level */
1969
2078
  commitment?: Commitment;
1970
- /** Optional encoding for account data (default base64) */
1971
- encoding?: 'base64' | 'jsonParsed';
2079
+ /** The minimum slot that the request can be evaluated at */
2080
+ minContextSlot?: number;
2081
+ };
2082
+
2083
+ /**
2084
+ * Configuration object for `getStakeActivation`
2085
+ */
2086
+ export type GetStakeActivationConfig = {
2087
+ /** Optional commitment level */
2088
+ commitment?: Commitment;
2089
+ /** Epoch for which to calculate activation details. If parameter not provided, defaults to current epoch */
2090
+ epoch?: number;
2091
+ /** The minimum slot that the request can be evaluated at */
2092
+ minContextSlot?: number;
2093
+ };
2094
+
2095
+ /**
2096
+ * Configuration object for `getStakeActivation`
2097
+ */
2098
+ export type GetTokenAccountsByOwnerConfig = {
2099
+ /** Optional commitment level */
2100
+ commitment?: Commitment;
2101
+ /** The minimum slot that the request can be evaluated at */
2102
+ minContextSlot?: number;
2103
+ };
2104
+
2105
+ /**
2106
+ * Configuration object for `getStakeActivation`
2107
+ */
2108
+ export type GetTransactionCountConfig = {
2109
+ /** Optional commitment level */
2110
+ commitment?: Commitment;
2111
+ /** The minimum slot that the request can be evaluated at */
2112
+ minContextSlot?: number;
1972
2113
  };
1973
2114
 
1974
2115
  /**
@@ -2377,17 +2518,23 @@ export class Connection {
2377
2518
  */
2378
2519
  async getBalanceAndContext(
2379
2520
  publicKey: PublicKey,
2380
- commitment?: Commitment,
2521
+ commitmentOrConfig?: Commitment | GetBalanceConfig,
2381
2522
  ): Promise<RpcResponseAndContext<number>> {
2382
- const args = this._buildArgs([publicKey.toBase58()], commitment);
2523
+ /** @internal */
2524
+ const {commitment, config} =
2525
+ extractCommitmentFromConfig(commitmentOrConfig);
2526
+ const args = this._buildArgs(
2527
+ [publicKey.toBase58()],
2528
+ commitment,
2529
+ undefined /* encoding */,
2530
+ config,
2531
+ );
2383
2532
  const unsafeRes = await this._rpcRequest('getBalance', args);
2384
2533
  const res = create(unsafeRes, jsonRpcResultAndContext(number()));
2385
2534
  if ('error' in res) {
2386
- throw new Error(
2387
- 'failed to get balance for ' +
2388
- publicKey.toBase58() +
2389
- ': ' +
2390
- res.error.message,
2535
+ throw new SolanaJSONRPCError(
2536
+ res.error,
2537
+ `failed to get balance for ${publicKey.toBase58()}`,
2391
2538
  );
2392
2539
  }
2393
2540
  return res.result;
@@ -2398,9 +2545,9 @@ export class Connection {
2398
2545
  */
2399
2546
  async getBalance(
2400
2547
  publicKey: PublicKey,
2401
- commitment?: Commitment,
2548
+ commitmentOrConfig?: Commitment | GetBalanceConfig,
2402
2549
  ): Promise<number> {
2403
- return await this.getBalanceAndContext(publicKey, commitment)
2550
+ return await this.getBalanceAndContext(publicKey, commitmentOrConfig)
2404
2551
  .then(x => x.value)
2405
2552
  .catch(e => {
2406
2553
  throw new Error(
@@ -2416,8 +2563,9 @@ export class Connection {
2416
2563
  const unsafeRes = await this._rpcRequest('getBlockTime', [slot]);
2417
2564
  const res = create(unsafeRes, jsonRpcResult(nullable(number())));
2418
2565
  if ('error' in res) {
2419
- throw new Error(
2420
- 'failed to get block time for slot ' + slot + ': ' + res.error.message,
2566
+ throw new SolanaJSONRPCError(
2567
+ res.error,
2568
+ `failed to get block time for slot ${slot}`,
2421
2569
  );
2422
2570
  }
2423
2571
  return res.result;
@@ -2431,8 +2579,9 @@ export class Connection {
2431
2579
  const unsafeRes = await this._rpcRequest('minimumLedgerSlot', []);
2432
2580
  const res = create(unsafeRes, jsonRpcResult(number()));
2433
2581
  if ('error' in res) {
2434
- throw new Error(
2435
- 'failed to get minimum ledger slot: ' + res.error.message,
2582
+ throw new SolanaJSONRPCError(
2583
+ res.error,
2584
+ 'failed to get minimum ledger slot',
2436
2585
  );
2437
2586
  }
2438
2587
  return res.result;
@@ -2445,8 +2594,9 @@ export class Connection {
2445
2594
  const unsafeRes = await this._rpcRequest('getFirstAvailableBlock', []);
2446
2595
  const res = create(unsafeRes, SlotRpcResult);
2447
2596
  if ('error' in res) {
2448
- throw new Error(
2449
- 'failed to get first available block: ' + res.error.message,
2597
+ throw new SolanaJSONRPCError(
2598
+ res.error,
2599
+ 'failed to get first available block',
2450
2600
  );
2451
2601
  }
2452
2602
  return res.result;
@@ -2475,7 +2625,7 @@ export class Connection {
2475
2625
  const unsafeRes = await this._rpcRequest('getSupply', [configArg]);
2476
2626
  const res = create(unsafeRes, GetSupplyRpcResult);
2477
2627
  if ('error' in res) {
2478
- throw new Error('failed to get supply: ' + res.error.message);
2628
+ throw new SolanaJSONRPCError(res.error, 'failed to get supply');
2479
2629
  }
2480
2630
  return res.result;
2481
2631
  }
@@ -2491,7 +2641,7 @@ export class Connection {
2491
2641
  const unsafeRes = await this._rpcRequest('getTokenSupply', args);
2492
2642
  const res = create(unsafeRes, jsonRpcResultAndContext(TokenAmountResult));
2493
2643
  if ('error' in res) {
2494
- throw new Error('failed to get token supply: ' + res.error.message);
2644
+ throw new SolanaJSONRPCError(res.error, 'failed to get token supply');
2495
2645
  }
2496
2646
  return res.result;
2497
2647
  }
@@ -2507,8 +2657,9 @@ export class Connection {
2507
2657
  const unsafeRes = await this._rpcRequest('getTokenAccountBalance', args);
2508
2658
  const res = create(unsafeRes, jsonRpcResultAndContext(TokenAmountResult));
2509
2659
  if ('error' in res) {
2510
- throw new Error(
2511
- 'failed to get token account balance: ' + res.error.message,
2660
+ throw new SolanaJSONRPCError(
2661
+ res.error,
2662
+ 'failed to get token account balance',
2512
2663
  );
2513
2664
  }
2514
2665
  return res.result;
@@ -2522,12 +2673,14 @@ export class Connection {
2522
2673
  async getTokenAccountsByOwner(
2523
2674
  ownerAddress: PublicKey,
2524
2675
  filter: TokenAccountsFilter,
2525
- commitment?: Commitment,
2676
+ commitmentOrConfig?: Commitment | GetTokenAccountsByOwnerConfig,
2526
2677
  ): Promise<
2527
2678
  RpcResponseAndContext<
2528
2679
  Array<{pubkey: PublicKey; account: AccountInfo<Buffer>}>
2529
2680
  >
2530
2681
  > {
2682
+ const {commitment, config} =
2683
+ extractCommitmentFromConfig(commitmentOrConfig);
2531
2684
  let _args: any[] = [ownerAddress.toBase58()];
2532
2685
  if ('mint' in filter) {
2533
2686
  _args.push({mint: filter.mint.toBase58()});
@@ -2535,15 +2688,13 @@ export class Connection {
2535
2688
  _args.push({programId: filter.programId.toBase58()});
2536
2689
  }
2537
2690
 
2538
- const args = this._buildArgs(_args, commitment, 'base64');
2691
+ const args = this._buildArgs(_args, commitment, 'base64', config);
2539
2692
  const unsafeRes = await this._rpcRequest('getTokenAccountsByOwner', args);
2540
2693
  const res = create(unsafeRes, GetTokenAccountsByOwner);
2541
2694
  if ('error' in res) {
2542
- throw new Error(
2543
- 'failed to get token accounts owned by account ' +
2544
- ownerAddress.toBase58() +
2545
- ': ' +
2546
- res.error.message,
2695
+ throw new SolanaJSONRPCError(
2696
+ res.error,
2697
+ `failed to get token accounts owned by account ${ownerAddress.toBase58()}`,
2547
2698
  );
2548
2699
  }
2549
2700
  return res.result;
@@ -2574,11 +2725,9 @@ export class Connection {
2574
2725
  const unsafeRes = await this._rpcRequest('getTokenAccountsByOwner', args);
2575
2726
  const res = create(unsafeRes, GetParsedTokenAccountsByOwner);
2576
2727
  if ('error' in res) {
2577
- throw new Error(
2578
- 'failed to get token accounts owned by account ' +
2579
- ownerAddress.toBase58() +
2580
- ': ' +
2581
- res.error.message,
2728
+ throw new SolanaJSONRPCError(
2729
+ res.error,
2730
+ `failed to get token accounts owned by account ${ownerAddress.toBase58()}`,
2582
2731
  );
2583
2732
  }
2584
2733
  return res.result;
@@ -2598,7 +2747,7 @@ export class Connection {
2598
2747
  const unsafeRes = await this._rpcRequest('getLargestAccounts', args);
2599
2748
  const res = create(unsafeRes, GetLargestAccountsRpcResult);
2600
2749
  if ('error' in res) {
2601
- throw new Error('failed to get largest accounts: ' + res.error.message);
2750
+ throw new SolanaJSONRPCError(res.error, 'failed to get largest accounts');
2602
2751
  }
2603
2752
  return res.result;
2604
2753
  }
@@ -2615,8 +2764,9 @@ export class Connection {
2615
2764
  const unsafeRes = await this._rpcRequest('getTokenLargestAccounts', args);
2616
2765
  const res = create(unsafeRes, GetTokenLargestAccountsResult);
2617
2766
  if ('error' in res) {
2618
- throw new Error(
2619
- 'failed to get token largest accounts: ' + res.error.message,
2767
+ throw new SolanaJSONRPCError(
2768
+ res.error,
2769
+ 'failed to get token largest accounts',
2620
2770
  );
2621
2771
  }
2622
2772
  return res.result;
@@ -2627,20 +2777,25 @@ export class Connection {
2627
2777
  */
2628
2778
  async getAccountInfoAndContext(
2629
2779
  publicKey: PublicKey,
2630
- commitment?: Commitment,
2780
+ commitmentOrConfig?: Commitment | GetAccountInfoConfig,
2631
2781
  ): Promise<RpcResponseAndContext<AccountInfo<Buffer> | null>> {
2632
- const args = this._buildArgs([publicKey.toBase58()], commitment, 'base64');
2782
+ const {commitment, config} =
2783
+ extractCommitmentFromConfig(commitmentOrConfig);
2784
+ const args = this._buildArgs(
2785
+ [publicKey.toBase58()],
2786
+ commitment,
2787
+ 'base64',
2788
+ config,
2789
+ );
2633
2790
  const unsafeRes = await this._rpcRequest('getAccountInfo', args);
2634
2791
  const res = create(
2635
2792
  unsafeRes,
2636
2793
  jsonRpcResultAndContext(nullable(AccountInfoResult)),
2637
2794
  );
2638
2795
  if ('error' in res) {
2639
- throw new Error(
2640
- 'failed to get info about account ' +
2641
- publicKey.toBase58() +
2642
- ': ' +
2643
- res.error.message,
2796
+ throw new SolanaJSONRPCError(
2797
+ res.error,
2798
+ `failed to get info about account ${publicKey.toBase58()}`,
2644
2799
  );
2645
2800
  }
2646
2801
  return res.result;
@@ -2666,11 +2821,9 @@ export class Connection {
2666
2821
  jsonRpcResultAndContext(nullable(ParsedAccountInfoResult)),
2667
2822
  );
2668
2823
  if ('error' in res) {
2669
- throw new Error(
2670
- 'failed to get info about account ' +
2671
- publicKey.toBase58() +
2672
- ': ' +
2673
- res.error.message,
2824
+ throw new SolanaJSONRPCError(
2825
+ res.error,
2826
+ `failed to get info about account ${publicKey.toBase58()}`,
2674
2827
  );
2675
2828
  }
2676
2829
  return res.result;
@@ -2681,10 +2834,13 @@ export class Connection {
2681
2834
  */
2682
2835
  async getAccountInfo(
2683
2836
  publicKey: PublicKey,
2684
- commitment?: Commitment,
2837
+ commitmentOrConfig?: Commitment | GetAccountInfoConfig,
2685
2838
  ): Promise<AccountInfo<Buffer> | null> {
2686
2839
  try {
2687
- const res = await this.getAccountInfoAndContext(publicKey, commitment);
2840
+ const res = await this.getAccountInfoAndContext(
2841
+ publicKey,
2842
+ commitmentOrConfig,
2843
+ );
2688
2844
  return res.value;
2689
2845
  } catch (e) {
2690
2846
  throw new Error(
@@ -2698,18 +2854,21 @@ export class Connection {
2698
2854
  */
2699
2855
  async getMultipleAccountsInfoAndContext(
2700
2856
  publicKeys: PublicKey[],
2701
- commitment?: Commitment,
2857
+ commitmentOrConfig?: Commitment | GetMultipleAccountsConfig,
2702
2858
  ): Promise<RpcResponseAndContext<(AccountInfo<Buffer> | null)[]>> {
2859
+ const {commitment, config} =
2860
+ extractCommitmentFromConfig(commitmentOrConfig);
2703
2861
  const keys = publicKeys.map(key => key.toBase58());
2704
- const args = this._buildArgs([keys], commitment, 'base64');
2862
+ const args = this._buildArgs([keys], commitment, 'base64', config);
2705
2863
  const unsafeRes = await this._rpcRequest('getMultipleAccounts', args);
2706
2864
  const res = create(
2707
2865
  unsafeRes,
2708
2866
  jsonRpcResultAndContext(array(nullable(AccountInfoResult))),
2709
2867
  );
2710
2868
  if ('error' in res) {
2711
- throw new Error(
2712
- 'failed to get info for accounts ' + keys + ': ' + res.error.message,
2869
+ throw new SolanaJSONRPCError(
2870
+ res.error,
2871
+ `failed to get info for accounts ${keys}`,
2713
2872
  );
2714
2873
  }
2715
2874
  return res.result;
@@ -2720,11 +2879,11 @@ export class Connection {
2720
2879
  */
2721
2880
  async getMultipleAccountsInfo(
2722
2881
  publicKeys: PublicKey[],
2723
- commitment?: Commitment,
2882
+ commitmentOrConfig?: Commitment | GetMultipleAccountsConfig,
2724
2883
  ): Promise<(AccountInfo<Buffer> | null)[]> {
2725
2884
  const res = await this.getMultipleAccountsInfoAndContext(
2726
2885
  publicKeys,
2727
- commitment,
2886
+ commitmentOrConfig,
2728
2887
  );
2729
2888
  return res.value;
2730
2889
  }
@@ -2734,23 +2893,27 @@ export class Connection {
2734
2893
  */
2735
2894
  async getStakeActivation(
2736
2895
  publicKey: PublicKey,
2737
- commitment?: Commitment,
2896
+ commitmentOrConfig?: Commitment | GetStakeActivationConfig,
2738
2897
  epoch?: number,
2739
2898
  ): Promise<StakeActivationData> {
2899
+ const {commitment, config} =
2900
+ extractCommitmentFromConfig(commitmentOrConfig);
2740
2901
  const args = this._buildArgs(
2741
2902
  [publicKey.toBase58()],
2742
2903
  commitment,
2743
- undefined,
2744
- epoch !== undefined ? {epoch} : undefined,
2904
+ undefined /* encoding */,
2905
+ {
2906
+ ...config,
2907
+ epoch: epoch != null ? epoch : config?.epoch,
2908
+ },
2745
2909
  );
2746
2910
 
2747
2911
  const unsafeRes = await this._rpcRequest('getStakeActivation', args);
2748
2912
  const res = create(unsafeRes, jsonRpcResult(StakeActivationResult));
2749
2913
  if ('error' in res) {
2750
- throw new Error(
2751
- `failed to get Stake Activation ${publicKey.toBase58()}: ${
2752
- res.error.message
2753
- }`,
2914
+ throw new SolanaJSONRPCError(
2915
+ res.error,
2916
+ `failed to get Stake Activation ${publicKey.toBase58()}`,
2754
2917
  );
2755
2918
  }
2756
2919
  return res.result;
@@ -2765,40 +2928,21 @@ export class Connection {
2765
2928
  programId: PublicKey,
2766
2929
  configOrCommitment?: GetProgramAccountsConfig | Commitment,
2767
2930
  ): Promise<Array<{pubkey: PublicKey; account: AccountInfo<Buffer>}>> {
2768
- const extra: Pick<GetProgramAccountsConfig, 'dataSlice' | 'filters'> = {};
2769
-
2770
- let commitment;
2771
- let encoding;
2772
- if (configOrCommitment) {
2773
- if (typeof configOrCommitment === 'string') {
2774
- commitment = configOrCommitment;
2775
- } else {
2776
- commitment = configOrCommitment.commitment;
2777
- encoding = configOrCommitment.encoding;
2778
-
2779
- if (configOrCommitment.dataSlice) {
2780
- extra.dataSlice = configOrCommitment.dataSlice;
2781
- }
2782
- if (configOrCommitment.filters) {
2783
- extra.filters = configOrCommitment.filters;
2784
- }
2785
- }
2786
- }
2787
-
2931
+ const {commitment, config} =
2932
+ extractCommitmentFromConfig(configOrCommitment);
2933
+ const {encoding, ...configWithoutEncoding} = config || {};
2788
2934
  const args = this._buildArgs(
2789
2935
  [programId.toBase58()],
2790
2936
  commitment,
2791
2937
  encoding || 'base64',
2792
- extra,
2938
+ configWithoutEncoding,
2793
2939
  );
2794
2940
  const unsafeRes = await this._rpcRequest('getProgramAccounts', args);
2795
2941
  const res = create(unsafeRes, jsonRpcResult(array(KeyedAccountInfoResult)));
2796
2942
  if ('error' in res) {
2797
- throw new Error(
2798
- 'failed to get accounts owned by program ' +
2799
- programId.toBase58() +
2800
- ': ' +
2801
- res.error.message,
2943
+ throw new SolanaJSONRPCError(
2944
+ res.error,
2945
+ `failed to get accounts owned by program ${programId.toBase58()}`,
2802
2946
  );
2803
2947
  }
2804
2948
  return res.result;
@@ -2818,26 +2962,13 @@ export class Connection {
2818
2962
  account: AccountInfo<Buffer | ParsedAccountData>;
2819
2963
  }>
2820
2964
  > {
2821
- const extra: Pick<GetParsedProgramAccountsConfig, 'filters'> = {};
2822
-
2823
- let commitment;
2824
- if (configOrCommitment) {
2825
- if (typeof configOrCommitment === 'string') {
2826
- commitment = configOrCommitment;
2827
- } else {
2828
- commitment = configOrCommitment.commitment;
2829
-
2830
- if (configOrCommitment.filters) {
2831
- extra.filters = configOrCommitment.filters;
2832
- }
2833
- }
2834
- }
2835
-
2965
+ const {commitment, config} =
2966
+ extractCommitmentFromConfig(configOrCommitment);
2836
2967
  const args = this._buildArgs(
2837
2968
  [programId.toBase58()],
2838
2969
  commitment,
2839
2970
  'jsonParsed',
2840
- extra,
2971
+ config,
2841
2972
  );
2842
2973
  const unsafeRes = await this._rpcRequest('getProgramAccounts', args);
2843
2974
  const res = create(
@@ -2845,11 +2976,9 @@ export class Connection {
2845
2976
  jsonRpcResult(array(KeyedParsedAccountInfoResult)),
2846
2977
  );
2847
2978
  if ('error' in res) {
2848
- throw new Error(
2849
- 'failed to get accounts owned by program ' +
2850
- programId.toBase58() +
2851
- ': ' +
2852
- res.error.message,
2979
+ throw new SolanaJSONRPCError(
2980
+ res.error,
2981
+ `failed to get accounts owned by program ${programId.toBase58()}`,
2853
2982
  );
2854
2983
  }
2855
2984
  return res.result;
@@ -3004,7 +3133,7 @@ export class Connection {
3004
3133
  const unsafeRes = await this._rpcRequest('getClusterNodes', []);
3005
3134
  const res = create(unsafeRes, jsonRpcResult(array(ContactInfoResult)));
3006
3135
  if ('error' in res) {
3007
- throw new Error('failed to get cluster nodes: ' + res.error.message);
3136
+ throw new SolanaJSONRPCError(res.error, 'failed to get cluster nodes');
3008
3137
  }
3009
3138
  return res.result;
3010
3139
  }
@@ -3017,7 +3146,7 @@ export class Connection {
3017
3146
  const unsafeRes = await this._rpcRequest('getVoteAccounts', args);
3018
3147
  const res = create(unsafeRes, GetVoteAccounts);
3019
3148
  if ('error' in res) {
3020
- throw new Error('failed to get vote accounts: ' + res.error.message);
3149
+ throw new SolanaJSONRPCError(res.error, 'failed to get vote accounts');
3021
3150
  }
3022
3151
  return res.result;
3023
3152
  }
@@ -3025,12 +3154,21 @@ export class Connection {
3025
3154
  /**
3026
3155
  * Fetch the current slot that the node is processing
3027
3156
  */
3028
- async getSlot(commitment?: Commitment): Promise<number> {
3029
- const args = this._buildArgs([], commitment);
3157
+ async getSlot(
3158
+ commitmentOrConfig?: Commitment | GetSlotConfig,
3159
+ ): Promise<number> {
3160
+ const {commitment, config} =
3161
+ extractCommitmentFromConfig(commitmentOrConfig);
3162
+ const args = this._buildArgs(
3163
+ [],
3164
+ commitment,
3165
+ undefined /* encoding */,
3166
+ config,
3167
+ );
3030
3168
  const unsafeRes = await this._rpcRequest('getSlot', args);
3031
3169
  const res = create(unsafeRes, jsonRpcResult(number()));
3032
3170
  if ('error' in res) {
3033
- throw new Error('failed to get slot: ' + res.error.message);
3171
+ throw new SolanaJSONRPCError(res.error, 'failed to get slot');
3034
3172
  }
3035
3173
  return res.result;
3036
3174
  }
@@ -3038,12 +3176,21 @@ export class Connection {
3038
3176
  /**
3039
3177
  * Fetch the current slot leader of the cluster
3040
3178
  */
3041
- async getSlotLeader(commitment?: Commitment): Promise<string> {
3042
- const args = this._buildArgs([], commitment);
3179
+ async getSlotLeader(
3180
+ commitmentOrConfig?: Commitment | GetSlotLeaderConfig,
3181
+ ): Promise<string> {
3182
+ const {commitment, config} =
3183
+ extractCommitmentFromConfig(commitmentOrConfig);
3184
+ const args = this._buildArgs(
3185
+ [],
3186
+ commitment,
3187
+ undefined /* encoding */,
3188
+ config,
3189
+ );
3043
3190
  const unsafeRes = await this._rpcRequest('getSlotLeader', args);
3044
3191
  const res = create(unsafeRes, jsonRpcResult(string()));
3045
3192
  if ('error' in res) {
3046
- throw new Error('failed to get slot leader: ' + res.error.message);
3193
+ throw new SolanaJSONRPCError(res.error, 'failed to get slot leader');
3047
3194
  }
3048
3195
  return res.result;
3049
3196
  }
@@ -3062,7 +3209,7 @@ export class Connection {
3062
3209
  const unsafeRes = await this._rpcRequest('getSlotLeaders', args);
3063
3210
  const res = create(unsafeRes, jsonRpcResult(array(PublicKeyFromString)));
3064
3211
  if ('error' in res) {
3065
- throw new Error('failed to get slot leaders: ' + res.error.message);
3212
+ throw new SolanaJSONRPCError(res.error, 'failed to get slot leaders');
3066
3213
  }
3067
3214
  return res.result;
3068
3215
  }
@@ -3097,7 +3244,7 @@ export class Connection {
3097
3244
  const unsafeRes = await this._rpcRequest('getSignatureStatuses', params);
3098
3245
  const res = create(unsafeRes, GetSignatureStatusesRpcResult);
3099
3246
  if ('error' in res) {
3100
- throw new Error('failed to get signature status: ' + res.error.message);
3247
+ throw new SolanaJSONRPCError(res.error, 'failed to get signature status');
3101
3248
  }
3102
3249
  return res.result;
3103
3250
  }
@@ -3105,12 +3252,24 @@ export class Connection {
3105
3252
  /**
3106
3253
  * Fetch the current transaction count of the cluster
3107
3254
  */
3108
- async getTransactionCount(commitment?: Commitment): Promise<number> {
3109
- const args = this._buildArgs([], commitment);
3255
+ async getTransactionCount(
3256
+ commitmentOrConfig?: Commitment | GetTransactionCountConfig,
3257
+ ): Promise<number> {
3258
+ const {commitment, config} =
3259
+ extractCommitmentFromConfig(commitmentOrConfig);
3260
+ const args = this._buildArgs(
3261
+ [],
3262
+ commitment,
3263
+ undefined /* encoding */,
3264
+ config,
3265
+ );
3110
3266
  const unsafeRes = await this._rpcRequest('getTransactionCount', args);
3111
3267
  const res = create(unsafeRes, jsonRpcResult(number()));
3112
3268
  if ('error' in res) {
3113
- throw new Error('failed to get transaction count: ' + res.error.message);
3269
+ throw new SolanaJSONRPCError(
3270
+ res.error,
3271
+ 'failed to get transaction count',
3272
+ );
3114
3273
  }
3115
3274
  return res.result;
3116
3275
  }
@@ -3138,7 +3297,7 @@ export class Connection {
3138
3297
  const unsafeRes = await this._rpcRequest('getInflationGovernor', args);
3139
3298
  const res = create(unsafeRes, GetInflationGovernorRpcResult);
3140
3299
  if ('error' in res) {
3141
- throw new Error('failed to get inflation: ' + res.error.message);
3300
+ throw new SolanaJSONRPCError(res.error, 'failed to get inflation');
3142
3301
  }
3143
3302
  return res.result;
3144
3303
  }
@@ -3149,20 +3308,23 @@ export class Connection {
3149
3308
  async getInflationReward(
3150
3309
  addresses: PublicKey[],
3151
3310
  epoch?: number,
3152
- commitment?: Commitment,
3311
+ commitmentOrConfig?: Commitment | GetInflationRewardConfig,
3153
3312
  ): Promise<(InflationReward | null)[]> {
3313
+ const {commitment, config} =
3314
+ extractCommitmentFromConfig(commitmentOrConfig);
3154
3315
  const args = this._buildArgs(
3155
3316
  [addresses.map(pubkey => pubkey.toBase58())],
3156
3317
  commitment,
3157
- undefined,
3318
+ undefined /* encoding */,
3158
3319
  {
3159
- epoch,
3320
+ ...config,
3321
+ epoch: epoch != null ? epoch : config?.epoch,
3160
3322
  },
3161
3323
  );
3162
3324
  const unsafeRes = await this._rpcRequest('getInflationReward', args);
3163
3325
  const res = create(unsafeRes, GetInflationRewardResult);
3164
3326
  if ('error' in res) {
3165
- throw new Error('failed to get inflation reward: ' + res.error.message);
3327
+ throw new SolanaJSONRPCError(res.error, 'failed to get inflation reward');
3166
3328
  }
3167
3329
  return res.result;
3168
3330
  }
@@ -3170,12 +3332,21 @@ export class Connection {
3170
3332
  /**
3171
3333
  * Fetch the Epoch Info parameters
3172
3334
  */
3173
- async getEpochInfo(commitment?: Commitment): Promise<EpochInfo> {
3174
- const args = this._buildArgs([], commitment);
3335
+ async getEpochInfo(
3336
+ commitmentOrConfig?: Commitment | GetEpochInfoConfig,
3337
+ ): Promise<EpochInfo> {
3338
+ const {commitment, config} =
3339
+ extractCommitmentFromConfig(commitmentOrConfig);
3340
+ const args = this._buildArgs(
3341
+ [],
3342
+ commitment,
3343
+ undefined /* encoding */,
3344
+ config,
3345
+ );
3175
3346
  const unsafeRes = await this._rpcRequest('getEpochInfo', args);
3176
3347
  const res = create(unsafeRes, GetEpochInfoRpcResult);
3177
3348
  if ('error' in res) {
3178
- throw new Error('failed to get epoch info: ' + res.error.message);
3349
+ throw new SolanaJSONRPCError(res.error, 'failed to get epoch info');
3179
3350
  }
3180
3351
  return res.result;
3181
3352
  }
@@ -3187,7 +3358,7 @@ export class Connection {
3187
3358
  const unsafeRes = await this._rpcRequest('getEpochSchedule', []);
3188
3359
  const res = create(unsafeRes, GetEpochScheduleRpcResult);
3189
3360
  if ('error' in res) {
3190
- throw new Error('failed to get epoch schedule: ' + res.error.message);
3361
+ throw new SolanaJSONRPCError(res.error, 'failed to get epoch schedule');
3191
3362
  }
3192
3363
  const epochSchedule = res.result;
3193
3364
  return new EpochSchedule(
@@ -3207,7 +3378,7 @@ export class Connection {
3207
3378
  const unsafeRes = await this._rpcRequest('getLeaderSchedule', []);
3208
3379
  const res = create(unsafeRes, GetLeaderScheduleRpcResult);
3209
3380
  if ('error' in res) {
3210
- throw new Error('failed to get leader schedule: ' + res.error.message);
3381
+ throw new SolanaJSONRPCError(res.error, 'failed to get leader schedule');
3211
3382
  }
3212
3383
  return res.result;
3213
3384
  }
@@ -3248,7 +3419,7 @@ export class Connection {
3248
3419
  const unsafeRes = await this._rpcRequest('getRecentBlockhash', args);
3249
3420
  const res = create(unsafeRes, GetRecentBlockhashAndContextRpcResult);
3250
3421
  if ('error' in res) {
3251
- throw new Error('failed to get recent blockhash: ' + res.error.message);
3422
+ throw new SolanaJSONRPCError(res.error, 'failed to get recent blockhash');
3252
3423
  }
3253
3424
  return res.result;
3254
3425
  }
@@ -3267,8 +3438,9 @@ export class Connection {
3267
3438
  );
3268
3439
  const res = create(unsafeRes, GetRecentPerformanceSamplesRpcResult);
3269
3440
  if ('error' in res) {
3270
- throw new Error(
3271
- 'failed to get recent performance samples: ' + res.error.message,
3441
+ throw new SolanaJSONRPCError(
3442
+ res.error,
3443
+ 'failed to get recent performance samples',
3272
3444
  );
3273
3445
  }
3274
3446
 
@@ -3292,7 +3464,7 @@ export class Connection {
3292
3464
 
3293
3465
  const res = create(unsafeRes, GetFeeCalculatorRpcResult);
3294
3466
  if ('error' in res) {
3295
- throw new Error('failed to get fee calculator: ' + res.error.message);
3467
+ throw new SolanaJSONRPCError(res.error, 'failed to get fee calculator');
3296
3468
  }
3297
3469
  const {context, value} = res.result;
3298
3470
  return {
@@ -3314,7 +3486,7 @@ export class Connection {
3314
3486
 
3315
3487
  const res = create(unsafeRes, jsonRpcResultAndContext(nullable(number())));
3316
3488
  if ('error' in res) {
3317
- throw new Error('failed to get slot: ' + res.error.message);
3489
+ throw new SolanaJSONRPCError(res.error, 'failed to get slot');
3318
3490
  }
3319
3491
  if (res.result === null) {
3320
3492
  throw new Error('invalid blockhash');
@@ -3344,10 +3516,10 @@ export class Connection {
3344
3516
  * @return {Promise<BlockhashWithExpiryBlockHeight>}
3345
3517
  */
3346
3518
  async getLatestBlockhash(
3347
- commitment?: Commitment,
3519
+ commitmentOrConfig?: Commitment | GetLatestBlockhashConfig,
3348
3520
  ): Promise<BlockhashWithExpiryBlockHeight> {
3349
3521
  try {
3350
- const res = await this.getLatestBlockhashAndContext(commitment);
3522
+ const res = await this.getLatestBlockhashAndContext(commitmentOrConfig);
3351
3523
  return res.value;
3352
3524
  } catch (e) {
3353
3525
  throw new Error('failed to get recent blockhash: ' + e);
@@ -3359,13 +3531,20 @@ export class Connection {
3359
3531
  * @return {Promise<BlockhashWithExpiryBlockHeight>}
3360
3532
  */
3361
3533
  async getLatestBlockhashAndContext(
3362
- commitment?: Commitment,
3534
+ commitmentOrConfig?: Commitment | GetLatestBlockhashConfig,
3363
3535
  ): Promise<RpcResponseAndContext<BlockhashWithExpiryBlockHeight>> {
3364
- const args = this._buildArgs([], commitment);
3536
+ const {commitment, config} =
3537
+ extractCommitmentFromConfig(commitmentOrConfig);
3538
+ const args = this._buildArgs(
3539
+ [],
3540
+ commitment,
3541
+ undefined /* encoding */,
3542
+ config,
3543
+ );
3365
3544
  const unsafeRes = await this._rpcRequest('getLatestBlockhash', args);
3366
3545
  const res = create(unsafeRes, GetLatestBlockhashRpcResult);
3367
3546
  if ('error' in res) {
3368
- throw new Error('failed to get latest blockhash: ' + res.error.message);
3547
+ throw new SolanaJSONRPCError(res.error, 'failed to get latest blockhash');
3369
3548
  }
3370
3549
  return res.result;
3371
3550
  }
@@ -3377,7 +3556,7 @@ export class Connection {
3377
3556
  const unsafeRes = await this._rpcRequest('getVersion', []);
3378
3557
  const res = create(unsafeRes, jsonRpcResult(VersionResult));
3379
3558
  if ('error' in res) {
3380
- throw new Error('failed to get version: ' + res.error.message);
3559
+ throw new SolanaJSONRPCError(res.error, 'failed to get version');
3381
3560
  }
3382
3561
  return res.result;
3383
3562
  }
@@ -3389,7 +3568,7 @@ export class Connection {
3389
3568
  const unsafeRes = await this._rpcRequest('getGenesisHash', []);
3390
3569
  const res = create(unsafeRes, jsonRpcResult(string()));
3391
3570
  if ('error' in res) {
3392
- throw new Error('failed to get genesis hash: ' + res.error.message);
3571
+ throw new SolanaJSONRPCError(res.error, 'failed to get genesis hash');
3393
3572
  }
3394
3573
  return res.result;
3395
3574
  }
@@ -3409,7 +3588,7 @@ export class Connection {
3409
3588
  const res = create(unsafeRes, GetBlockRpcResult);
3410
3589
 
3411
3590
  if ('error' in res) {
3412
- throw new Error('failed to get confirmed block: ' + res.error.message);
3591
+ throw new SolanaJSONRPCError(res.error, 'failed to get confirmed block');
3413
3592
  }
3414
3593
 
3415
3594
  const result = res.result;
@@ -3433,13 +3612,23 @@ export class Connection {
3433
3612
  /*
3434
3613
  * Returns the current block height of the node
3435
3614
  */
3436
- async getBlockHeight(commitment?: Commitment): Promise<number> {
3437
- const args = this._buildArgs([], commitment);
3615
+ async getBlockHeight(
3616
+ commitmentOrConfig?: Commitment | GetBlockHeightConfig,
3617
+ ): Promise<number> {
3618
+ const {commitment, config} =
3619
+ extractCommitmentFromConfig(commitmentOrConfig);
3620
+ const args = this._buildArgs(
3621
+ [],
3622
+ commitment,
3623
+ undefined /* encoding */,
3624
+ config,
3625
+ );
3438
3626
  const unsafeRes = await this._rpcRequest('getBlockHeight', args);
3439
3627
  const res = create(unsafeRes, jsonRpcResult(number()));
3440
3628
  if ('error' in res) {
3441
- throw new Error(
3442
- 'failed to get block height information: ' + res.error.message,
3629
+ throw new SolanaJSONRPCError(
3630
+ res.error,
3631
+ 'failed to get block height information',
3443
3632
  );
3444
3633
  }
3445
3634
 
@@ -3467,8 +3656,9 @@ export class Connection {
3467
3656
  const unsafeRes = await this._rpcRequest('getBlockProduction', args);
3468
3657
  const res = create(unsafeRes, BlockProductionResponseStruct);
3469
3658
  if ('error' in res) {
3470
- throw new Error(
3471
- 'failed to get block production information: ' + res.error.message,
3659
+ throw new SolanaJSONRPCError(
3660
+ res.error,
3661
+ 'failed to get block production information',
3472
3662
  );
3473
3663
  }
3474
3664
 
@@ -3489,7 +3679,7 @@ export class Connection {
3489
3679
  const unsafeRes = await this._rpcRequest('getTransaction', args);
3490
3680
  const res = create(unsafeRes, GetTransactionRpcResult);
3491
3681
  if ('error' in res) {
3492
- throw new Error('failed to get transaction: ' + res.error.message);
3682
+ throw new SolanaJSONRPCError(res.error, 'failed to get transaction');
3493
3683
  }
3494
3684
 
3495
3685
  const result = res.result;
@@ -3519,7 +3709,7 @@ export class Connection {
3519
3709
  const unsafeRes = await this._rpcRequest('getTransaction', args);
3520
3710
  const res = create(unsafeRes, GetParsedTransactionRpcResult);
3521
3711
  if ('error' in res) {
3522
- throw new Error('failed to get transaction: ' + res.error.message);
3712
+ throw new SolanaJSONRPCError(res.error, 'failed to get transaction');
3523
3713
  }
3524
3714
  return res.result;
3525
3715
  }
@@ -3547,7 +3737,7 @@ export class Connection {
3547
3737
  const res = unsafeRes.map((unsafeRes: any) => {
3548
3738
  const res = create(unsafeRes, GetParsedTransactionRpcResult);
3549
3739
  if ('error' in res) {
3550
- throw new Error('failed to get transactions: ' + res.error.message);
3740
+ throw new SolanaJSONRPCError(res.error, 'failed to get transactions');
3551
3741
  }
3552
3742
  return res.result;
3553
3743
  });
@@ -3575,7 +3765,7 @@ export class Connection {
3575
3765
  const res = unsafeRes.map((unsafeRes: any) => {
3576
3766
  const res = create(unsafeRes, GetTransactionRpcResult);
3577
3767
  if ('error' in res) {
3578
- throw new Error('failed to get transactions: ' + res.error.message);
3768
+ throw new SolanaJSONRPCError(res.error, 'failed to get transactions');
3579
3769
  }
3580
3770
  const result = res.result;
3581
3771
  if (!result) return result;
@@ -3607,7 +3797,7 @@ export class Connection {
3607
3797
  const res = create(unsafeRes, GetConfirmedBlockRpcResult);
3608
3798
 
3609
3799
  if ('error' in res) {
3610
- throw new Error('failed to get confirmed block: ' + res.error.message);
3800
+ throw new SolanaJSONRPCError(res.error, 'failed to get confirmed block');
3611
3801
  }
3612
3802
 
3613
3803
  const result = res.result;
@@ -3658,7 +3848,7 @@ export class Connection {
3658
3848
  const unsafeRes = await this._rpcRequest('getBlocks', args);
3659
3849
  const res = create(unsafeRes, jsonRpcResult(array(number())));
3660
3850
  if ('error' in res) {
3661
- throw new Error('failed to get blocks: ' + res.error.message);
3851
+ throw new SolanaJSONRPCError(res.error, 'failed to get blocks');
3662
3852
  }
3663
3853
  return res.result;
3664
3854
  }
@@ -3682,7 +3872,7 @@ export class Connection {
3682
3872
  const unsafeRes = await this._rpcRequest('getBlock', args);
3683
3873
  const res = create(unsafeRes, GetBlockSignaturesRpcResult);
3684
3874
  if ('error' in res) {
3685
- throw new Error('failed to get block: ' + res.error.message);
3875
+ throw new SolanaJSONRPCError(res.error, 'failed to get block');
3686
3876
  }
3687
3877
  const result = res.result;
3688
3878
  if (!result) {
@@ -3712,7 +3902,7 @@ export class Connection {
3712
3902
  const unsafeRes = await this._rpcRequest('getConfirmedBlock', args);
3713
3903
  const res = create(unsafeRes, GetBlockSignaturesRpcResult);
3714
3904
  if ('error' in res) {
3715
- throw new Error('failed to get confirmed block: ' + res.error.message);
3905
+ throw new SolanaJSONRPCError(res.error, 'failed to get confirmed block');
3716
3906
  }
3717
3907
  const result = res.result;
3718
3908
  if (!result) {
@@ -3734,7 +3924,7 @@ export class Connection {
3734
3924
  const unsafeRes = await this._rpcRequest('getConfirmedTransaction', args);
3735
3925
  const res = create(unsafeRes, GetTransactionRpcResult);
3736
3926
  if ('error' in res) {
3737
- throw new Error('failed to get transaction: ' + res.error.message);
3927
+ throw new SolanaJSONRPCError(res.error, 'failed to get transaction');
3738
3928
  }
3739
3929
 
3740
3930
  const result = res.result;
@@ -3765,8 +3955,9 @@ export class Connection {
3765
3955
  const unsafeRes = await this._rpcRequest('getConfirmedTransaction', args);
3766
3956
  const res = create(unsafeRes, GetParsedTransactionRpcResult);
3767
3957
  if ('error' in res) {
3768
- throw new Error(
3769
- 'failed to get confirmed transaction: ' + res.error.message,
3958
+ throw new SolanaJSONRPCError(
3959
+ res.error,
3960
+ 'failed to get confirmed transaction',
3770
3961
  );
3771
3962
  }
3772
3963
  return res.result;
@@ -3797,8 +3988,9 @@ export class Connection {
3797
3988
  const res = unsafeRes.map((unsafeRes: any) => {
3798
3989
  const res = create(unsafeRes, GetParsedTransactionRpcResult);
3799
3990
  if ('error' in res) {
3800
- throw new Error(
3801
- 'failed to get confirmed transactions: ' + res.error.message,
3991
+ throw new SolanaJSONRPCError(
3992
+ res.error,
3993
+ 'failed to get confirmed transactions',
3802
3994
  );
3803
3995
  }
3804
3996
  return res.result;
@@ -3903,8 +4095,9 @@ export class Connection {
3903
4095
  );
3904
4096
  const res = create(unsafeRes, GetConfirmedSignaturesForAddress2RpcResult);
3905
4097
  if ('error' in res) {
3906
- throw new Error(
3907
- 'failed to get confirmed signatures for address: ' + res.error.message,
4098
+ throw new SolanaJSONRPCError(
4099
+ res.error,
4100
+ 'failed to get confirmed signatures for address',
3908
4101
  );
3909
4102
  }
3910
4103
  return res.result;
@@ -3932,8 +4125,9 @@ export class Connection {
3932
4125
  const unsafeRes = await this._rpcRequest('getSignaturesForAddress', args);
3933
4126
  const res = create(unsafeRes, GetSignaturesForAddressRpcResult);
3934
4127
  if ('error' in res) {
3935
- throw new Error(
3936
- 'failed to get signatures for address: ' + res.error.message,
4128
+ throw new SolanaJSONRPCError(
4129
+ res.error,
4130
+ 'failed to get signatures for address',
3937
4131
  );
3938
4132
  }
3939
4133
  return res.result;
@@ -4005,8 +4199,9 @@ export class Connection {
4005
4199
  ]);
4006
4200
  const res = create(unsafeRes, RequestAirdropRpcResult);
4007
4201
  if ('error' in res) {
4008
- throw new Error(
4009
- 'airdrop to ' + to.toBase58() + ' failed: ' + res.error.message,
4202
+ throw new SolanaJSONRPCError(
4203
+ res.error,
4204
+ `airdrop to ${to.toBase58()} failed`,
4010
4205
  );
4011
4206
  }
4012
4207
  return res.result;
@@ -4247,9 +4442,12 @@ export class Connection {
4247
4442
  const preflightCommitment =
4248
4443
  (options && options.preflightCommitment) || this.commitment;
4249
4444
 
4250
- if (options && options.maxRetries) {
4445
+ if (options && options.maxRetries != null) {
4251
4446
  config.maxRetries = options.maxRetries;
4252
4447
  }
4448
+ if (options && options.minContextSlot != null) {
4449
+ config.minContextSlot = options.minContextSlot;
4450
+ }
4253
4451
  if (skipPreflight) {
4254
4452
  config.skipPreflight = skipPreflight;
4255
4453
  }