@solana/web3.js 1.44.2 → 1.46.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@solana/web3.js",
3
- "version": "1.44.2",
3
+ "version": "1.46.0",
4
4
  "description": "Solana Javascript API",
5
5
  "keywords": [
6
6
  "api",
@@ -50,7 +50,7 @@
50
50
  "pretty": "prettier --check '{,{src,test}/**/}*.{j,t}s'",
51
51
  "pretty:fix": "prettier --write '{,{src,test}/**/}*.{j,t}s'",
52
52
  "re": "semantic-release --repository-url git@github.com:solana-labs/solana-web3.js.git",
53
- "test": "cross-env TS_NODE_COMPILER_OPTIONS='{ \"module\": \"commonjs\" }' ts-mocha --require esm './test/**/*.test.ts'",
53
+ "test": "cross-env TS_NODE_COMPILER_OPTIONS='{ \"module\": \"commonjs\", \"target\": \"es2019\" }' ts-mocha --require esm './test/**/*.test.ts'",
54
54
  "test:cover": "nyc --reporter=lcov npm run test",
55
55
  "test:live": "TEST_LIVE=1 npm run test",
56
56
  "test:live-with-test-validator": "start-server-and-test 'solana-test-validator --reset --quiet' http://localhost:8899/health test:live"
@@ -68,7 +68,7 @@
68
68
  "jayson": "^3.4.4",
69
69
  "js-sha3": "^0.8.0",
70
70
  "node-fetch": "2",
71
- "rpc-websockets": "^7.4.2",
71
+ "rpc-websockets": "^7.5.0",
72
72
  "secp256k1": "^4.0.2",
73
73
  "superstruct": "^0.14.2",
74
74
  "tweetnacl": "^1.0.0"
package/src/connection.ts CHANGED
@@ -191,9 +191,9 @@ type Subscription = BaseSubscription &
191
191
  StatefulSubscription &
192
192
  DistributiveOmit<SubscriptionConfig, 'callback'>;
193
193
 
194
- type RpcRequest = (methodName: string, args: Array<any>) => any;
194
+ type RpcRequest = (methodName: string, args: Array<any>) => Promise<any>;
195
195
 
196
- type RpcBatchRequest = (requests: RpcParams[]) => any;
196
+ type RpcBatchRequest = (requests: RpcParams[]) => Promise<any[]>;
197
197
 
198
198
  /**
199
199
  * @internal
@@ -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
  */
@@ -995,6 +1100,7 @@ function createRpcClient(
995
1100
  'Content-Type': 'application/json',
996
1101
  },
997
1102
  httpHeaders || {},
1103
+ COMMON_HTTP_HEADERS,
998
1104
  ),
999
1105
  };
1000
1106
 
@@ -1948,6 +2054,8 @@ export type GetProgramAccountsConfig = {
1948
2054
  dataSlice?: DataSlice;
1949
2055
  /** Optional array of filters to apply to accounts */
1950
2056
  filters?: GetProgramAccountsFilter[];
2057
+ /** The minimum slot that the request can be evaluated at */
2058
+ minContextSlot?: number;
1951
2059
  };
1952
2060
 
1953
2061
  /**
@@ -1958,6 +2066,8 @@ export type GetParsedProgramAccountsConfig = {
1958
2066
  commitment?: Commitment;
1959
2067
  /** Optional array of filters to apply to accounts */
1960
2068
  filters?: GetProgramAccountsFilter[];
2069
+ /** The minimum slot that the request can be evaluated at */
2070
+ minContextSlot?: number;
1961
2071
  };
1962
2072
 
1963
2073
  /**
@@ -1966,8 +2076,40 @@ export type GetParsedProgramAccountsConfig = {
1966
2076
  export type GetMultipleAccountsConfig = {
1967
2077
  /** Optional commitment level */
1968
2078
  commitment?: Commitment;
1969
- /** Optional encoding for account data (default base64) */
1970
- 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;
1971
2113
  };
1972
2114
 
1973
2115
  /**
@@ -2158,7 +2300,12 @@ export type ConfirmedSignatureInfo = {
2158
2300
  /**
2159
2301
  * An object defining headers to be passed to the RPC server
2160
2302
  */
2161
- export type HttpHeaders = {[header: string]: string};
2303
+ export type HttpHeaders = {
2304
+ [header: string]: string;
2305
+ } & {
2306
+ // Prohibited headers; for internal use only.
2307
+ 'solana-client'?: never;
2308
+ };
2162
2309
 
2163
2310
  /**
2164
2311
  * The type of the JavaScript `fetch()` API
@@ -2194,6 +2341,11 @@ export type ConnectionConfig = {
2194
2341
  confirmTransactionInitialTimeout?: number;
2195
2342
  };
2196
2343
 
2344
+ /** @internal */
2345
+ const COMMON_HTTP_HEADERS = {
2346
+ 'solana-client': `js/${process.env.npm_package_version ?? 'UNKNOWN'}`,
2347
+ };
2348
+
2197
2349
  /**
2198
2350
  * A connection to a fullnode JSON RPC endpoint
2199
2351
  */
@@ -2366,9 +2518,17 @@ export class Connection {
2366
2518
  */
2367
2519
  async getBalanceAndContext(
2368
2520
  publicKey: PublicKey,
2369
- commitment?: Commitment,
2521
+ commitmentOrConfig?: Commitment | GetBalanceConfig,
2370
2522
  ): Promise<RpcResponseAndContext<number>> {
2371
- 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
+ );
2372
2532
  const unsafeRes = await this._rpcRequest('getBalance', args);
2373
2533
  const res = create(unsafeRes, jsonRpcResultAndContext(number()));
2374
2534
  if ('error' in res) {
@@ -2387,9 +2547,9 @@ export class Connection {
2387
2547
  */
2388
2548
  async getBalance(
2389
2549
  publicKey: PublicKey,
2390
- commitment?: Commitment,
2550
+ commitmentOrConfig?: Commitment | GetBalanceConfig,
2391
2551
  ): Promise<number> {
2392
- return await this.getBalanceAndContext(publicKey, commitment)
2552
+ return await this.getBalanceAndContext(publicKey, commitmentOrConfig)
2393
2553
  .then(x => x.value)
2394
2554
  .catch(e => {
2395
2555
  throw new Error(
@@ -2511,12 +2671,14 @@ export class Connection {
2511
2671
  async getTokenAccountsByOwner(
2512
2672
  ownerAddress: PublicKey,
2513
2673
  filter: TokenAccountsFilter,
2514
- commitment?: Commitment,
2674
+ commitmentOrConfig?: Commitment | GetTokenAccountsByOwnerConfig,
2515
2675
  ): Promise<
2516
2676
  RpcResponseAndContext<
2517
2677
  Array<{pubkey: PublicKey; account: AccountInfo<Buffer>}>
2518
2678
  >
2519
2679
  > {
2680
+ const {commitment, config} =
2681
+ extractCommitmentFromConfig(commitmentOrConfig);
2520
2682
  let _args: any[] = [ownerAddress.toBase58()];
2521
2683
  if ('mint' in filter) {
2522
2684
  _args.push({mint: filter.mint.toBase58()});
@@ -2524,7 +2686,7 @@ export class Connection {
2524
2686
  _args.push({programId: filter.programId.toBase58()});
2525
2687
  }
2526
2688
 
2527
- const args = this._buildArgs(_args, commitment, 'base64');
2689
+ const args = this._buildArgs(_args, commitment, 'base64', config);
2528
2690
  const unsafeRes = await this._rpcRequest('getTokenAccountsByOwner', args);
2529
2691
  const res = create(unsafeRes, GetTokenAccountsByOwner);
2530
2692
  if ('error' in res) {
@@ -2616,9 +2778,16 @@ export class Connection {
2616
2778
  */
2617
2779
  async getAccountInfoAndContext(
2618
2780
  publicKey: PublicKey,
2619
- commitment?: Commitment,
2781
+ commitmentOrConfig?: Commitment | GetAccountInfoConfig,
2620
2782
  ): Promise<RpcResponseAndContext<AccountInfo<Buffer> | null>> {
2621
- const args = this._buildArgs([publicKey.toBase58()], commitment, 'base64');
2783
+ const {commitment, config} =
2784
+ extractCommitmentFromConfig(commitmentOrConfig);
2785
+ const args = this._buildArgs(
2786
+ [publicKey.toBase58()],
2787
+ commitment,
2788
+ 'base64',
2789
+ config,
2790
+ );
2622
2791
  const unsafeRes = await this._rpcRequest('getAccountInfo', args);
2623
2792
  const res = create(
2624
2793
  unsafeRes,
@@ -2670,10 +2839,13 @@ export class Connection {
2670
2839
  */
2671
2840
  async getAccountInfo(
2672
2841
  publicKey: PublicKey,
2673
- commitment?: Commitment,
2842
+ commitmentOrConfig?: Commitment | GetAccountInfoConfig,
2674
2843
  ): Promise<AccountInfo<Buffer> | null> {
2675
2844
  try {
2676
- const res = await this.getAccountInfoAndContext(publicKey, commitment);
2845
+ const res = await this.getAccountInfoAndContext(
2846
+ publicKey,
2847
+ commitmentOrConfig,
2848
+ );
2677
2849
  return res.value;
2678
2850
  } catch (e) {
2679
2851
  throw new Error(
@@ -2687,10 +2859,12 @@ export class Connection {
2687
2859
  */
2688
2860
  async getMultipleAccountsInfoAndContext(
2689
2861
  publicKeys: PublicKey[],
2690
- commitment?: Commitment,
2862
+ commitmentOrConfig?: Commitment | GetMultipleAccountsConfig,
2691
2863
  ): Promise<RpcResponseAndContext<(AccountInfo<Buffer> | null)[]>> {
2864
+ const {commitment, config} =
2865
+ extractCommitmentFromConfig(commitmentOrConfig);
2692
2866
  const keys = publicKeys.map(key => key.toBase58());
2693
- const args = this._buildArgs([keys], commitment, 'base64');
2867
+ const args = this._buildArgs([keys], commitment, 'base64', config);
2694
2868
  const unsafeRes = await this._rpcRequest('getMultipleAccounts', args);
2695
2869
  const res = create(
2696
2870
  unsafeRes,
@@ -2709,11 +2883,11 @@ export class Connection {
2709
2883
  */
2710
2884
  async getMultipleAccountsInfo(
2711
2885
  publicKeys: PublicKey[],
2712
- commitment?: Commitment,
2886
+ commitmentOrConfig?: Commitment | GetMultipleAccountsConfig,
2713
2887
  ): Promise<(AccountInfo<Buffer> | null)[]> {
2714
2888
  const res = await this.getMultipleAccountsInfoAndContext(
2715
2889
  publicKeys,
2716
- commitment,
2890
+ commitmentOrConfig,
2717
2891
  );
2718
2892
  return res.value;
2719
2893
  }
@@ -2723,14 +2897,19 @@ export class Connection {
2723
2897
  */
2724
2898
  async getStakeActivation(
2725
2899
  publicKey: PublicKey,
2726
- commitment?: Commitment,
2900
+ commitmentOrConfig?: Commitment | GetStakeActivationConfig,
2727
2901
  epoch?: number,
2728
2902
  ): Promise<StakeActivationData> {
2903
+ const {commitment, config} =
2904
+ extractCommitmentFromConfig(commitmentOrConfig);
2729
2905
  const args = this._buildArgs(
2730
2906
  [publicKey.toBase58()],
2731
2907
  commitment,
2732
- undefined,
2733
- epoch !== undefined ? {epoch} : undefined,
2908
+ undefined /* encoding */,
2909
+ {
2910
+ ...config,
2911
+ epoch: epoch != null ? epoch : config?.epoch,
2912
+ },
2734
2913
  );
2735
2914
 
2736
2915
  const unsafeRes = await this._rpcRequest('getStakeActivation', args);
@@ -2754,31 +2933,14 @@ export class Connection {
2754
2933
  programId: PublicKey,
2755
2934
  configOrCommitment?: GetProgramAccountsConfig | Commitment,
2756
2935
  ): Promise<Array<{pubkey: PublicKey; account: AccountInfo<Buffer>}>> {
2757
- const extra: Pick<GetProgramAccountsConfig, 'dataSlice' | 'filters'> = {};
2758
-
2759
- let commitment;
2760
- let encoding;
2761
- if (configOrCommitment) {
2762
- if (typeof configOrCommitment === 'string') {
2763
- commitment = configOrCommitment;
2764
- } else {
2765
- commitment = configOrCommitment.commitment;
2766
- encoding = configOrCommitment.encoding;
2767
-
2768
- if (configOrCommitment.dataSlice) {
2769
- extra.dataSlice = configOrCommitment.dataSlice;
2770
- }
2771
- if (configOrCommitment.filters) {
2772
- extra.filters = configOrCommitment.filters;
2773
- }
2774
- }
2775
- }
2776
-
2936
+ const {commitment, config} =
2937
+ extractCommitmentFromConfig(configOrCommitment);
2938
+ const {encoding, ...configWithoutEncoding} = config || {};
2777
2939
  const args = this._buildArgs(
2778
2940
  [programId.toBase58()],
2779
2941
  commitment,
2780
2942
  encoding || 'base64',
2781
- extra,
2943
+ configWithoutEncoding,
2782
2944
  );
2783
2945
  const unsafeRes = await this._rpcRequest('getProgramAccounts', args);
2784
2946
  const res = create(unsafeRes, jsonRpcResult(array(KeyedAccountInfoResult)));
@@ -2807,26 +2969,13 @@ export class Connection {
2807
2969
  account: AccountInfo<Buffer | ParsedAccountData>;
2808
2970
  }>
2809
2971
  > {
2810
- const extra: Pick<GetParsedProgramAccountsConfig, 'filters'> = {};
2811
-
2812
- let commitment;
2813
- if (configOrCommitment) {
2814
- if (typeof configOrCommitment === 'string') {
2815
- commitment = configOrCommitment;
2816
- } else {
2817
- commitment = configOrCommitment.commitment;
2818
-
2819
- if (configOrCommitment.filters) {
2820
- extra.filters = configOrCommitment.filters;
2821
- }
2822
- }
2823
- }
2824
-
2972
+ const {commitment, config} =
2973
+ extractCommitmentFromConfig(configOrCommitment);
2825
2974
  const args = this._buildArgs(
2826
2975
  [programId.toBase58()],
2827
2976
  commitment,
2828
2977
  'jsonParsed',
2829
- extra,
2978
+ config,
2830
2979
  );
2831
2980
  const unsafeRes = await this._rpcRequest('getProgramAccounts', args);
2832
2981
  const res = create(
@@ -3014,8 +3163,17 @@ export class Connection {
3014
3163
  /**
3015
3164
  * Fetch the current slot that the node is processing
3016
3165
  */
3017
- async getSlot(commitment?: Commitment): Promise<number> {
3018
- const args = this._buildArgs([], commitment);
3166
+ async getSlot(
3167
+ commitmentOrConfig?: Commitment | GetSlotConfig,
3168
+ ): Promise<number> {
3169
+ const {commitment, config} =
3170
+ extractCommitmentFromConfig(commitmentOrConfig);
3171
+ const args = this._buildArgs(
3172
+ [],
3173
+ commitment,
3174
+ undefined /* encoding */,
3175
+ config,
3176
+ );
3019
3177
  const unsafeRes = await this._rpcRequest('getSlot', args);
3020
3178
  const res = create(unsafeRes, jsonRpcResult(number()));
3021
3179
  if ('error' in res) {
@@ -3027,8 +3185,17 @@ export class Connection {
3027
3185
  /**
3028
3186
  * Fetch the current slot leader of the cluster
3029
3187
  */
3030
- async getSlotLeader(commitment?: Commitment): Promise<string> {
3031
- const args = this._buildArgs([], commitment);
3188
+ async getSlotLeader(
3189
+ commitmentOrConfig?: Commitment | GetSlotLeaderConfig,
3190
+ ): Promise<string> {
3191
+ const {commitment, config} =
3192
+ extractCommitmentFromConfig(commitmentOrConfig);
3193
+ const args = this._buildArgs(
3194
+ [],
3195
+ commitment,
3196
+ undefined /* encoding */,
3197
+ config,
3198
+ );
3032
3199
  const unsafeRes = await this._rpcRequest('getSlotLeader', args);
3033
3200
  const res = create(unsafeRes, jsonRpcResult(string()));
3034
3201
  if ('error' in res) {
@@ -3094,8 +3261,17 @@ export class Connection {
3094
3261
  /**
3095
3262
  * Fetch the current transaction count of the cluster
3096
3263
  */
3097
- async getTransactionCount(commitment?: Commitment): Promise<number> {
3098
- const args = this._buildArgs([], commitment);
3264
+ async getTransactionCount(
3265
+ commitmentOrConfig?: Commitment | GetTransactionCountConfig,
3266
+ ): Promise<number> {
3267
+ const {commitment, config} =
3268
+ extractCommitmentFromConfig(commitmentOrConfig);
3269
+ const args = this._buildArgs(
3270
+ [],
3271
+ commitment,
3272
+ undefined /* encoding */,
3273
+ config,
3274
+ );
3099
3275
  const unsafeRes = await this._rpcRequest('getTransactionCount', args);
3100
3276
  const res = create(unsafeRes, jsonRpcResult(number()));
3101
3277
  if ('error' in res) {
@@ -3138,14 +3314,17 @@ export class Connection {
3138
3314
  async getInflationReward(
3139
3315
  addresses: PublicKey[],
3140
3316
  epoch?: number,
3141
- commitment?: Commitment,
3317
+ commitmentOrConfig?: Commitment | GetInflationRewardConfig,
3142
3318
  ): Promise<(InflationReward | null)[]> {
3319
+ const {commitment, config} =
3320
+ extractCommitmentFromConfig(commitmentOrConfig);
3143
3321
  const args = this._buildArgs(
3144
3322
  [addresses.map(pubkey => pubkey.toBase58())],
3145
3323
  commitment,
3146
- undefined,
3324
+ undefined /* encoding */,
3147
3325
  {
3148
- epoch,
3326
+ ...config,
3327
+ epoch: epoch != null ? epoch : config?.epoch,
3149
3328
  },
3150
3329
  );
3151
3330
  const unsafeRes = await this._rpcRequest('getInflationReward', args);
@@ -3159,8 +3338,17 @@ export class Connection {
3159
3338
  /**
3160
3339
  * Fetch the Epoch Info parameters
3161
3340
  */
3162
- async getEpochInfo(commitment?: Commitment): Promise<EpochInfo> {
3163
- const args = this._buildArgs([], commitment);
3341
+ async getEpochInfo(
3342
+ commitmentOrConfig?: Commitment | GetEpochInfoConfig,
3343
+ ): Promise<EpochInfo> {
3344
+ const {commitment, config} =
3345
+ extractCommitmentFromConfig(commitmentOrConfig);
3346
+ const args = this._buildArgs(
3347
+ [],
3348
+ commitment,
3349
+ undefined /* encoding */,
3350
+ config,
3351
+ );
3164
3352
  const unsafeRes = await this._rpcRequest('getEpochInfo', args);
3165
3353
  const res = create(unsafeRes, GetEpochInfoRpcResult);
3166
3354
  if ('error' in res) {
@@ -3333,10 +3521,10 @@ export class Connection {
3333
3521
  * @return {Promise<BlockhashWithExpiryBlockHeight>}
3334
3522
  */
3335
3523
  async getLatestBlockhash(
3336
- commitment?: Commitment,
3524
+ commitmentOrConfig?: Commitment | GetLatestBlockhashConfig,
3337
3525
  ): Promise<BlockhashWithExpiryBlockHeight> {
3338
3526
  try {
3339
- const res = await this.getLatestBlockhashAndContext(commitment);
3527
+ const res = await this.getLatestBlockhashAndContext(commitmentOrConfig);
3340
3528
  return res.value;
3341
3529
  } catch (e) {
3342
3530
  throw new Error('failed to get recent blockhash: ' + e);
@@ -3348,9 +3536,16 @@ export class Connection {
3348
3536
  * @return {Promise<BlockhashWithExpiryBlockHeight>}
3349
3537
  */
3350
3538
  async getLatestBlockhashAndContext(
3351
- commitment?: Commitment,
3539
+ commitmentOrConfig?: Commitment | GetLatestBlockhashConfig,
3352
3540
  ): Promise<RpcResponseAndContext<BlockhashWithExpiryBlockHeight>> {
3353
- const args = this._buildArgs([], commitment);
3541
+ const {commitment, config} =
3542
+ extractCommitmentFromConfig(commitmentOrConfig);
3543
+ const args = this._buildArgs(
3544
+ [],
3545
+ commitment,
3546
+ undefined /* encoding */,
3547
+ config,
3548
+ );
3354
3549
  const unsafeRes = await this._rpcRequest('getLatestBlockhash', args);
3355
3550
  const res = create(unsafeRes, GetLatestBlockhashRpcResult);
3356
3551
  if ('error' in res) {
@@ -3422,8 +3617,17 @@ export class Connection {
3422
3617
  /*
3423
3618
  * Returns the current block height of the node
3424
3619
  */
3425
- async getBlockHeight(commitment?: Commitment): Promise<number> {
3426
- const args = this._buildArgs([], commitment);
3620
+ async getBlockHeight(
3621
+ commitmentOrConfig?: Commitment | GetBlockHeightConfig,
3622
+ ): Promise<number> {
3623
+ const {commitment, config} =
3624
+ extractCommitmentFromConfig(commitmentOrConfig);
3625
+ const args = this._buildArgs(
3626
+ [],
3627
+ commitment,
3628
+ undefined /* encoding */,
3629
+ config,
3630
+ );
3427
3631
  const unsafeRes = await this._rpcRequest('getBlockHeight', args);
3428
3632
  const res = create(unsafeRes, jsonRpcResult(number()));
3429
3633
  if ('error' in res) {
@@ -4239,6 +4443,9 @@ export class Connection {
4239
4443
  if (options && options.maxRetries) {
4240
4444
  config.maxRetries = options.maxRetries;
4241
4445
  }
4446
+ if (options && options.minContextSlot != null) {
4447
+ config.minContextSlot = options.minContextSlot;
4448
+ }
4242
4449
  if (skipPreflight) {
4243
4450
  config.skipPreflight = skipPreflight;
4244
4451
  }