@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.
@@ -4532,6 +4532,41 @@ class SendTransactionError extends Error {
4532
4532
  this.logs = logs;
4533
4533
  }
4534
4534
 
4535
+ } // Keep in sync with client/src/rpc_custom_errors.rs
4536
+ // Typescript `enums` thwart tree-shaking. See https://bargsten.org/jsts/enums/
4537
+
4538
+ const SolanaJSONRPCErrorCode = {
4539
+ JSON_RPC_SERVER_ERROR_BLOCK_CLEANED_UP: -32001,
4540
+ JSON_RPC_SERVER_ERROR_SEND_TRANSACTION_PREFLIGHT_FAILURE: -32002,
4541
+ JSON_RPC_SERVER_ERROR_TRANSACTION_SIGNATURE_VERIFICATION_FAILURE: -32003,
4542
+ JSON_RPC_SERVER_ERROR_BLOCK_NOT_AVAILABLE: -32004,
4543
+ JSON_RPC_SERVER_ERROR_NODE_UNHEALTHY: -32005,
4544
+ JSON_RPC_SERVER_ERROR_TRANSACTION_PRECOMPILE_VERIFICATION_FAILURE: -32006,
4545
+ JSON_RPC_SERVER_ERROR_SLOT_SKIPPED: -32007,
4546
+ JSON_RPC_SERVER_ERROR_NO_SNAPSHOT: -32008,
4547
+ JSON_RPC_SERVER_ERROR_LONG_TERM_STORAGE_SLOT_SKIPPED: -32009,
4548
+ JSON_RPC_SERVER_ERROR_KEY_EXCLUDED_FROM_SECONDARY_INDEX: -32010,
4549
+ JSON_RPC_SERVER_ERROR_TRANSACTION_HISTORY_NOT_AVAILABLE: -32011,
4550
+ JSON_RPC_SCAN_ERROR: -32012,
4551
+ JSON_RPC_SERVER_ERROR_TRANSACTION_SIGNATURE_LEN_MISMATCH: -32013,
4552
+ JSON_RPC_SERVER_ERROR_BLOCK_STATUS_NOT_AVAILABLE_YET: -32014,
4553
+ JSON_RPC_SERVER_ERROR_UNSUPPORTED_TRANSACTION_VERSION: -32015,
4554
+ JSON_RPC_SERVER_ERROR_MIN_CONTEXT_SLOT_NOT_REACHED: -32016
4555
+ };
4556
+ class SolanaJSONRPCError extends Error {
4557
+ constructor({
4558
+ code,
4559
+ message,
4560
+ data
4561
+ }, customMessage) {
4562
+ super(customMessage != null ? `${customMessage}: ${message}` : message);
4563
+ this.code = void 0;
4564
+ this.data = void 0;
4565
+ this.code = code;
4566
+ this.data = data;
4567
+ this.name = 'SolanaJSONRPCError';
4568
+ }
4569
+
4535
4570
  }
4536
4571
 
4537
4572
  var fetchImpl = globalThis.fetch;
@@ -5694,7 +5729,7 @@ class Connection {
5694
5729
  const res = superstruct.create(unsafeRes, jsonRpcResultAndContext(superstruct.number()));
5695
5730
 
5696
5731
  if ('error' in res) {
5697
- throw new Error('failed to get balance for ' + publicKey.toBase58() + ': ' + res.error.message);
5732
+ throw new SolanaJSONRPCError(res.error, `failed to get balance for ${publicKey.toBase58()}`);
5698
5733
  }
5699
5734
 
5700
5735
  return res.result;
@@ -5719,7 +5754,7 @@ class Connection {
5719
5754
  const res = superstruct.create(unsafeRes, jsonRpcResult(superstruct.nullable(superstruct.number())));
5720
5755
 
5721
5756
  if ('error' in res) {
5722
- throw new Error('failed to get block time for slot ' + slot + ': ' + res.error.message);
5757
+ throw new SolanaJSONRPCError(res.error, `failed to get block time for slot ${slot}`);
5723
5758
  }
5724
5759
 
5725
5760
  return res.result;
@@ -5735,7 +5770,7 @@ class Connection {
5735
5770
  const res = superstruct.create(unsafeRes, jsonRpcResult(superstruct.number()));
5736
5771
 
5737
5772
  if ('error' in res) {
5738
- throw new Error('failed to get minimum ledger slot: ' + res.error.message);
5773
+ throw new SolanaJSONRPCError(res.error, 'failed to get minimum ledger slot');
5739
5774
  }
5740
5775
 
5741
5776
  return res.result;
@@ -5750,7 +5785,7 @@ class Connection {
5750
5785
  const res = superstruct.create(unsafeRes, SlotRpcResult);
5751
5786
 
5752
5787
  if ('error' in res) {
5753
- throw new Error('failed to get first available block: ' + res.error.message);
5788
+ throw new SolanaJSONRPCError(res.error, 'failed to get first available block');
5754
5789
  }
5755
5790
 
5756
5791
  return res.result;
@@ -5781,7 +5816,7 @@ class Connection {
5781
5816
  const res = superstruct.create(unsafeRes, GetSupplyRpcResult);
5782
5817
 
5783
5818
  if ('error' in res) {
5784
- throw new Error('failed to get supply: ' + res.error.message);
5819
+ throw new SolanaJSONRPCError(res.error, 'failed to get supply');
5785
5820
  }
5786
5821
 
5787
5822
  return res.result;
@@ -5798,7 +5833,7 @@ class Connection {
5798
5833
  const res = superstruct.create(unsafeRes, jsonRpcResultAndContext(TokenAmountResult));
5799
5834
 
5800
5835
  if ('error' in res) {
5801
- throw new Error('failed to get token supply: ' + res.error.message);
5836
+ throw new SolanaJSONRPCError(res.error, 'failed to get token supply');
5802
5837
  }
5803
5838
 
5804
5839
  return res.result;
@@ -5815,7 +5850,7 @@ class Connection {
5815
5850
  const res = superstruct.create(unsafeRes, jsonRpcResultAndContext(TokenAmountResult));
5816
5851
 
5817
5852
  if ('error' in res) {
5818
- throw new Error('failed to get token account balance: ' + res.error.message);
5853
+ throw new SolanaJSONRPCError(res.error, 'failed to get token account balance');
5819
5854
  }
5820
5855
 
5821
5856
  return res.result;
@@ -5850,7 +5885,7 @@ class Connection {
5850
5885
  const res = superstruct.create(unsafeRes, GetTokenAccountsByOwner);
5851
5886
 
5852
5887
  if ('error' in res) {
5853
- throw new Error('failed to get token accounts owned by account ' + ownerAddress.toBase58() + ': ' + res.error.message);
5888
+ throw new SolanaJSONRPCError(res.error, `failed to get token accounts owned by account ${ownerAddress.toBase58()}`);
5854
5889
  }
5855
5890
 
5856
5891
  return res.result;
@@ -5881,7 +5916,7 @@ class Connection {
5881
5916
  const res = superstruct.create(unsafeRes, GetParsedTokenAccountsByOwner);
5882
5917
 
5883
5918
  if ('error' in res) {
5884
- throw new Error('failed to get token accounts owned by account ' + ownerAddress.toBase58() + ': ' + res.error.message);
5919
+ throw new SolanaJSONRPCError(res.error, `failed to get token accounts owned by account ${ownerAddress.toBase58()}`);
5885
5920
  }
5886
5921
 
5887
5922
  return res.result;
@@ -5900,7 +5935,7 @@ class Connection {
5900
5935
  const res = superstruct.create(unsafeRes, GetLargestAccountsRpcResult);
5901
5936
 
5902
5937
  if ('error' in res) {
5903
- throw new Error('failed to get largest accounts: ' + res.error.message);
5938
+ throw new SolanaJSONRPCError(res.error, 'failed to get largest accounts');
5904
5939
  }
5905
5940
 
5906
5941
  return res.result;
@@ -5918,7 +5953,7 @@ class Connection {
5918
5953
  const res = superstruct.create(unsafeRes, GetTokenLargestAccountsResult);
5919
5954
 
5920
5955
  if ('error' in res) {
5921
- throw new Error('failed to get token largest accounts: ' + res.error.message);
5956
+ throw new SolanaJSONRPCError(res.error, 'failed to get token largest accounts');
5922
5957
  }
5923
5958
 
5924
5959
  return res.result;
@@ -5940,7 +5975,7 @@ class Connection {
5940
5975
  const res = superstruct.create(unsafeRes, jsonRpcResultAndContext(superstruct.nullable(AccountInfoResult)));
5941
5976
 
5942
5977
  if ('error' in res) {
5943
- throw new Error('failed to get info about account ' + publicKey.toBase58() + ': ' + res.error.message);
5978
+ throw new SolanaJSONRPCError(res.error, `failed to get info about account ${publicKey.toBase58()}`);
5944
5979
  }
5945
5980
 
5946
5981
  return res.result;
@@ -5957,7 +5992,7 @@ class Connection {
5957
5992
  const res = superstruct.create(unsafeRes, jsonRpcResultAndContext(superstruct.nullable(ParsedAccountInfoResult)));
5958
5993
 
5959
5994
  if ('error' in res) {
5960
- throw new Error('failed to get info about account ' + publicKey.toBase58() + ': ' + res.error.message);
5995
+ throw new SolanaJSONRPCError(res.error, `failed to get info about account ${publicKey.toBase58()}`);
5961
5996
  }
5962
5997
 
5963
5998
  return res.result;
@@ -5993,7 +6028,7 @@ class Connection {
5993
6028
  const res = superstruct.create(unsafeRes, jsonRpcResultAndContext(superstruct.array(superstruct.nullable(AccountInfoResult))));
5994
6029
 
5995
6030
  if ('error' in res) {
5996
- throw new Error('failed to get info for accounts ' + keys + ': ' + res.error.message);
6031
+ throw new SolanaJSONRPCError(res.error, `failed to get info for accounts ${keys}`);
5997
6032
  }
5998
6033
 
5999
6034
  return res.result;
@@ -6028,7 +6063,7 @@ class Connection {
6028
6063
  const res = superstruct.create(unsafeRes, jsonRpcResult(StakeActivationResult));
6029
6064
 
6030
6065
  if ('error' in res) {
6031
- throw new Error(`failed to get Stake Activation ${publicKey.toBase58()}: ${res.error.message}`);
6066
+ throw new SolanaJSONRPCError(res.error, `failed to get Stake Activation ${publicKey.toBase58()}`);
6032
6067
  }
6033
6068
 
6034
6069
  return res.result;
@@ -6056,7 +6091,7 @@ class Connection {
6056
6091
  const res = superstruct.create(unsafeRes, jsonRpcResult(superstruct.array(KeyedAccountInfoResult)));
6057
6092
 
6058
6093
  if ('error' in res) {
6059
- throw new Error('failed to get accounts owned by program ' + programId.toBase58() + ': ' + res.error.message);
6094
+ throw new SolanaJSONRPCError(res.error, `failed to get accounts owned by program ${programId.toBase58()}`);
6060
6095
  }
6061
6096
 
6062
6097
  return res.result;
@@ -6080,7 +6115,7 @@ class Connection {
6080
6115
  const res = superstruct.create(unsafeRes, jsonRpcResult(superstruct.array(KeyedParsedAccountInfoResult)));
6081
6116
 
6082
6117
  if ('error' in res) {
6083
- throw new Error('failed to get accounts owned by program ' + programId.toBase58() + ': ' + res.error.message);
6118
+ throw new SolanaJSONRPCError(res.error, `failed to get accounts owned by program ${programId.toBase58()}`);
6084
6119
  }
6085
6120
 
6086
6121
  return res.result;
@@ -6214,7 +6249,7 @@ class Connection {
6214
6249
  const res = superstruct.create(unsafeRes, jsonRpcResult(superstruct.array(ContactInfoResult)));
6215
6250
 
6216
6251
  if ('error' in res) {
6217
- throw new Error('failed to get cluster nodes: ' + res.error.message);
6252
+ throw new SolanaJSONRPCError(res.error, 'failed to get cluster nodes');
6218
6253
  }
6219
6254
 
6220
6255
  return res.result;
@@ -6231,7 +6266,7 @@ class Connection {
6231
6266
  const res = superstruct.create(unsafeRes, GetVoteAccounts);
6232
6267
 
6233
6268
  if ('error' in res) {
6234
- throw new Error('failed to get vote accounts: ' + res.error.message);
6269
+ throw new SolanaJSONRPCError(res.error, 'failed to get vote accounts');
6235
6270
  }
6236
6271
 
6237
6272
  return res.result;
@@ -6255,7 +6290,7 @@ class Connection {
6255
6290
  const res = superstruct.create(unsafeRes, jsonRpcResult(superstruct.number()));
6256
6291
 
6257
6292
  if ('error' in res) {
6258
- throw new Error('failed to get slot: ' + res.error.message);
6293
+ throw new SolanaJSONRPCError(res.error, 'failed to get slot');
6259
6294
  }
6260
6295
 
6261
6296
  return res.result;
@@ -6279,7 +6314,7 @@ class Connection {
6279
6314
  const res = superstruct.create(unsafeRes, jsonRpcResult(superstruct.string()));
6280
6315
 
6281
6316
  if ('error' in res) {
6282
- throw new Error('failed to get slot leader: ' + res.error.message);
6317
+ throw new SolanaJSONRPCError(res.error, 'failed to get slot leader');
6283
6318
  }
6284
6319
 
6285
6320
  return res.result;
@@ -6298,7 +6333,7 @@ class Connection {
6298
6333
  const res = superstruct.create(unsafeRes, jsonRpcResult(superstruct.array(PublicKeyFromString)));
6299
6334
 
6300
6335
  if ('error' in res) {
6301
- throw new Error('failed to get slot leaders: ' + res.error.message);
6336
+ throw new SolanaJSONRPCError(res.error, 'failed to get slot leaders');
6302
6337
  }
6303
6338
 
6304
6339
  return res.result;
@@ -6336,7 +6371,7 @@ class Connection {
6336
6371
  const res = superstruct.create(unsafeRes, GetSignatureStatusesRpcResult);
6337
6372
 
6338
6373
  if ('error' in res) {
6339
- throw new Error('failed to get signature status: ' + res.error.message);
6374
+ throw new SolanaJSONRPCError(res.error, 'failed to get signature status');
6340
6375
  }
6341
6376
 
6342
6377
  return res.result;
@@ -6360,7 +6395,7 @@ class Connection {
6360
6395
  const res = superstruct.create(unsafeRes, jsonRpcResult(superstruct.number()));
6361
6396
 
6362
6397
  if ('error' in res) {
6363
- throw new Error('failed to get transaction count: ' + res.error.message);
6398
+ throw new SolanaJSONRPCError(res.error, 'failed to get transaction count');
6364
6399
  }
6365
6400
 
6366
6401
  return res.result;
@@ -6391,7 +6426,7 @@ class Connection {
6391
6426
  const res = superstruct.create(unsafeRes, GetInflationGovernorRpcResult);
6392
6427
 
6393
6428
  if ('error' in res) {
6394
- throw new Error('failed to get inflation: ' + res.error.message);
6429
+ throw new SolanaJSONRPCError(res.error, 'failed to get inflation');
6395
6430
  }
6396
6431
 
6397
6432
  return res.result;
@@ -6417,7 +6452,7 @@ class Connection {
6417
6452
  const res = superstruct.create(unsafeRes, GetInflationRewardResult);
6418
6453
 
6419
6454
  if ('error' in res) {
6420
- throw new Error('failed to get inflation reward: ' + res.error.message);
6455
+ throw new SolanaJSONRPCError(res.error, 'failed to get inflation reward');
6421
6456
  }
6422
6457
 
6423
6458
  return res.result;
@@ -6441,7 +6476,7 @@ class Connection {
6441
6476
  const res = superstruct.create(unsafeRes, GetEpochInfoRpcResult);
6442
6477
 
6443
6478
  if ('error' in res) {
6444
- throw new Error('failed to get epoch info: ' + res.error.message);
6479
+ throw new SolanaJSONRPCError(res.error, 'failed to get epoch info');
6445
6480
  }
6446
6481
 
6447
6482
  return res.result;
@@ -6456,7 +6491,7 @@ class Connection {
6456
6491
  const res = superstruct.create(unsafeRes, GetEpochScheduleRpcResult);
6457
6492
 
6458
6493
  if ('error' in res) {
6459
- throw new Error('failed to get epoch schedule: ' + res.error.message);
6494
+ throw new SolanaJSONRPCError(res.error, 'failed to get epoch schedule');
6460
6495
  }
6461
6496
 
6462
6497
  const epochSchedule = res.result;
@@ -6473,7 +6508,7 @@ class Connection {
6473
6508
  const res = superstruct.create(unsafeRes, GetLeaderScheduleRpcResult);
6474
6509
 
6475
6510
  if ('error' in res) {
6476
- throw new Error('failed to get leader schedule: ' + res.error.message);
6511
+ throw new SolanaJSONRPCError(res.error, 'failed to get leader schedule');
6477
6512
  }
6478
6513
 
6479
6514
  return res.result;
@@ -6512,7 +6547,7 @@ class Connection {
6512
6547
  const res = superstruct.create(unsafeRes, GetRecentBlockhashAndContextRpcResult);
6513
6548
 
6514
6549
  if ('error' in res) {
6515
- throw new Error('failed to get recent blockhash: ' + res.error.message);
6550
+ throw new SolanaJSONRPCError(res.error, 'failed to get recent blockhash');
6516
6551
  }
6517
6552
 
6518
6553
  return res.result;
@@ -6524,13 +6559,11 @@ class Connection {
6524
6559
 
6525
6560
 
6526
6561
  async getRecentPerformanceSamples(limit) {
6527
- const args = this._buildArgs(limit ? [limit] : []);
6528
-
6529
- const unsafeRes = await this._rpcRequest('getRecentPerformanceSamples', args);
6562
+ const unsafeRes = await this._rpcRequest('getRecentPerformanceSamples', limit ? [limit] : []);
6530
6563
  const res = superstruct.create(unsafeRes, GetRecentPerformanceSamplesRpcResult);
6531
6564
 
6532
6565
  if ('error' in res) {
6533
- throw new Error('failed to get recent performance samples: ' + res.error.message);
6566
+ throw new SolanaJSONRPCError(res.error, 'failed to get recent performance samples');
6534
6567
  }
6535
6568
 
6536
6569
  return res.result;
@@ -6549,7 +6582,7 @@ class Connection {
6549
6582
  const res = superstruct.create(unsafeRes, GetFeeCalculatorRpcResult);
6550
6583
 
6551
6584
  if ('error' in res) {
6552
- throw new Error('failed to get fee calculator: ' + res.error.message);
6585
+ throw new SolanaJSONRPCError(res.error, 'failed to get fee calculator');
6553
6586
  }
6554
6587
 
6555
6588
  const {
@@ -6575,7 +6608,7 @@ class Connection {
6575
6608
  const res = superstruct.create(unsafeRes, jsonRpcResultAndContext(superstruct.nullable(superstruct.number())));
6576
6609
 
6577
6610
  if ('error' in res) {
6578
- throw new Error('failed to get slot: ' + res.error.message);
6611
+ throw new SolanaJSONRPCError(res.error, 'failed to get slot');
6579
6612
  }
6580
6613
 
6581
6614
  if (res.result === null) {
@@ -6634,7 +6667,7 @@ class Connection {
6634
6667
  const res = superstruct.create(unsafeRes, GetLatestBlockhashRpcResult);
6635
6668
 
6636
6669
  if ('error' in res) {
6637
- throw new Error('failed to get latest blockhash: ' + res.error.message);
6670
+ throw new SolanaJSONRPCError(res.error, 'failed to get latest blockhash');
6638
6671
  }
6639
6672
 
6640
6673
  return res.result;
@@ -6649,7 +6682,7 @@ class Connection {
6649
6682
  const res = superstruct.create(unsafeRes, jsonRpcResult(VersionResult));
6650
6683
 
6651
6684
  if ('error' in res) {
6652
- throw new Error('failed to get version: ' + res.error.message);
6685
+ throw new SolanaJSONRPCError(res.error, 'failed to get version');
6653
6686
  }
6654
6687
 
6655
6688
  return res.result;
@@ -6664,7 +6697,7 @@ class Connection {
6664
6697
  const res = superstruct.create(unsafeRes, jsonRpcResult(superstruct.string()));
6665
6698
 
6666
6699
  if ('error' in res) {
6667
- throw new Error('failed to get genesis hash: ' + res.error.message);
6700
+ throw new SolanaJSONRPCError(res.error, 'failed to get genesis hash');
6668
6701
  }
6669
6702
 
6670
6703
  return res.result;
@@ -6681,7 +6714,7 @@ class Connection {
6681
6714
  const res = superstruct.create(unsafeRes, GetBlockRpcResult);
6682
6715
 
6683
6716
  if ('error' in res) {
6684
- throw new Error('failed to get confirmed block: ' + res.error.message);
6717
+ throw new SolanaJSONRPCError(res.error, 'failed to get confirmed block');
6685
6718
  }
6686
6719
 
6687
6720
  const result = res.result;
@@ -6720,7 +6753,7 @@ class Connection {
6720
6753
  const res = superstruct.create(unsafeRes, jsonRpcResult(superstruct.number()));
6721
6754
 
6722
6755
  if ('error' in res) {
6723
- throw new Error('failed to get block height information: ' + res.error.message);
6756
+ throw new SolanaJSONRPCError(res.error, 'failed to get block height information');
6724
6757
  }
6725
6758
 
6726
6759
  return res.result;
@@ -6751,7 +6784,7 @@ class Connection {
6751
6784
  const res = superstruct.create(unsafeRes, BlockProductionResponseStruct);
6752
6785
 
6753
6786
  if ('error' in res) {
6754
- throw new Error('failed to get block production information: ' + res.error.message);
6787
+ throw new SolanaJSONRPCError(res.error, 'failed to get block production information');
6755
6788
  }
6756
6789
 
6757
6790
  return res.result;
@@ -6768,7 +6801,7 @@ class Connection {
6768
6801
  const res = superstruct.create(unsafeRes, GetTransactionRpcResult);
6769
6802
 
6770
6803
  if ('error' in res) {
6771
- throw new Error('failed to get transaction: ' + res.error.message);
6804
+ throw new SolanaJSONRPCError(res.error, 'failed to get transaction');
6772
6805
  }
6773
6806
 
6774
6807
  const result = res.result;
@@ -6791,7 +6824,7 @@ class Connection {
6791
6824
  const res = superstruct.create(unsafeRes, GetParsedTransactionRpcResult);
6792
6825
 
6793
6826
  if ('error' in res) {
6794
- throw new Error('failed to get transaction: ' + res.error.message);
6827
+ throw new SolanaJSONRPCError(res.error, 'failed to get transaction');
6795
6828
  }
6796
6829
 
6797
6830
  return res.result;
@@ -6815,7 +6848,7 @@ class Connection {
6815
6848
  const res = superstruct.create(unsafeRes, GetParsedTransactionRpcResult);
6816
6849
 
6817
6850
  if ('error' in res) {
6818
- throw new Error('failed to get transactions: ' + res.error.message);
6851
+ throw new SolanaJSONRPCError(res.error, 'failed to get transactions');
6819
6852
  }
6820
6853
 
6821
6854
  return res.result;
@@ -6842,7 +6875,7 @@ class Connection {
6842
6875
  const res = superstruct.create(unsafeRes, GetTransactionRpcResult);
6843
6876
 
6844
6877
  if ('error' in res) {
6845
- throw new Error('failed to get transactions: ' + res.error.message);
6878
+ throw new SolanaJSONRPCError(res.error, 'failed to get transactions');
6846
6879
  }
6847
6880
 
6848
6881
  const result = res.result;
@@ -6870,7 +6903,7 @@ class Connection {
6870
6903
  const res = superstruct.create(unsafeRes, GetConfirmedBlockRpcResult);
6871
6904
 
6872
6905
  if ('error' in res) {
6873
- throw new Error('failed to get confirmed block: ' + res.error.message);
6906
+ throw new SolanaJSONRPCError(res.error, 'failed to get confirmed block');
6874
6907
  }
6875
6908
 
6876
6909
  const result = res.result;
@@ -6917,7 +6950,7 @@ class Connection {
6917
6950
  const res = superstruct.create(unsafeRes, jsonRpcResult(superstruct.array(superstruct.number())));
6918
6951
 
6919
6952
  if ('error' in res) {
6920
- throw new Error('failed to get blocks: ' + res.error.message);
6953
+ throw new SolanaJSONRPCError(res.error, 'failed to get blocks');
6921
6954
  }
6922
6955
 
6923
6956
  return res.result;
@@ -6937,7 +6970,7 @@ class Connection {
6937
6970
  const res = superstruct.create(unsafeRes, GetBlockSignaturesRpcResult);
6938
6971
 
6939
6972
  if ('error' in res) {
6940
- throw new Error('failed to get block: ' + res.error.message);
6973
+ throw new SolanaJSONRPCError(res.error, 'failed to get block');
6941
6974
  }
6942
6975
 
6943
6976
  const result = res.result;
@@ -6965,7 +6998,7 @@ class Connection {
6965
6998
  const res = superstruct.create(unsafeRes, GetBlockSignaturesRpcResult);
6966
6999
 
6967
7000
  if ('error' in res) {
6968
- throw new Error('failed to get confirmed block: ' + res.error.message);
7001
+ throw new SolanaJSONRPCError(res.error, 'failed to get confirmed block');
6969
7002
  }
6970
7003
 
6971
7004
  const result = res.result;
@@ -6990,7 +7023,7 @@ class Connection {
6990
7023
  const res = superstruct.create(unsafeRes, GetTransactionRpcResult);
6991
7024
 
6992
7025
  if ('error' in res) {
6993
- throw new Error('failed to get transaction: ' + res.error.message);
7026
+ throw new SolanaJSONRPCError(res.error, 'failed to get transaction');
6994
7027
  }
6995
7028
 
6996
7029
  const result = res.result;
@@ -7015,7 +7048,7 @@ class Connection {
7015
7048
  const res = superstruct.create(unsafeRes, GetParsedTransactionRpcResult);
7016
7049
 
7017
7050
  if ('error' in res) {
7018
- throw new Error('failed to get confirmed transaction: ' + res.error.message);
7051
+ throw new SolanaJSONRPCError(res.error, 'failed to get confirmed transaction');
7019
7052
  }
7020
7053
 
7021
7054
  return res.result;
@@ -7041,7 +7074,7 @@ class Connection {
7041
7074
  const res = superstruct.create(unsafeRes, GetParsedTransactionRpcResult);
7042
7075
 
7043
7076
  if ('error' in res) {
7044
- throw new Error('failed to get confirmed transactions: ' + res.error.message);
7077
+ throw new SolanaJSONRPCError(res.error, 'failed to get confirmed transactions');
7045
7078
  }
7046
7079
 
7047
7080
  return res.result;
@@ -7130,7 +7163,7 @@ class Connection {
7130
7163
  const res = superstruct.create(unsafeRes, GetConfirmedSignaturesForAddress2RpcResult);
7131
7164
 
7132
7165
  if ('error' in res) {
7133
- throw new Error('failed to get confirmed signatures for address: ' + res.error.message);
7166
+ throw new SolanaJSONRPCError(res.error, 'failed to get confirmed signatures for address');
7134
7167
  }
7135
7168
 
7136
7169
  return res.result;
@@ -7152,7 +7185,7 @@ class Connection {
7152
7185
  const res = superstruct.create(unsafeRes, GetSignaturesForAddressRpcResult);
7153
7186
 
7154
7187
  if ('error' in res) {
7155
- throw new Error('failed to get signatures for address: ' + res.error.message);
7188
+ throw new SolanaJSONRPCError(res.error, 'failed to get signatures for address');
7156
7189
  }
7157
7190
 
7158
7191
  return res.result;
@@ -7209,7 +7242,7 @@ class Connection {
7209
7242
  const res = superstruct.create(unsafeRes, RequestAirdropRpcResult);
7210
7243
 
7211
7244
  if ('error' in res) {
7212
- throw new Error('airdrop to ' + to.toBase58() + ' failed: ' + res.error.message);
7245
+ throw new SolanaJSONRPCError(res.error, `airdrop to ${to.toBase58()} failed`);
7213
7246
  }
7214
7247
 
7215
7248
  return res.result;
@@ -7439,7 +7472,7 @@ class Connection {
7439
7472
  const skipPreflight = options && options.skipPreflight;
7440
7473
  const preflightCommitment = options && options.preflightCommitment || this.commitment;
7441
7474
 
7442
- if (options && options.maxRetries) {
7475
+ if (options && options.maxRetries != null) {
7443
7476
  config.maxRetries = options.maxRetries;
7444
7477
  }
7445
7478
 
@@ -9949,6 +9982,8 @@ exports.SYSVAR_SLOT_HISTORY_PUBKEY = SYSVAR_SLOT_HISTORY_PUBKEY;
9949
9982
  exports.SYSVAR_STAKE_HISTORY_PUBKEY = SYSVAR_STAKE_HISTORY_PUBKEY;
9950
9983
  exports.Secp256k1Program = Secp256k1Program;
9951
9984
  exports.SendTransactionError = SendTransactionError;
9985
+ exports.SolanaJSONRPCError = SolanaJSONRPCError;
9986
+ exports.SolanaJSONRPCErrorCode = SolanaJSONRPCErrorCode;
9952
9987
  exports.StakeAuthorizationLayout = StakeAuthorizationLayout;
9953
9988
  exports.StakeInstruction = StakeInstruction;
9954
9989
  exports.StakeProgram = StakeProgram;