@solana/web3.js 1.44.3 → 1.47.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/lib/index.iife.js CHANGED
@@ -14764,7 +14764,8 @@ var solanaWeb3 = (function (exports) {
14764
14764
  const sendOptions = options && {
14765
14765
  skipPreflight: options.skipPreflight,
14766
14766
  preflightCommitment: options.preflightCommitment || options.commitment,
14767
- maxRetries: options.maxRetries
14767
+ maxRetries: options.maxRetries,
14768
+ minContextSlot: options.minContextSlot
14768
14769
  };
14769
14770
  const signature = await connection.sendTransaction(transaction, signers, sendOptions);
14770
14771
  const status = transaction.recentBlockhash != null && transaction.lastValidBlockHeight != null ? (await connection.confirmTransaction({
@@ -19356,6 +19357,41 @@ var solanaWeb3 = (function (exports) {
19356
19357
  this.logs = logs;
19357
19358
  }
19358
19359
 
19360
+ } // Keep in sync with client/src/rpc_custom_errors.rs
19361
+ // Typescript `enums` thwart tree-shaking. See https://bargsten.org/jsts/enums/
19362
+
19363
+ const SolanaJSONRPCErrorCode = {
19364
+ JSON_RPC_SERVER_ERROR_BLOCK_CLEANED_UP: -32001,
19365
+ JSON_RPC_SERVER_ERROR_SEND_TRANSACTION_PREFLIGHT_FAILURE: -32002,
19366
+ JSON_RPC_SERVER_ERROR_TRANSACTION_SIGNATURE_VERIFICATION_FAILURE: -32003,
19367
+ JSON_RPC_SERVER_ERROR_BLOCK_NOT_AVAILABLE: -32004,
19368
+ JSON_RPC_SERVER_ERROR_NODE_UNHEALTHY: -32005,
19369
+ JSON_RPC_SERVER_ERROR_TRANSACTION_PRECOMPILE_VERIFICATION_FAILURE: -32006,
19370
+ JSON_RPC_SERVER_ERROR_SLOT_SKIPPED: -32007,
19371
+ JSON_RPC_SERVER_ERROR_NO_SNAPSHOT: -32008,
19372
+ JSON_RPC_SERVER_ERROR_LONG_TERM_STORAGE_SLOT_SKIPPED: -32009,
19373
+ JSON_RPC_SERVER_ERROR_KEY_EXCLUDED_FROM_SECONDARY_INDEX: -32010,
19374
+ JSON_RPC_SERVER_ERROR_TRANSACTION_HISTORY_NOT_AVAILABLE: -32011,
19375
+ JSON_RPC_SCAN_ERROR: -32012,
19376
+ JSON_RPC_SERVER_ERROR_TRANSACTION_SIGNATURE_LEN_MISMATCH: -32013,
19377
+ JSON_RPC_SERVER_ERROR_BLOCK_STATUS_NOT_AVAILABLE_YET: -32014,
19378
+ JSON_RPC_SERVER_ERROR_UNSUPPORTED_TRANSACTION_VERSION: -32015,
19379
+ JSON_RPC_SERVER_ERROR_MIN_CONTEXT_SLOT_NOT_REACHED: -32016
19380
+ };
19381
+ class SolanaJSONRPCError extends Error {
19382
+ constructor({
19383
+ code,
19384
+ message,
19385
+ data
19386
+ }, customMessage) {
19387
+ super(customMessage != null ? `${customMessage}: ${message}` : message);
19388
+ this.code = void 0;
19389
+ this.data = void 0;
19390
+ this.code = code;
19391
+ this.data = data;
19392
+ this.name = 'SolanaJSONRPCError';
19393
+ }
19394
+
19359
19395
  }
19360
19396
 
19361
19397
  var fetchImpl = globalThis.fetch;
@@ -19424,6 +19460,7 @@ var solanaWeb3 = (function (exports) {
19424
19460
  return url.toString();
19425
19461
  }
19426
19462
 
19463
+ var _process$env$npm_pack;
19427
19464
  const PublicKeyFromString = coerce(instance(PublicKey), string(), value => new PublicKey(value));
19428
19465
  const RawAccountDataResult = tuple([string(), literal('base64')]);
19429
19466
  const BufferFromRawAccountData = coerce(instance(buffer.Buffer), RawAccountDataResult, value => buffer.Buffer.from(value[0], 'base64'));
@@ -19440,9 +19477,32 @@ var solanaWeb3 = (function (exports) {
19440
19477
  * https://gist.github.com/steveluscher/c057eca81d479ef705cdb53162f9971d
19441
19478
  */
19442
19479
 
19480
+ /** @internal */
19481
+ function extractCommitmentFromConfig(commitmentOrConfig) {
19482
+ let commitment;
19483
+ let config;
19484
+
19485
+ if (typeof commitmentOrConfig === 'string') {
19486
+ commitment = commitmentOrConfig;
19487
+ } else if (commitmentOrConfig) {
19488
+ const {
19489
+ commitment: specifiedCommitment,
19490
+ ...specifiedConfig
19491
+ } = commitmentOrConfig;
19492
+ commitment = specifiedCommitment;
19493
+ config = specifiedConfig;
19494
+ }
19495
+
19496
+ return {
19497
+ commitment,
19498
+ config
19499
+ };
19500
+ }
19443
19501
  /**
19444
19502
  * @internal
19445
19503
  */
19504
+
19505
+
19446
19506
  function createRpcResult(result) {
19447
19507
  return union([type({
19448
19508
  jsonrpc: literal('2.0'),
@@ -19634,7 +19694,7 @@ var solanaWeb3 = (function (exports) {
19634
19694
  agent,
19635
19695
  headers: Object.assign({
19636
19696
  'Content-Type': 'application/json'
19637
- }, httpHeaders || {})
19697
+ }, httpHeaders || {}, COMMON_HTTP_HEADERS)
19638
19698
  };
19639
19699
 
19640
19700
  try {
@@ -20307,9 +20367,14 @@ var solanaWeb3 = (function (exports) {
20307
20367
  * Filter for log subscriptions.
20308
20368
  */
20309
20369
 
20370
+ /** @internal */
20371
+ const COMMON_HTTP_HEADERS = {
20372
+ 'solana-client': `js/${(_process$env$npm_pack = "0.0.0-development") !== null && _process$env$npm_pack !== void 0 ? _process$env$npm_pack : 'UNKNOWN'}`
20373
+ };
20310
20374
  /**
20311
20375
  * A connection to a fullnode JSON RPC endpoint
20312
20376
  */
20377
+
20313
20378
  class Connection {
20314
20379
  /** @internal */
20315
20380
 
@@ -20474,14 +20539,22 @@ var solanaWeb3 = (function (exports) {
20474
20539
  */
20475
20540
 
20476
20541
 
20477
- async getBalanceAndContext(publicKey, commitment) {
20478
- const args = this._buildArgs([publicKey.toBase58()], commitment);
20542
+ async getBalanceAndContext(publicKey, commitmentOrConfig) {
20543
+ /** @internal */
20544
+ const {
20545
+ commitment,
20546
+ config
20547
+ } = extractCommitmentFromConfig(commitmentOrConfig);
20548
+
20549
+ const args = this._buildArgs([publicKey.toBase58()], commitment, undefined
20550
+ /* encoding */
20551
+ , config);
20479
20552
 
20480
20553
  const unsafeRes = await this._rpcRequest('getBalance', args);
20481
20554
  const res = create(unsafeRes, jsonRpcResultAndContext(number()));
20482
20555
 
20483
20556
  if ('error' in res) {
20484
- throw new Error('failed to get balance for ' + publicKey.toBase58() + ': ' + res.error.message);
20557
+ throw new SolanaJSONRPCError(res.error, `failed to get balance for ${publicKey.toBase58()}`);
20485
20558
  }
20486
20559
 
20487
20560
  return res.result;
@@ -20491,8 +20564,8 @@ var solanaWeb3 = (function (exports) {
20491
20564
  */
20492
20565
 
20493
20566
 
20494
- async getBalance(publicKey, commitment) {
20495
- return await this.getBalanceAndContext(publicKey, commitment).then(x => x.value).catch(e => {
20567
+ async getBalance(publicKey, commitmentOrConfig) {
20568
+ return await this.getBalanceAndContext(publicKey, commitmentOrConfig).then(x => x.value).catch(e => {
20496
20569
  throw new Error('failed to get balance of account ' + publicKey.toBase58() + ': ' + e);
20497
20570
  });
20498
20571
  }
@@ -20506,7 +20579,7 @@ var solanaWeb3 = (function (exports) {
20506
20579
  const res = create(unsafeRes, jsonRpcResult(nullable(number())));
20507
20580
 
20508
20581
  if ('error' in res) {
20509
- throw new Error('failed to get block time for slot ' + slot + ': ' + res.error.message);
20582
+ throw new SolanaJSONRPCError(res.error, `failed to get block time for slot ${slot}`);
20510
20583
  }
20511
20584
 
20512
20585
  return res.result;
@@ -20522,7 +20595,7 @@ var solanaWeb3 = (function (exports) {
20522
20595
  const res = create(unsafeRes, jsonRpcResult(number()));
20523
20596
 
20524
20597
  if ('error' in res) {
20525
- throw new Error('failed to get minimum ledger slot: ' + res.error.message);
20598
+ throw new SolanaJSONRPCError(res.error, 'failed to get minimum ledger slot');
20526
20599
  }
20527
20600
 
20528
20601
  return res.result;
@@ -20537,7 +20610,7 @@ var solanaWeb3 = (function (exports) {
20537
20610
  const res = create(unsafeRes, SlotRpcResult);
20538
20611
 
20539
20612
  if ('error' in res) {
20540
- throw new Error('failed to get first available block: ' + res.error.message);
20613
+ throw new SolanaJSONRPCError(res.error, 'failed to get first available block');
20541
20614
  }
20542
20615
 
20543
20616
  return res.result;
@@ -20568,7 +20641,7 @@ var solanaWeb3 = (function (exports) {
20568
20641
  const res = create(unsafeRes, GetSupplyRpcResult);
20569
20642
 
20570
20643
  if ('error' in res) {
20571
- throw new Error('failed to get supply: ' + res.error.message);
20644
+ throw new SolanaJSONRPCError(res.error, 'failed to get supply');
20572
20645
  }
20573
20646
 
20574
20647
  return res.result;
@@ -20585,7 +20658,7 @@ var solanaWeb3 = (function (exports) {
20585
20658
  const res = create(unsafeRes, jsonRpcResultAndContext(TokenAmountResult));
20586
20659
 
20587
20660
  if ('error' in res) {
20588
- throw new Error('failed to get token supply: ' + res.error.message);
20661
+ throw new SolanaJSONRPCError(res.error, 'failed to get token supply');
20589
20662
  }
20590
20663
 
20591
20664
  return res.result;
@@ -20602,7 +20675,7 @@ var solanaWeb3 = (function (exports) {
20602
20675
  const res = create(unsafeRes, jsonRpcResultAndContext(TokenAmountResult));
20603
20676
 
20604
20677
  if ('error' in res) {
20605
- throw new Error('failed to get token account balance: ' + res.error.message);
20678
+ throw new SolanaJSONRPCError(res.error, 'failed to get token account balance');
20606
20679
  }
20607
20680
 
20608
20681
  return res.result;
@@ -20614,7 +20687,11 @@ var solanaWeb3 = (function (exports) {
20614
20687
  */
20615
20688
 
20616
20689
 
20617
- async getTokenAccountsByOwner(ownerAddress, filter, commitment) {
20690
+ async getTokenAccountsByOwner(ownerAddress, filter, commitmentOrConfig) {
20691
+ const {
20692
+ commitment,
20693
+ config
20694
+ } = extractCommitmentFromConfig(commitmentOrConfig);
20618
20695
  let _args = [ownerAddress.toBase58()];
20619
20696
 
20620
20697
  if ('mint' in filter) {
@@ -20627,13 +20704,13 @@ var solanaWeb3 = (function (exports) {
20627
20704
  });
20628
20705
  }
20629
20706
 
20630
- const args = this._buildArgs(_args, commitment, 'base64');
20707
+ const args = this._buildArgs(_args, commitment, 'base64', config);
20631
20708
 
20632
20709
  const unsafeRes = await this._rpcRequest('getTokenAccountsByOwner', args);
20633
20710
  const res = create(unsafeRes, GetTokenAccountsByOwner);
20634
20711
 
20635
20712
  if ('error' in res) {
20636
- throw new Error('failed to get token accounts owned by account ' + ownerAddress.toBase58() + ': ' + res.error.message);
20713
+ throw new SolanaJSONRPCError(res.error, `failed to get token accounts owned by account ${ownerAddress.toBase58()}`);
20637
20714
  }
20638
20715
 
20639
20716
  return res.result;
@@ -20664,7 +20741,7 @@ var solanaWeb3 = (function (exports) {
20664
20741
  const res = create(unsafeRes, GetParsedTokenAccountsByOwner);
20665
20742
 
20666
20743
  if ('error' in res) {
20667
- throw new Error('failed to get token accounts owned by account ' + ownerAddress.toBase58() + ': ' + res.error.message);
20744
+ throw new SolanaJSONRPCError(res.error, `failed to get token accounts owned by account ${ownerAddress.toBase58()}`);
20668
20745
  }
20669
20746
 
20670
20747
  return res.result;
@@ -20683,7 +20760,7 @@ var solanaWeb3 = (function (exports) {
20683
20760
  const res = create(unsafeRes, GetLargestAccountsRpcResult);
20684
20761
 
20685
20762
  if ('error' in res) {
20686
- throw new Error('failed to get largest accounts: ' + res.error.message);
20763
+ throw new SolanaJSONRPCError(res.error, 'failed to get largest accounts');
20687
20764
  }
20688
20765
 
20689
20766
  return res.result;
@@ -20701,7 +20778,7 @@ var solanaWeb3 = (function (exports) {
20701
20778
  const res = create(unsafeRes, GetTokenLargestAccountsResult);
20702
20779
 
20703
20780
  if ('error' in res) {
20704
- throw new Error('failed to get token largest accounts: ' + res.error.message);
20781
+ throw new SolanaJSONRPCError(res.error, 'failed to get token largest accounts');
20705
20782
  }
20706
20783
 
20707
20784
  return res.result;
@@ -20711,14 +20788,19 @@ var solanaWeb3 = (function (exports) {
20711
20788
  */
20712
20789
 
20713
20790
 
20714
- async getAccountInfoAndContext(publicKey, commitment) {
20715
- const args = this._buildArgs([publicKey.toBase58()], commitment, 'base64');
20791
+ async getAccountInfoAndContext(publicKey, commitmentOrConfig) {
20792
+ const {
20793
+ commitment,
20794
+ config
20795
+ } = extractCommitmentFromConfig(commitmentOrConfig);
20796
+
20797
+ const args = this._buildArgs([publicKey.toBase58()], commitment, 'base64', config);
20716
20798
 
20717
20799
  const unsafeRes = await this._rpcRequest('getAccountInfo', args);
20718
20800
  const res = create(unsafeRes, jsonRpcResultAndContext(nullable(AccountInfoResult)));
20719
20801
 
20720
20802
  if ('error' in res) {
20721
- throw new Error('failed to get info about account ' + publicKey.toBase58() + ': ' + res.error.message);
20803
+ throw new SolanaJSONRPCError(res.error, `failed to get info about account ${publicKey.toBase58()}`);
20722
20804
  }
20723
20805
 
20724
20806
  return res.result;
@@ -20735,7 +20817,7 @@ var solanaWeb3 = (function (exports) {
20735
20817
  const res = create(unsafeRes, jsonRpcResultAndContext(nullable(ParsedAccountInfoResult)));
20736
20818
 
20737
20819
  if ('error' in res) {
20738
- throw new Error('failed to get info about account ' + publicKey.toBase58() + ': ' + res.error.message);
20820
+ throw new SolanaJSONRPCError(res.error, `failed to get info about account ${publicKey.toBase58()}`);
20739
20821
  }
20740
20822
 
20741
20823
  return res.result;
@@ -20745,9 +20827,9 @@ var solanaWeb3 = (function (exports) {
20745
20827
  */
20746
20828
 
20747
20829
 
20748
- async getAccountInfo(publicKey, commitment) {
20830
+ async getAccountInfo(publicKey, commitmentOrConfig) {
20749
20831
  try {
20750
- const res = await this.getAccountInfoAndContext(publicKey, commitment);
20832
+ const res = await this.getAccountInfoAndContext(publicKey, commitmentOrConfig);
20751
20833
  return res.value;
20752
20834
  } catch (e) {
20753
20835
  throw new Error('failed to get info about account ' + publicKey.toBase58() + ': ' + e);
@@ -20758,16 +20840,20 @@ var solanaWeb3 = (function (exports) {
20758
20840
  */
20759
20841
 
20760
20842
 
20761
- async getMultipleAccountsInfoAndContext(publicKeys, commitment) {
20843
+ async getMultipleAccountsInfoAndContext(publicKeys, commitmentOrConfig) {
20844
+ const {
20845
+ commitment,
20846
+ config
20847
+ } = extractCommitmentFromConfig(commitmentOrConfig);
20762
20848
  const keys = publicKeys.map(key => key.toBase58());
20763
20849
 
20764
- const args = this._buildArgs([keys], commitment, 'base64');
20850
+ const args = this._buildArgs([keys], commitment, 'base64', config);
20765
20851
 
20766
20852
  const unsafeRes = await this._rpcRequest('getMultipleAccounts', args);
20767
20853
  const res = create(unsafeRes, jsonRpcResultAndContext(array(nullable(AccountInfoResult))));
20768
20854
 
20769
20855
  if ('error' in res) {
20770
- throw new Error('failed to get info for accounts ' + keys + ': ' + res.error.message);
20856
+ throw new SolanaJSONRPCError(res.error, `failed to get info for accounts ${keys}`);
20771
20857
  }
20772
20858
 
20773
20859
  return res.result;
@@ -20777,8 +20863,8 @@ var solanaWeb3 = (function (exports) {
20777
20863
  */
20778
20864
 
20779
20865
 
20780
- async getMultipleAccountsInfo(publicKeys, commitment) {
20781
- const res = await this.getMultipleAccountsInfoAndContext(publicKeys, commitment);
20866
+ async getMultipleAccountsInfo(publicKeys, commitmentOrConfig) {
20867
+ const res = await this.getMultipleAccountsInfoAndContext(publicKeys, commitmentOrConfig);
20782
20868
  return res.value;
20783
20869
  }
20784
20870
  /**
@@ -20786,16 +20872,23 @@ var solanaWeb3 = (function (exports) {
20786
20872
  */
20787
20873
 
20788
20874
 
20789
- async getStakeActivation(publicKey, commitment, epoch) {
20790
- const args = this._buildArgs([publicKey.toBase58()], commitment, undefined, epoch !== undefined ? {
20791
- epoch
20792
- } : undefined);
20875
+ async getStakeActivation(publicKey, commitmentOrConfig, epoch) {
20876
+ const {
20877
+ commitment,
20878
+ config
20879
+ } = extractCommitmentFromConfig(commitmentOrConfig);
20880
+
20881
+ const args = this._buildArgs([publicKey.toBase58()], commitment, undefined
20882
+ /* encoding */
20883
+ , { ...config,
20884
+ epoch: epoch != null ? epoch : config === null || config === void 0 ? void 0 : config.epoch
20885
+ });
20793
20886
 
20794
20887
  const unsafeRes = await this._rpcRequest('getStakeActivation', args);
20795
20888
  const res = create(unsafeRes, jsonRpcResult(StakeActivationResult));
20796
20889
 
20797
20890
  if ('error' in res) {
20798
- throw new Error(`failed to get Stake Activation ${publicKey.toBase58()}: ${res.error.message}`);
20891
+ throw new SolanaJSONRPCError(res.error, `failed to get Stake Activation ${publicKey.toBase58()}`);
20799
20892
  }
20800
20893
 
20801
20894
  return res.result;
@@ -20808,34 +20901,22 @@ var solanaWeb3 = (function (exports) {
20808
20901
 
20809
20902
 
20810
20903
  async getProgramAccounts(programId, configOrCommitment) {
20811
- const extra = {};
20812
- let commitment;
20813
- let encoding;
20814
-
20815
- if (configOrCommitment) {
20816
- if (typeof configOrCommitment === 'string') {
20817
- commitment = configOrCommitment;
20818
- } else {
20819
- commitment = configOrCommitment.commitment;
20820
- encoding = configOrCommitment.encoding;
20821
-
20822
- if (configOrCommitment.dataSlice) {
20823
- extra.dataSlice = configOrCommitment.dataSlice;
20824
- }
20825
-
20826
- if (configOrCommitment.filters) {
20827
- extra.filters = configOrCommitment.filters;
20828
- }
20829
- }
20830
- }
20904
+ const {
20905
+ commitment,
20906
+ config
20907
+ } = extractCommitmentFromConfig(configOrCommitment);
20908
+ const {
20909
+ encoding,
20910
+ ...configWithoutEncoding
20911
+ } = config || {};
20831
20912
 
20832
- const args = this._buildArgs([programId.toBase58()], commitment, encoding || 'base64', extra);
20913
+ const args = this._buildArgs([programId.toBase58()], commitment, encoding || 'base64', configWithoutEncoding);
20833
20914
 
20834
20915
  const unsafeRes = await this._rpcRequest('getProgramAccounts', args);
20835
20916
  const res = create(unsafeRes, jsonRpcResult(array(KeyedAccountInfoResult)));
20836
20917
 
20837
20918
  if ('error' in res) {
20838
- throw new Error('failed to get accounts owned by program ' + programId.toBase58() + ': ' + res.error.message);
20919
+ throw new SolanaJSONRPCError(res.error, `failed to get accounts owned by program ${programId.toBase58()}`);
20839
20920
  }
20840
20921
 
20841
20922
  return res.result;
@@ -20848,28 +20929,18 @@ var solanaWeb3 = (function (exports) {
20848
20929
 
20849
20930
 
20850
20931
  async getParsedProgramAccounts(programId, configOrCommitment) {
20851
- const extra = {};
20852
- let commitment;
20853
-
20854
- if (configOrCommitment) {
20855
- if (typeof configOrCommitment === 'string') {
20856
- commitment = configOrCommitment;
20857
- } else {
20858
- commitment = configOrCommitment.commitment;
20859
-
20860
- if (configOrCommitment.filters) {
20861
- extra.filters = configOrCommitment.filters;
20862
- }
20863
- }
20864
- }
20932
+ const {
20933
+ commitment,
20934
+ config
20935
+ } = extractCommitmentFromConfig(configOrCommitment);
20865
20936
 
20866
- const args = this._buildArgs([programId.toBase58()], commitment, 'jsonParsed', extra);
20937
+ const args = this._buildArgs([programId.toBase58()], commitment, 'jsonParsed', config);
20867
20938
 
20868
20939
  const unsafeRes = await this._rpcRequest('getProgramAccounts', args);
20869
20940
  const res = create(unsafeRes, jsonRpcResult(array(KeyedParsedAccountInfoResult)));
20870
20941
 
20871
20942
  if ('error' in res) {
20872
- throw new Error('failed to get accounts owned by program ' + programId.toBase58() + ': ' + res.error.message);
20943
+ throw new SolanaJSONRPCError(res.error, `failed to get accounts owned by program ${programId.toBase58()}`);
20873
20944
  }
20874
20945
 
20875
20946
  return res.result;
@@ -21003,7 +21074,7 @@ var solanaWeb3 = (function (exports) {
21003
21074
  const res = create(unsafeRes, jsonRpcResult(array(ContactInfoResult)));
21004
21075
 
21005
21076
  if ('error' in res) {
21006
- throw new Error('failed to get cluster nodes: ' + res.error.message);
21077
+ throw new SolanaJSONRPCError(res.error, 'failed to get cluster nodes');
21007
21078
  }
21008
21079
 
21009
21080
  return res.result;
@@ -21020,7 +21091,7 @@ var solanaWeb3 = (function (exports) {
21020
21091
  const res = create(unsafeRes, GetVoteAccounts);
21021
21092
 
21022
21093
  if ('error' in res) {
21023
- throw new Error('failed to get vote accounts: ' + res.error.message);
21094
+ throw new SolanaJSONRPCError(res.error, 'failed to get vote accounts');
21024
21095
  }
21025
21096
 
21026
21097
  return res.result;
@@ -21030,14 +21101,21 @@ var solanaWeb3 = (function (exports) {
21030
21101
  */
21031
21102
 
21032
21103
 
21033
- async getSlot(commitment) {
21034
- const args = this._buildArgs([], commitment);
21104
+ async getSlot(commitmentOrConfig) {
21105
+ const {
21106
+ commitment,
21107
+ config
21108
+ } = extractCommitmentFromConfig(commitmentOrConfig);
21109
+
21110
+ const args = this._buildArgs([], commitment, undefined
21111
+ /* encoding */
21112
+ , config);
21035
21113
 
21036
21114
  const unsafeRes = await this._rpcRequest('getSlot', args);
21037
21115
  const res = create(unsafeRes, jsonRpcResult(number()));
21038
21116
 
21039
21117
  if ('error' in res) {
21040
- throw new Error('failed to get slot: ' + res.error.message);
21118
+ throw new SolanaJSONRPCError(res.error, 'failed to get slot');
21041
21119
  }
21042
21120
 
21043
21121
  return res.result;
@@ -21047,14 +21125,21 @@ var solanaWeb3 = (function (exports) {
21047
21125
  */
21048
21126
 
21049
21127
 
21050
- async getSlotLeader(commitment) {
21051
- const args = this._buildArgs([], commitment);
21128
+ async getSlotLeader(commitmentOrConfig) {
21129
+ const {
21130
+ commitment,
21131
+ config
21132
+ } = extractCommitmentFromConfig(commitmentOrConfig);
21133
+
21134
+ const args = this._buildArgs([], commitment, undefined
21135
+ /* encoding */
21136
+ , config);
21052
21137
 
21053
21138
  const unsafeRes = await this._rpcRequest('getSlotLeader', args);
21054
21139
  const res = create(unsafeRes, jsonRpcResult(string()));
21055
21140
 
21056
21141
  if ('error' in res) {
21057
- throw new Error('failed to get slot leader: ' + res.error.message);
21142
+ throw new SolanaJSONRPCError(res.error, 'failed to get slot leader');
21058
21143
  }
21059
21144
 
21060
21145
  return res.result;
@@ -21073,7 +21158,7 @@ var solanaWeb3 = (function (exports) {
21073
21158
  const res = create(unsafeRes, jsonRpcResult(array(PublicKeyFromString)));
21074
21159
 
21075
21160
  if ('error' in res) {
21076
- throw new Error('failed to get slot leaders: ' + res.error.message);
21161
+ throw new SolanaJSONRPCError(res.error, 'failed to get slot leaders');
21077
21162
  }
21078
21163
 
21079
21164
  return res.result;
@@ -21111,7 +21196,7 @@ var solanaWeb3 = (function (exports) {
21111
21196
  const res = create(unsafeRes, GetSignatureStatusesRpcResult);
21112
21197
 
21113
21198
  if ('error' in res) {
21114
- throw new Error('failed to get signature status: ' + res.error.message);
21199
+ throw new SolanaJSONRPCError(res.error, 'failed to get signature status');
21115
21200
  }
21116
21201
 
21117
21202
  return res.result;
@@ -21121,14 +21206,21 @@ var solanaWeb3 = (function (exports) {
21121
21206
  */
21122
21207
 
21123
21208
 
21124
- async getTransactionCount(commitment) {
21125
- const args = this._buildArgs([], commitment);
21209
+ async getTransactionCount(commitmentOrConfig) {
21210
+ const {
21211
+ commitment,
21212
+ config
21213
+ } = extractCommitmentFromConfig(commitmentOrConfig);
21214
+
21215
+ const args = this._buildArgs([], commitment, undefined
21216
+ /* encoding */
21217
+ , config);
21126
21218
 
21127
21219
  const unsafeRes = await this._rpcRequest('getTransactionCount', args);
21128
21220
  const res = create(unsafeRes, jsonRpcResult(number()));
21129
21221
 
21130
21222
  if ('error' in res) {
21131
- throw new Error('failed to get transaction count: ' + res.error.message);
21223
+ throw new SolanaJSONRPCError(res.error, 'failed to get transaction count');
21132
21224
  }
21133
21225
 
21134
21226
  return res.result;
@@ -21159,7 +21251,7 @@ var solanaWeb3 = (function (exports) {
21159
21251
  const res = create(unsafeRes, GetInflationGovernorRpcResult);
21160
21252
 
21161
21253
  if ('error' in res) {
21162
- throw new Error('failed to get inflation: ' + res.error.message);
21254
+ throw new SolanaJSONRPCError(res.error, 'failed to get inflation');
21163
21255
  }
21164
21256
 
21165
21257
  return res.result;
@@ -21169,16 +21261,23 @@ var solanaWeb3 = (function (exports) {
21169
21261
  */
21170
21262
 
21171
21263
 
21172
- async getInflationReward(addresses, epoch, commitment) {
21173
- const args = this._buildArgs([addresses.map(pubkey => pubkey.toBase58())], commitment, undefined, {
21174
- epoch
21264
+ async getInflationReward(addresses, epoch, commitmentOrConfig) {
21265
+ const {
21266
+ commitment,
21267
+ config
21268
+ } = extractCommitmentFromConfig(commitmentOrConfig);
21269
+
21270
+ const args = this._buildArgs([addresses.map(pubkey => pubkey.toBase58())], commitment, undefined
21271
+ /* encoding */
21272
+ , { ...config,
21273
+ epoch: epoch != null ? epoch : config === null || config === void 0 ? void 0 : config.epoch
21175
21274
  });
21176
21275
 
21177
21276
  const unsafeRes = await this._rpcRequest('getInflationReward', args);
21178
21277
  const res = create(unsafeRes, GetInflationRewardResult);
21179
21278
 
21180
21279
  if ('error' in res) {
21181
- throw new Error('failed to get inflation reward: ' + res.error.message);
21280
+ throw new SolanaJSONRPCError(res.error, 'failed to get inflation reward');
21182
21281
  }
21183
21282
 
21184
21283
  return res.result;
@@ -21188,14 +21287,21 @@ var solanaWeb3 = (function (exports) {
21188
21287
  */
21189
21288
 
21190
21289
 
21191
- async getEpochInfo(commitment) {
21192
- const args = this._buildArgs([], commitment);
21290
+ async getEpochInfo(commitmentOrConfig) {
21291
+ const {
21292
+ commitment,
21293
+ config
21294
+ } = extractCommitmentFromConfig(commitmentOrConfig);
21295
+
21296
+ const args = this._buildArgs([], commitment, undefined
21297
+ /* encoding */
21298
+ , config);
21193
21299
 
21194
21300
  const unsafeRes = await this._rpcRequest('getEpochInfo', args);
21195
21301
  const res = create(unsafeRes, GetEpochInfoRpcResult);
21196
21302
 
21197
21303
  if ('error' in res) {
21198
- throw new Error('failed to get epoch info: ' + res.error.message);
21304
+ throw new SolanaJSONRPCError(res.error, 'failed to get epoch info');
21199
21305
  }
21200
21306
 
21201
21307
  return res.result;
@@ -21210,7 +21316,7 @@ var solanaWeb3 = (function (exports) {
21210
21316
  const res = create(unsafeRes, GetEpochScheduleRpcResult);
21211
21317
 
21212
21318
  if ('error' in res) {
21213
- throw new Error('failed to get epoch schedule: ' + res.error.message);
21319
+ throw new SolanaJSONRPCError(res.error, 'failed to get epoch schedule');
21214
21320
  }
21215
21321
 
21216
21322
  const epochSchedule = res.result;
@@ -21227,7 +21333,7 @@ var solanaWeb3 = (function (exports) {
21227
21333
  const res = create(unsafeRes, GetLeaderScheduleRpcResult);
21228
21334
 
21229
21335
  if ('error' in res) {
21230
- throw new Error('failed to get leader schedule: ' + res.error.message);
21336
+ throw new SolanaJSONRPCError(res.error, 'failed to get leader schedule');
21231
21337
  }
21232
21338
 
21233
21339
  return res.result;
@@ -21266,7 +21372,7 @@ var solanaWeb3 = (function (exports) {
21266
21372
  const res = create(unsafeRes, GetRecentBlockhashAndContextRpcResult);
21267
21373
 
21268
21374
  if ('error' in res) {
21269
- throw new Error('failed to get recent blockhash: ' + res.error.message);
21375
+ throw new SolanaJSONRPCError(res.error, 'failed to get recent blockhash');
21270
21376
  }
21271
21377
 
21272
21378
  return res.result;
@@ -21284,7 +21390,7 @@ var solanaWeb3 = (function (exports) {
21284
21390
  const res = create(unsafeRes, GetRecentPerformanceSamplesRpcResult);
21285
21391
 
21286
21392
  if ('error' in res) {
21287
- throw new Error('failed to get recent performance samples: ' + res.error.message);
21393
+ throw new SolanaJSONRPCError(res.error, 'failed to get recent performance samples');
21288
21394
  }
21289
21395
 
21290
21396
  return res.result;
@@ -21303,7 +21409,7 @@ var solanaWeb3 = (function (exports) {
21303
21409
  const res = create(unsafeRes, GetFeeCalculatorRpcResult);
21304
21410
 
21305
21411
  if ('error' in res) {
21306
- throw new Error('failed to get fee calculator: ' + res.error.message);
21412
+ throw new SolanaJSONRPCError(res.error, 'failed to get fee calculator');
21307
21413
  }
21308
21414
 
21309
21415
  const {
@@ -21329,7 +21435,7 @@ var solanaWeb3 = (function (exports) {
21329
21435
  const res = create(unsafeRes, jsonRpcResultAndContext(nullable(number())));
21330
21436
 
21331
21437
  if ('error' in res) {
21332
- throw new Error('failed to get slot: ' + res.error.message);
21438
+ throw new SolanaJSONRPCError(res.error, 'failed to get slot');
21333
21439
  }
21334
21440
 
21335
21441
  if (res.result === null) {
@@ -21360,9 +21466,9 @@ var solanaWeb3 = (function (exports) {
21360
21466
  */
21361
21467
 
21362
21468
 
21363
- async getLatestBlockhash(commitment) {
21469
+ async getLatestBlockhash(commitmentOrConfig) {
21364
21470
  try {
21365
- const res = await this.getLatestBlockhashAndContext(commitment);
21471
+ const res = await this.getLatestBlockhashAndContext(commitmentOrConfig);
21366
21472
  return res.value;
21367
21473
  } catch (e) {
21368
21474
  throw new Error('failed to get recent blockhash: ' + e);
@@ -21374,14 +21480,21 @@ var solanaWeb3 = (function (exports) {
21374
21480
  */
21375
21481
 
21376
21482
 
21377
- async getLatestBlockhashAndContext(commitment) {
21378
- const args = this._buildArgs([], commitment);
21483
+ async getLatestBlockhashAndContext(commitmentOrConfig) {
21484
+ const {
21485
+ commitment,
21486
+ config
21487
+ } = extractCommitmentFromConfig(commitmentOrConfig);
21488
+
21489
+ const args = this._buildArgs([], commitment, undefined
21490
+ /* encoding */
21491
+ , config);
21379
21492
 
21380
21493
  const unsafeRes = await this._rpcRequest('getLatestBlockhash', args);
21381
21494
  const res = create(unsafeRes, GetLatestBlockhashRpcResult);
21382
21495
 
21383
21496
  if ('error' in res) {
21384
- throw new Error('failed to get latest blockhash: ' + res.error.message);
21497
+ throw new SolanaJSONRPCError(res.error, 'failed to get latest blockhash');
21385
21498
  }
21386
21499
 
21387
21500
  return res.result;
@@ -21396,7 +21509,7 @@ var solanaWeb3 = (function (exports) {
21396
21509
  const res = create(unsafeRes, jsonRpcResult(VersionResult));
21397
21510
 
21398
21511
  if ('error' in res) {
21399
- throw new Error('failed to get version: ' + res.error.message);
21512
+ throw new SolanaJSONRPCError(res.error, 'failed to get version');
21400
21513
  }
21401
21514
 
21402
21515
  return res.result;
@@ -21411,7 +21524,7 @@ var solanaWeb3 = (function (exports) {
21411
21524
  const res = create(unsafeRes, jsonRpcResult(string()));
21412
21525
 
21413
21526
  if ('error' in res) {
21414
- throw new Error('failed to get genesis hash: ' + res.error.message);
21527
+ throw new SolanaJSONRPCError(res.error, 'failed to get genesis hash');
21415
21528
  }
21416
21529
 
21417
21530
  return res.result;
@@ -21428,7 +21541,7 @@ var solanaWeb3 = (function (exports) {
21428
21541
  const res = create(unsafeRes, GetBlockRpcResult);
21429
21542
 
21430
21543
  if ('error' in res) {
21431
- throw new Error('failed to get confirmed block: ' + res.error.message);
21544
+ throw new SolanaJSONRPCError(res.error, 'failed to get confirmed block');
21432
21545
  }
21433
21546
 
21434
21547
  const result = res.result;
@@ -21453,14 +21566,21 @@ var solanaWeb3 = (function (exports) {
21453
21566
  */
21454
21567
 
21455
21568
 
21456
- async getBlockHeight(commitment) {
21457
- const args = this._buildArgs([], commitment);
21569
+ async getBlockHeight(commitmentOrConfig) {
21570
+ const {
21571
+ commitment,
21572
+ config
21573
+ } = extractCommitmentFromConfig(commitmentOrConfig);
21574
+
21575
+ const args = this._buildArgs([], commitment, undefined
21576
+ /* encoding */
21577
+ , config);
21458
21578
 
21459
21579
  const unsafeRes = await this._rpcRequest('getBlockHeight', args);
21460
21580
  const res = create(unsafeRes, jsonRpcResult(number()));
21461
21581
 
21462
21582
  if ('error' in res) {
21463
- throw new Error('failed to get block height information: ' + res.error.message);
21583
+ throw new SolanaJSONRPCError(res.error, 'failed to get block height information');
21464
21584
  }
21465
21585
 
21466
21586
  return res.result;
@@ -21491,7 +21611,7 @@ var solanaWeb3 = (function (exports) {
21491
21611
  const res = create(unsafeRes, BlockProductionResponseStruct);
21492
21612
 
21493
21613
  if ('error' in res) {
21494
- throw new Error('failed to get block production information: ' + res.error.message);
21614
+ throw new SolanaJSONRPCError(res.error, 'failed to get block production information');
21495
21615
  }
21496
21616
 
21497
21617
  return res.result;
@@ -21508,7 +21628,7 @@ var solanaWeb3 = (function (exports) {
21508
21628
  const res = create(unsafeRes, GetTransactionRpcResult);
21509
21629
 
21510
21630
  if ('error' in res) {
21511
- throw new Error('failed to get transaction: ' + res.error.message);
21631
+ throw new SolanaJSONRPCError(res.error, 'failed to get transaction');
21512
21632
  }
21513
21633
 
21514
21634
  const result = res.result;
@@ -21531,7 +21651,7 @@ var solanaWeb3 = (function (exports) {
21531
21651
  const res = create(unsafeRes, GetParsedTransactionRpcResult);
21532
21652
 
21533
21653
  if ('error' in res) {
21534
- throw new Error('failed to get transaction: ' + res.error.message);
21654
+ throw new SolanaJSONRPCError(res.error, 'failed to get transaction');
21535
21655
  }
21536
21656
 
21537
21657
  return res.result;
@@ -21555,7 +21675,7 @@ var solanaWeb3 = (function (exports) {
21555
21675
  const res = create(unsafeRes, GetParsedTransactionRpcResult);
21556
21676
 
21557
21677
  if ('error' in res) {
21558
- throw new Error('failed to get transactions: ' + res.error.message);
21678
+ throw new SolanaJSONRPCError(res.error, 'failed to get transactions');
21559
21679
  }
21560
21680
 
21561
21681
  return res.result;
@@ -21582,7 +21702,7 @@ var solanaWeb3 = (function (exports) {
21582
21702
  const res = create(unsafeRes, GetTransactionRpcResult);
21583
21703
 
21584
21704
  if ('error' in res) {
21585
- throw new Error('failed to get transactions: ' + res.error.message);
21705
+ throw new SolanaJSONRPCError(res.error, 'failed to get transactions');
21586
21706
  }
21587
21707
 
21588
21708
  const result = res.result;
@@ -21610,7 +21730,7 @@ var solanaWeb3 = (function (exports) {
21610
21730
  const res = create(unsafeRes, GetConfirmedBlockRpcResult);
21611
21731
 
21612
21732
  if ('error' in res) {
21613
- throw new Error('failed to get confirmed block: ' + res.error.message);
21733
+ throw new SolanaJSONRPCError(res.error, 'failed to get confirmed block');
21614
21734
  }
21615
21735
 
21616
21736
  const result = res.result;
@@ -21657,7 +21777,7 @@ var solanaWeb3 = (function (exports) {
21657
21777
  const res = create(unsafeRes, jsonRpcResult(array(number())));
21658
21778
 
21659
21779
  if ('error' in res) {
21660
- throw new Error('failed to get blocks: ' + res.error.message);
21780
+ throw new SolanaJSONRPCError(res.error, 'failed to get blocks');
21661
21781
  }
21662
21782
 
21663
21783
  return res.result;
@@ -21677,7 +21797,7 @@ var solanaWeb3 = (function (exports) {
21677
21797
  const res = create(unsafeRes, GetBlockSignaturesRpcResult);
21678
21798
 
21679
21799
  if ('error' in res) {
21680
- throw new Error('failed to get block: ' + res.error.message);
21800
+ throw new SolanaJSONRPCError(res.error, 'failed to get block');
21681
21801
  }
21682
21802
 
21683
21803
  const result = res.result;
@@ -21705,7 +21825,7 @@ var solanaWeb3 = (function (exports) {
21705
21825
  const res = create(unsafeRes, GetBlockSignaturesRpcResult);
21706
21826
 
21707
21827
  if ('error' in res) {
21708
- throw new Error('failed to get confirmed block: ' + res.error.message);
21828
+ throw new SolanaJSONRPCError(res.error, 'failed to get confirmed block');
21709
21829
  }
21710
21830
 
21711
21831
  const result = res.result;
@@ -21730,7 +21850,7 @@ var solanaWeb3 = (function (exports) {
21730
21850
  const res = create(unsafeRes, GetTransactionRpcResult);
21731
21851
 
21732
21852
  if ('error' in res) {
21733
- throw new Error('failed to get transaction: ' + res.error.message);
21853
+ throw new SolanaJSONRPCError(res.error, 'failed to get transaction');
21734
21854
  }
21735
21855
 
21736
21856
  const result = res.result;
@@ -21755,7 +21875,7 @@ var solanaWeb3 = (function (exports) {
21755
21875
  const res = create(unsafeRes, GetParsedTransactionRpcResult);
21756
21876
 
21757
21877
  if ('error' in res) {
21758
- throw new Error('failed to get confirmed transaction: ' + res.error.message);
21878
+ throw new SolanaJSONRPCError(res.error, 'failed to get confirmed transaction');
21759
21879
  }
21760
21880
 
21761
21881
  return res.result;
@@ -21781,7 +21901,7 @@ var solanaWeb3 = (function (exports) {
21781
21901
  const res = create(unsafeRes, GetParsedTransactionRpcResult);
21782
21902
 
21783
21903
  if ('error' in res) {
21784
- throw new Error('failed to get confirmed transactions: ' + res.error.message);
21904
+ throw new SolanaJSONRPCError(res.error, 'failed to get confirmed transactions');
21785
21905
  }
21786
21906
 
21787
21907
  return res.result;
@@ -21870,7 +21990,7 @@ var solanaWeb3 = (function (exports) {
21870
21990
  const res = create(unsafeRes, GetConfirmedSignaturesForAddress2RpcResult);
21871
21991
 
21872
21992
  if ('error' in res) {
21873
- throw new Error('failed to get confirmed signatures for address: ' + res.error.message);
21993
+ throw new SolanaJSONRPCError(res.error, 'failed to get confirmed signatures for address');
21874
21994
  }
21875
21995
 
21876
21996
  return res.result;
@@ -21892,7 +22012,7 @@ var solanaWeb3 = (function (exports) {
21892
22012
  const res = create(unsafeRes, GetSignaturesForAddressRpcResult);
21893
22013
 
21894
22014
  if ('error' in res) {
21895
- throw new Error('failed to get signatures for address: ' + res.error.message);
22015
+ throw new SolanaJSONRPCError(res.error, 'failed to get signatures for address');
21896
22016
  }
21897
22017
 
21898
22018
  return res.result;
@@ -21949,7 +22069,7 @@ var solanaWeb3 = (function (exports) {
21949
22069
  const res = create(unsafeRes, RequestAirdropRpcResult);
21950
22070
 
21951
22071
  if ('error' in res) {
21952
- throw new Error('airdrop to ' + to.toBase58() + ' failed: ' + res.error.message);
22072
+ throw new SolanaJSONRPCError(res.error, `airdrop to ${to.toBase58()} failed`);
21953
22073
  }
21954
22074
 
21955
22075
  return res.result;
@@ -22183,6 +22303,10 @@ var solanaWeb3 = (function (exports) {
22183
22303
  config.maxRetries = options.maxRetries;
22184
22304
  }
22185
22305
 
22306
+ if (options && options.minContextSlot != null) {
22307
+ config.minContextSlot = options.minContextSlot;
22308
+ }
22309
+
22186
22310
  if (skipPreflight) {
22187
22311
  config.skipPreflight = skipPreflight;
22188
22312
  }
@@ -30185,7 +30309,8 @@ var solanaWeb3 = (function (exports) {
30185
30309
 
30186
30310
  const sendOptions = options && {
30187
30311
  skipPreflight: options.skipPreflight,
30188
- preflightCommitment: options.preflightCommitment || options.commitment
30312
+ preflightCommitment: options.preflightCommitment || options.commitment,
30313
+ minContextSlot: options.minContextSlot
30189
30314
  };
30190
30315
  const signature = await connection.sendRawTransaction(rawTransaction, sendOptions);
30191
30316
  const commitment = options && options.commitment;
@@ -30277,6 +30402,8 @@ var solanaWeb3 = (function (exports) {
30277
30402
  exports.SYSVAR_STAKE_HISTORY_PUBKEY = SYSVAR_STAKE_HISTORY_PUBKEY;
30278
30403
  exports.Secp256k1Program = Secp256k1Program;
30279
30404
  exports.SendTransactionError = SendTransactionError;
30405
+ exports.SolanaJSONRPCError = SolanaJSONRPCError;
30406
+ exports.SolanaJSONRPCErrorCode = SolanaJSONRPCErrorCode;
30280
30407
  exports.StakeAuthorizationLayout = StakeAuthorizationLayout;
30281
30408
  exports.StakeInstruction = StakeInstruction;
30282
30409
  exports.StakeProgram = StakeProgram;