@solana/web3.js 1.46.0 → 1.47.2

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.cjs.js CHANGED
@@ -4608,6 +4608,41 @@ class SendTransactionError extends Error {
4608
4608
  this.logs = logs;
4609
4609
  }
4610
4610
 
4611
+ } // Keep in sync with client/src/rpc_custom_errors.rs
4612
+ // Typescript `enums` thwart tree-shaking. See https://bargsten.org/jsts/enums/
4613
+
4614
+ const SolanaJSONRPCErrorCode = {
4615
+ JSON_RPC_SERVER_ERROR_BLOCK_CLEANED_UP: -32001,
4616
+ JSON_RPC_SERVER_ERROR_SEND_TRANSACTION_PREFLIGHT_FAILURE: -32002,
4617
+ JSON_RPC_SERVER_ERROR_TRANSACTION_SIGNATURE_VERIFICATION_FAILURE: -32003,
4618
+ JSON_RPC_SERVER_ERROR_BLOCK_NOT_AVAILABLE: -32004,
4619
+ JSON_RPC_SERVER_ERROR_NODE_UNHEALTHY: -32005,
4620
+ JSON_RPC_SERVER_ERROR_TRANSACTION_PRECOMPILE_VERIFICATION_FAILURE: -32006,
4621
+ JSON_RPC_SERVER_ERROR_SLOT_SKIPPED: -32007,
4622
+ JSON_RPC_SERVER_ERROR_NO_SNAPSHOT: -32008,
4623
+ JSON_RPC_SERVER_ERROR_LONG_TERM_STORAGE_SLOT_SKIPPED: -32009,
4624
+ JSON_RPC_SERVER_ERROR_KEY_EXCLUDED_FROM_SECONDARY_INDEX: -32010,
4625
+ JSON_RPC_SERVER_ERROR_TRANSACTION_HISTORY_NOT_AVAILABLE: -32011,
4626
+ JSON_RPC_SCAN_ERROR: -32012,
4627
+ JSON_RPC_SERVER_ERROR_TRANSACTION_SIGNATURE_LEN_MISMATCH: -32013,
4628
+ JSON_RPC_SERVER_ERROR_BLOCK_STATUS_NOT_AVAILABLE_YET: -32014,
4629
+ JSON_RPC_SERVER_ERROR_UNSUPPORTED_TRANSACTION_VERSION: -32015,
4630
+ JSON_RPC_SERVER_ERROR_MIN_CONTEXT_SLOT_NOT_REACHED: -32016
4631
+ };
4632
+ class SolanaJSONRPCError extends Error {
4633
+ constructor({
4634
+ code,
4635
+ message,
4636
+ data
4637
+ }, customMessage) {
4638
+ super(customMessage != null ? `${customMessage}: ${message}` : message);
4639
+ this.code = void 0;
4640
+ this.data = void 0;
4641
+ this.code = code;
4642
+ this.data = data;
4643
+ this.name = 'SolanaJSONRPCError';
4644
+ }
4645
+
4611
4646
  }
4612
4647
 
4613
4648
  async function fetchImpl (input, init) {
@@ -5779,7 +5814,7 @@ class Connection {
5779
5814
  const res = superstruct.create(unsafeRes, jsonRpcResultAndContext(superstruct.number()));
5780
5815
 
5781
5816
  if ('error' in res) {
5782
- throw new Error('failed to get balance for ' + publicKey.toBase58() + ': ' + res.error.message);
5817
+ throw new SolanaJSONRPCError(res.error, `failed to get balance for ${publicKey.toBase58()}`);
5783
5818
  }
5784
5819
 
5785
5820
  return res.result;
@@ -5804,7 +5839,7 @@ class Connection {
5804
5839
  const res = superstruct.create(unsafeRes, jsonRpcResult(superstruct.nullable(superstruct.number())));
5805
5840
 
5806
5841
  if ('error' in res) {
5807
- throw new Error('failed to get block time for slot ' + slot + ': ' + res.error.message);
5842
+ throw new SolanaJSONRPCError(res.error, `failed to get block time for slot ${slot}`);
5808
5843
  }
5809
5844
 
5810
5845
  return res.result;
@@ -5820,7 +5855,7 @@ class Connection {
5820
5855
  const res = superstruct.create(unsafeRes, jsonRpcResult(superstruct.number()));
5821
5856
 
5822
5857
  if ('error' in res) {
5823
- throw new Error('failed to get minimum ledger slot: ' + res.error.message);
5858
+ throw new SolanaJSONRPCError(res.error, 'failed to get minimum ledger slot');
5824
5859
  }
5825
5860
 
5826
5861
  return res.result;
@@ -5835,7 +5870,7 @@ class Connection {
5835
5870
  const res = superstruct.create(unsafeRes, SlotRpcResult);
5836
5871
 
5837
5872
  if ('error' in res) {
5838
- throw new Error('failed to get first available block: ' + res.error.message);
5873
+ throw new SolanaJSONRPCError(res.error, 'failed to get first available block');
5839
5874
  }
5840
5875
 
5841
5876
  return res.result;
@@ -5866,7 +5901,7 @@ class Connection {
5866
5901
  const res = superstruct.create(unsafeRes, GetSupplyRpcResult);
5867
5902
 
5868
5903
  if ('error' in res) {
5869
- throw new Error('failed to get supply: ' + res.error.message);
5904
+ throw new SolanaJSONRPCError(res.error, 'failed to get supply');
5870
5905
  }
5871
5906
 
5872
5907
  return res.result;
@@ -5883,7 +5918,7 @@ class Connection {
5883
5918
  const res = superstruct.create(unsafeRes, jsonRpcResultAndContext(TokenAmountResult));
5884
5919
 
5885
5920
  if ('error' in res) {
5886
- throw new Error('failed to get token supply: ' + res.error.message);
5921
+ throw new SolanaJSONRPCError(res.error, 'failed to get token supply');
5887
5922
  }
5888
5923
 
5889
5924
  return res.result;
@@ -5900,7 +5935,7 @@ class Connection {
5900
5935
  const res = superstruct.create(unsafeRes, jsonRpcResultAndContext(TokenAmountResult));
5901
5936
 
5902
5937
  if ('error' in res) {
5903
- throw new Error('failed to get token account balance: ' + res.error.message);
5938
+ throw new SolanaJSONRPCError(res.error, 'failed to get token account balance');
5904
5939
  }
5905
5940
 
5906
5941
  return res.result;
@@ -5935,7 +5970,7 @@ class Connection {
5935
5970
  const res = superstruct.create(unsafeRes, GetTokenAccountsByOwner);
5936
5971
 
5937
5972
  if ('error' in res) {
5938
- throw new Error('failed to get token accounts owned by account ' + ownerAddress.toBase58() + ': ' + res.error.message);
5973
+ throw new SolanaJSONRPCError(res.error, `failed to get token accounts owned by account ${ownerAddress.toBase58()}`);
5939
5974
  }
5940
5975
 
5941
5976
  return res.result;
@@ -5966,7 +6001,7 @@ class Connection {
5966
6001
  const res = superstruct.create(unsafeRes, GetParsedTokenAccountsByOwner);
5967
6002
 
5968
6003
  if ('error' in res) {
5969
- throw new Error('failed to get token accounts owned by account ' + ownerAddress.toBase58() + ': ' + res.error.message);
6004
+ throw new SolanaJSONRPCError(res.error, `failed to get token accounts owned by account ${ownerAddress.toBase58()}`);
5970
6005
  }
5971
6006
 
5972
6007
  return res.result;
@@ -5985,7 +6020,7 @@ class Connection {
5985
6020
  const res = superstruct.create(unsafeRes, GetLargestAccountsRpcResult);
5986
6021
 
5987
6022
  if ('error' in res) {
5988
- throw new Error('failed to get largest accounts: ' + res.error.message);
6023
+ throw new SolanaJSONRPCError(res.error, 'failed to get largest accounts');
5989
6024
  }
5990
6025
 
5991
6026
  return res.result;
@@ -6003,7 +6038,7 @@ class Connection {
6003
6038
  const res = superstruct.create(unsafeRes, GetTokenLargestAccountsResult);
6004
6039
 
6005
6040
  if ('error' in res) {
6006
- throw new Error('failed to get token largest accounts: ' + res.error.message);
6041
+ throw new SolanaJSONRPCError(res.error, 'failed to get token largest accounts');
6007
6042
  }
6008
6043
 
6009
6044
  return res.result;
@@ -6025,7 +6060,7 @@ class Connection {
6025
6060
  const res = superstruct.create(unsafeRes, jsonRpcResultAndContext(superstruct.nullable(AccountInfoResult)));
6026
6061
 
6027
6062
  if ('error' in res) {
6028
- throw new Error('failed to get info about account ' + publicKey.toBase58() + ': ' + res.error.message);
6063
+ throw new SolanaJSONRPCError(res.error, `failed to get info about account ${publicKey.toBase58()}`);
6029
6064
  }
6030
6065
 
6031
6066
  return res.result;
@@ -6042,7 +6077,7 @@ class Connection {
6042
6077
  const res = superstruct.create(unsafeRes, jsonRpcResultAndContext(superstruct.nullable(ParsedAccountInfoResult)));
6043
6078
 
6044
6079
  if ('error' in res) {
6045
- throw new Error('failed to get info about account ' + publicKey.toBase58() + ': ' + res.error.message);
6080
+ throw new SolanaJSONRPCError(res.error, `failed to get info about account ${publicKey.toBase58()}`);
6046
6081
  }
6047
6082
 
6048
6083
  return res.result;
@@ -6078,7 +6113,7 @@ class Connection {
6078
6113
  const res = superstruct.create(unsafeRes, jsonRpcResultAndContext(superstruct.array(superstruct.nullable(AccountInfoResult))));
6079
6114
 
6080
6115
  if ('error' in res) {
6081
- throw new Error('failed to get info for accounts ' + keys + ': ' + res.error.message);
6116
+ throw new SolanaJSONRPCError(res.error, `failed to get info for accounts ${keys}`);
6082
6117
  }
6083
6118
 
6084
6119
  return res.result;
@@ -6113,7 +6148,7 @@ class Connection {
6113
6148
  const res = superstruct.create(unsafeRes, jsonRpcResult(StakeActivationResult));
6114
6149
 
6115
6150
  if ('error' in res) {
6116
- throw new Error(`failed to get Stake Activation ${publicKey.toBase58()}: ${res.error.message}`);
6151
+ throw new SolanaJSONRPCError(res.error, `failed to get Stake Activation ${publicKey.toBase58()}`);
6117
6152
  }
6118
6153
 
6119
6154
  return res.result;
@@ -6141,7 +6176,7 @@ class Connection {
6141
6176
  const res = superstruct.create(unsafeRes, jsonRpcResult(superstruct.array(KeyedAccountInfoResult)));
6142
6177
 
6143
6178
  if ('error' in res) {
6144
- throw new Error('failed to get accounts owned by program ' + programId.toBase58() + ': ' + res.error.message);
6179
+ throw new SolanaJSONRPCError(res.error, `failed to get accounts owned by program ${programId.toBase58()}`);
6145
6180
  }
6146
6181
 
6147
6182
  return res.result;
@@ -6165,7 +6200,7 @@ class Connection {
6165
6200
  const res = superstruct.create(unsafeRes, jsonRpcResult(superstruct.array(KeyedParsedAccountInfoResult)));
6166
6201
 
6167
6202
  if ('error' in res) {
6168
- throw new Error('failed to get accounts owned by program ' + programId.toBase58() + ': ' + res.error.message);
6203
+ throw new SolanaJSONRPCError(res.error, `failed to get accounts owned by program ${programId.toBase58()}`);
6169
6204
  }
6170
6205
 
6171
6206
  return res.result;
@@ -6299,7 +6334,7 @@ class Connection {
6299
6334
  const res = superstruct.create(unsafeRes, jsonRpcResult(superstruct.array(ContactInfoResult)));
6300
6335
 
6301
6336
  if ('error' in res) {
6302
- throw new Error('failed to get cluster nodes: ' + res.error.message);
6337
+ throw new SolanaJSONRPCError(res.error, 'failed to get cluster nodes');
6303
6338
  }
6304
6339
 
6305
6340
  return res.result;
@@ -6316,7 +6351,7 @@ class Connection {
6316
6351
  const res = superstruct.create(unsafeRes, GetVoteAccounts);
6317
6352
 
6318
6353
  if ('error' in res) {
6319
- throw new Error('failed to get vote accounts: ' + res.error.message);
6354
+ throw new SolanaJSONRPCError(res.error, 'failed to get vote accounts');
6320
6355
  }
6321
6356
 
6322
6357
  return res.result;
@@ -6340,7 +6375,7 @@ class Connection {
6340
6375
  const res = superstruct.create(unsafeRes, jsonRpcResult(superstruct.number()));
6341
6376
 
6342
6377
  if ('error' in res) {
6343
- throw new Error('failed to get slot: ' + res.error.message);
6378
+ throw new SolanaJSONRPCError(res.error, 'failed to get slot');
6344
6379
  }
6345
6380
 
6346
6381
  return res.result;
@@ -6364,7 +6399,7 @@ class Connection {
6364
6399
  const res = superstruct.create(unsafeRes, jsonRpcResult(superstruct.string()));
6365
6400
 
6366
6401
  if ('error' in res) {
6367
- throw new Error('failed to get slot leader: ' + res.error.message);
6402
+ throw new SolanaJSONRPCError(res.error, 'failed to get slot leader');
6368
6403
  }
6369
6404
 
6370
6405
  return res.result;
@@ -6383,7 +6418,7 @@ class Connection {
6383
6418
  const res = superstruct.create(unsafeRes, jsonRpcResult(superstruct.array(PublicKeyFromString)));
6384
6419
 
6385
6420
  if ('error' in res) {
6386
- throw new Error('failed to get slot leaders: ' + res.error.message);
6421
+ throw new SolanaJSONRPCError(res.error, 'failed to get slot leaders');
6387
6422
  }
6388
6423
 
6389
6424
  return res.result;
@@ -6421,7 +6456,7 @@ class Connection {
6421
6456
  const res = superstruct.create(unsafeRes, GetSignatureStatusesRpcResult);
6422
6457
 
6423
6458
  if ('error' in res) {
6424
- throw new Error('failed to get signature status: ' + res.error.message);
6459
+ throw new SolanaJSONRPCError(res.error, 'failed to get signature status');
6425
6460
  }
6426
6461
 
6427
6462
  return res.result;
@@ -6445,7 +6480,7 @@ class Connection {
6445
6480
  const res = superstruct.create(unsafeRes, jsonRpcResult(superstruct.number()));
6446
6481
 
6447
6482
  if ('error' in res) {
6448
- throw new Error('failed to get transaction count: ' + res.error.message);
6483
+ throw new SolanaJSONRPCError(res.error, 'failed to get transaction count');
6449
6484
  }
6450
6485
 
6451
6486
  return res.result;
@@ -6476,7 +6511,7 @@ class Connection {
6476
6511
  const res = superstruct.create(unsafeRes, GetInflationGovernorRpcResult);
6477
6512
 
6478
6513
  if ('error' in res) {
6479
- throw new Error('failed to get inflation: ' + res.error.message);
6514
+ throw new SolanaJSONRPCError(res.error, 'failed to get inflation');
6480
6515
  }
6481
6516
 
6482
6517
  return res.result;
@@ -6502,7 +6537,7 @@ class Connection {
6502
6537
  const res = superstruct.create(unsafeRes, GetInflationRewardResult);
6503
6538
 
6504
6539
  if ('error' in res) {
6505
- throw new Error('failed to get inflation reward: ' + res.error.message);
6540
+ throw new SolanaJSONRPCError(res.error, 'failed to get inflation reward');
6506
6541
  }
6507
6542
 
6508
6543
  return res.result;
@@ -6526,7 +6561,7 @@ class Connection {
6526
6561
  const res = superstruct.create(unsafeRes, GetEpochInfoRpcResult);
6527
6562
 
6528
6563
  if ('error' in res) {
6529
- throw new Error('failed to get epoch info: ' + res.error.message);
6564
+ throw new SolanaJSONRPCError(res.error, 'failed to get epoch info');
6530
6565
  }
6531
6566
 
6532
6567
  return res.result;
@@ -6541,7 +6576,7 @@ class Connection {
6541
6576
  const res = superstruct.create(unsafeRes, GetEpochScheduleRpcResult);
6542
6577
 
6543
6578
  if ('error' in res) {
6544
- throw new Error('failed to get epoch schedule: ' + res.error.message);
6579
+ throw new SolanaJSONRPCError(res.error, 'failed to get epoch schedule');
6545
6580
  }
6546
6581
 
6547
6582
  const epochSchedule = res.result;
@@ -6558,7 +6593,7 @@ class Connection {
6558
6593
  const res = superstruct.create(unsafeRes, GetLeaderScheduleRpcResult);
6559
6594
 
6560
6595
  if ('error' in res) {
6561
- throw new Error('failed to get leader schedule: ' + res.error.message);
6596
+ throw new SolanaJSONRPCError(res.error, 'failed to get leader schedule');
6562
6597
  }
6563
6598
 
6564
6599
  return res.result;
@@ -6597,7 +6632,7 @@ class Connection {
6597
6632
  const res = superstruct.create(unsafeRes, GetRecentBlockhashAndContextRpcResult);
6598
6633
 
6599
6634
  if ('error' in res) {
6600
- throw new Error('failed to get recent blockhash: ' + res.error.message);
6635
+ throw new SolanaJSONRPCError(res.error, 'failed to get recent blockhash');
6601
6636
  }
6602
6637
 
6603
6638
  return res.result;
@@ -6609,13 +6644,11 @@ class Connection {
6609
6644
 
6610
6645
 
6611
6646
  async getRecentPerformanceSamples(limit) {
6612
- const args = this._buildArgs(limit ? [limit] : []);
6613
-
6614
- const unsafeRes = await this._rpcRequest('getRecentPerformanceSamples', args);
6647
+ const unsafeRes = await this._rpcRequest('getRecentPerformanceSamples', limit ? [limit] : []);
6615
6648
  const res = superstruct.create(unsafeRes, GetRecentPerformanceSamplesRpcResult);
6616
6649
 
6617
6650
  if ('error' in res) {
6618
- throw new Error('failed to get recent performance samples: ' + res.error.message);
6651
+ throw new SolanaJSONRPCError(res.error, 'failed to get recent performance samples');
6619
6652
  }
6620
6653
 
6621
6654
  return res.result;
@@ -6634,7 +6667,7 @@ class Connection {
6634
6667
  const res = superstruct.create(unsafeRes, GetFeeCalculatorRpcResult);
6635
6668
 
6636
6669
  if ('error' in res) {
6637
- throw new Error('failed to get fee calculator: ' + res.error.message);
6670
+ throw new SolanaJSONRPCError(res.error, 'failed to get fee calculator');
6638
6671
  }
6639
6672
 
6640
6673
  const {
@@ -6660,7 +6693,7 @@ class Connection {
6660
6693
  const res = superstruct.create(unsafeRes, jsonRpcResultAndContext(superstruct.nullable(superstruct.number())));
6661
6694
 
6662
6695
  if ('error' in res) {
6663
- throw new Error('failed to get slot: ' + res.error.message);
6696
+ throw new SolanaJSONRPCError(res.error, 'failed to get slot');
6664
6697
  }
6665
6698
 
6666
6699
  if (res.result === null) {
@@ -6719,7 +6752,7 @@ class Connection {
6719
6752
  const res = superstruct.create(unsafeRes, GetLatestBlockhashRpcResult);
6720
6753
 
6721
6754
  if ('error' in res) {
6722
- throw new Error('failed to get latest blockhash: ' + res.error.message);
6755
+ throw new SolanaJSONRPCError(res.error, 'failed to get latest blockhash');
6723
6756
  }
6724
6757
 
6725
6758
  return res.result;
@@ -6734,7 +6767,7 @@ class Connection {
6734
6767
  const res = superstruct.create(unsafeRes, jsonRpcResult(VersionResult));
6735
6768
 
6736
6769
  if ('error' in res) {
6737
- throw new Error('failed to get version: ' + res.error.message);
6770
+ throw new SolanaJSONRPCError(res.error, 'failed to get version');
6738
6771
  }
6739
6772
 
6740
6773
  return res.result;
@@ -6749,7 +6782,7 @@ class Connection {
6749
6782
  const res = superstruct.create(unsafeRes, jsonRpcResult(superstruct.string()));
6750
6783
 
6751
6784
  if ('error' in res) {
6752
- throw new Error('failed to get genesis hash: ' + res.error.message);
6785
+ throw new SolanaJSONRPCError(res.error, 'failed to get genesis hash');
6753
6786
  }
6754
6787
 
6755
6788
  return res.result;
@@ -6766,7 +6799,7 @@ class Connection {
6766
6799
  const res = superstruct.create(unsafeRes, GetBlockRpcResult);
6767
6800
 
6768
6801
  if ('error' in res) {
6769
- throw new Error('failed to get confirmed block: ' + res.error.message);
6802
+ throw new SolanaJSONRPCError(res.error, 'failed to get confirmed block');
6770
6803
  }
6771
6804
 
6772
6805
  const result = res.result;
@@ -6805,7 +6838,7 @@ class Connection {
6805
6838
  const res = superstruct.create(unsafeRes, jsonRpcResult(superstruct.number()));
6806
6839
 
6807
6840
  if ('error' in res) {
6808
- throw new Error('failed to get block height information: ' + res.error.message);
6841
+ throw new SolanaJSONRPCError(res.error, 'failed to get block height information');
6809
6842
  }
6810
6843
 
6811
6844
  return res.result;
@@ -6836,7 +6869,7 @@ class Connection {
6836
6869
  const res = superstruct.create(unsafeRes, BlockProductionResponseStruct);
6837
6870
 
6838
6871
  if ('error' in res) {
6839
- throw new Error('failed to get block production information: ' + res.error.message);
6872
+ throw new SolanaJSONRPCError(res.error, 'failed to get block production information');
6840
6873
  }
6841
6874
 
6842
6875
  return res.result;
@@ -6853,7 +6886,7 @@ class Connection {
6853
6886
  const res = superstruct.create(unsafeRes, GetTransactionRpcResult);
6854
6887
 
6855
6888
  if ('error' in res) {
6856
- throw new Error('failed to get transaction: ' + res.error.message);
6889
+ throw new SolanaJSONRPCError(res.error, 'failed to get transaction');
6857
6890
  }
6858
6891
 
6859
6892
  const result = res.result;
@@ -6876,7 +6909,7 @@ class Connection {
6876
6909
  const res = superstruct.create(unsafeRes, GetParsedTransactionRpcResult);
6877
6910
 
6878
6911
  if ('error' in res) {
6879
- throw new Error('failed to get transaction: ' + res.error.message);
6912
+ throw new SolanaJSONRPCError(res.error, 'failed to get transaction');
6880
6913
  }
6881
6914
 
6882
6915
  return res.result;
@@ -6900,7 +6933,7 @@ class Connection {
6900
6933
  const res = superstruct.create(unsafeRes, GetParsedTransactionRpcResult);
6901
6934
 
6902
6935
  if ('error' in res) {
6903
- throw new Error('failed to get transactions: ' + res.error.message);
6936
+ throw new SolanaJSONRPCError(res.error, 'failed to get transactions');
6904
6937
  }
6905
6938
 
6906
6939
  return res.result;
@@ -6927,7 +6960,7 @@ class Connection {
6927
6960
  const res = superstruct.create(unsafeRes, GetTransactionRpcResult);
6928
6961
 
6929
6962
  if ('error' in res) {
6930
- throw new Error('failed to get transactions: ' + res.error.message);
6963
+ throw new SolanaJSONRPCError(res.error, 'failed to get transactions');
6931
6964
  }
6932
6965
 
6933
6966
  const result = res.result;
@@ -6955,7 +6988,7 @@ class Connection {
6955
6988
  const res = superstruct.create(unsafeRes, GetConfirmedBlockRpcResult);
6956
6989
 
6957
6990
  if ('error' in res) {
6958
- throw new Error('failed to get confirmed block: ' + res.error.message);
6991
+ throw new SolanaJSONRPCError(res.error, 'failed to get confirmed block');
6959
6992
  }
6960
6993
 
6961
6994
  const result = res.result;
@@ -7002,7 +7035,7 @@ class Connection {
7002
7035
  const res = superstruct.create(unsafeRes, jsonRpcResult(superstruct.array(superstruct.number())));
7003
7036
 
7004
7037
  if ('error' in res) {
7005
- throw new Error('failed to get blocks: ' + res.error.message);
7038
+ throw new SolanaJSONRPCError(res.error, 'failed to get blocks');
7006
7039
  }
7007
7040
 
7008
7041
  return res.result;
@@ -7022,7 +7055,7 @@ class Connection {
7022
7055
  const res = superstruct.create(unsafeRes, GetBlockSignaturesRpcResult);
7023
7056
 
7024
7057
  if ('error' in res) {
7025
- throw new Error('failed to get block: ' + res.error.message);
7058
+ throw new SolanaJSONRPCError(res.error, 'failed to get block');
7026
7059
  }
7027
7060
 
7028
7061
  const result = res.result;
@@ -7050,7 +7083,7 @@ class Connection {
7050
7083
  const res = superstruct.create(unsafeRes, GetBlockSignaturesRpcResult);
7051
7084
 
7052
7085
  if ('error' in res) {
7053
- throw new Error('failed to get confirmed block: ' + res.error.message);
7086
+ throw new SolanaJSONRPCError(res.error, 'failed to get confirmed block');
7054
7087
  }
7055
7088
 
7056
7089
  const result = res.result;
@@ -7075,7 +7108,7 @@ class Connection {
7075
7108
  const res = superstruct.create(unsafeRes, GetTransactionRpcResult);
7076
7109
 
7077
7110
  if ('error' in res) {
7078
- throw new Error('failed to get transaction: ' + res.error.message);
7111
+ throw new SolanaJSONRPCError(res.error, 'failed to get transaction');
7079
7112
  }
7080
7113
 
7081
7114
  const result = res.result;
@@ -7100,7 +7133,7 @@ class Connection {
7100
7133
  const res = superstruct.create(unsafeRes, GetParsedTransactionRpcResult);
7101
7134
 
7102
7135
  if ('error' in res) {
7103
- throw new Error('failed to get confirmed transaction: ' + res.error.message);
7136
+ throw new SolanaJSONRPCError(res.error, 'failed to get confirmed transaction');
7104
7137
  }
7105
7138
 
7106
7139
  return res.result;
@@ -7126,7 +7159,7 @@ class Connection {
7126
7159
  const res = superstruct.create(unsafeRes, GetParsedTransactionRpcResult);
7127
7160
 
7128
7161
  if ('error' in res) {
7129
- throw new Error('failed to get confirmed transactions: ' + res.error.message);
7162
+ throw new SolanaJSONRPCError(res.error, 'failed to get confirmed transactions');
7130
7163
  }
7131
7164
 
7132
7165
  return res.result;
@@ -7215,7 +7248,7 @@ class Connection {
7215
7248
  const res = superstruct.create(unsafeRes, GetConfirmedSignaturesForAddress2RpcResult);
7216
7249
 
7217
7250
  if ('error' in res) {
7218
- throw new Error('failed to get confirmed signatures for address: ' + res.error.message);
7251
+ throw new SolanaJSONRPCError(res.error, 'failed to get confirmed signatures for address');
7219
7252
  }
7220
7253
 
7221
7254
  return res.result;
@@ -7237,7 +7270,7 @@ class Connection {
7237
7270
  const res = superstruct.create(unsafeRes, GetSignaturesForAddressRpcResult);
7238
7271
 
7239
7272
  if ('error' in res) {
7240
- throw new Error('failed to get signatures for address: ' + res.error.message);
7273
+ throw new SolanaJSONRPCError(res.error, 'failed to get signatures for address');
7241
7274
  }
7242
7275
 
7243
7276
  return res.result;
@@ -7294,7 +7327,7 @@ class Connection {
7294
7327
  const res = superstruct.create(unsafeRes, RequestAirdropRpcResult);
7295
7328
 
7296
7329
  if ('error' in res) {
7297
- throw new Error('airdrop to ' + to.toBase58() + ' failed: ' + res.error.message);
7330
+ throw new SolanaJSONRPCError(res.error, `airdrop to ${to.toBase58()} failed`);
7298
7331
  }
7299
7332
 
7300
7333
  return res.result;
@@ -7524,7 +7557,7 @@ class Connection {
7524
7557
  const skipPreflight = options && options.skipPreflight;
7525
7558
  const preflightCommitment = options && options.preflightCommitment || this.commitment;
7526
7559
 
7527
- if (options && options.maxRetries) {
7560
+ if (options && options.maxRetries != null) {
7528
7561
  config.maxRetries = options.maxRetries;
7529
7562
  }
7530
7563
 
@@ -10034,6 +10067,8 @@ exports.SYSVAR_SLOT_HISTORY_PUBKEY = SYSVAR_SLOT_HISTORY_PUBKEY;
10034
10067
  exports.SYSVAR_STAKE_HISTORY_PUBKEY = SYSVAR_STAKE_HISTORY_PUBKEY;
10035
10068
  exports.Secp256k1Program = Secp256k1Program;
10036
10069
  exports.SendTransactionError = SendTransactionError;
10070
+ exports.SolanaJSONRPCError = SolanaJSONRPCError;
10071
+ exports.SolanaJSONRPCErrorCode = SolanaJSONRPCErrorCode;
10037
10072
  exports.StakeAuthorizationLayout = StakeAuthorizationLayout;
10038
10073
  exports.StakeInstruction = StakeInstruction;
10039
10074
  exports.StakeProgram = StakeProgram;