@solana/web3.js 1.32.0 → 1.32.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -2922,7 +2922,8 @@ const SYSVAR_STAKE_HISTORY_PUBKEY = new PublicKey('SysvarStakeHistory11111111111
2922
2922
  async function sendAndConfirmTransaction(connection, transaction, signers, options) {
2923
2923
  const sendOptions = options && {
2924
2924
  skipPreflight: options.skipPreflight,
2925
- preflightCommitment: options.preflightCommitment || options.commitment
2925
+ preflightCommitment: options.preflightCommitment || options.commitment,
2926
+ maxRetries: options.maxRetries
2926
2927
  };
2927
2928
  const signature = await connection.sendTransaction(transaction, signers, sendOptions);
2928
2929
  const status = (await connection.confirmTransaction(signature, options && options.commitment)).value;
@@ -5373,8 +5374,31 @@ const ParsedConfirmedTransactionMetaResult = type({
5373
5374
  preTokenBalances: optional(nullable(array(TokenBalanceResult))),
5374
5375
  postTokenBalances: optional(nullable(array(TokenBalanceResult)))
5375
5376
  });
5377
+ /**
5378
+ * Expected JSON RPC response for the "getBlock" message
5379
+ */
5380
+
5381
+ const GetBlockRpcResult = jsonRpcResult(nullable(type({
5382
+ blockhash: string(),
5383
+ previousBlockhash: string(),
5384
+ parentSlot: number(),
5385
+ transactions: array(type({
5386
+ transaction: ConfirmedTransactionResult,
5387
+ meta: nullable(ConfirmedTransactionMetaResult)
5388
+ })),
5389
+ rewards: optional(array(type({
5390
+ pubkey: string(),
5391
+ lamports: number(),
5392
+ postBalance: nullable(number()),
5393
+ rewardType: nullable(string())
5394
+ }))),
5395
+ blockTime: nullable(number()),
5396
+ blockHeight: nullable(number())
5397
+ })));
5376
5398
  /**
5377
5399
  * Expected JSON RPC response for the "getConfirmedBlock" message
5400
+ *
5401
+ * @deprecated Deprecated since Solana v1.8.0. Please use {@link GetBlockRpcResult} instead.
5378
5402
  */
5379
5403
 
5380
5404
  const GetConfirmedBlockRpcResult = jsonRpcResult(nullable(type({
@@ -5394,10 +5418,10 @@ const GetConfirmedBlockRpcResult = jsonRpcResult(nullable(type({
5394
5418
  blockTime: nullable(number())
5395
5419
  })));
5396
5420
  /**
5397
- * Expected JSON RPC response for the "getConfirmedBlockSignatures" message
5421
+ * Expected JSON RPC response for the "getBlock" message
5398
5422
  */
5399
5423
 
5400
- const GetConfirmedBlockSignaturesRpcResult = jsonRpcResult(nullable(type({
5424
+ const GetBlockSignaturesRpcResult = jsonRpcResult(nullable(type({
5401
5425
  blockhash: string(),
5402
5426
  previousBlockhash: string(),
5403
5427
  parentSlot: number(),
@@ -5405,20 +5429,20 @@ const GetConfirmedBlockSignaturesRpcResult = jsonRpcResult(nullable(type({
5405
5429
  blockTime: nullable(number())
5406
5430
  })));
5407
5431
  /**
5408
- * Expected JSON RPC response for the "getConfirmedTransaction" message
5432
+ * Expected JSON RPC response for the "getTransaction" message
5409
5433
  */
5410
5434
 
5411
- const GetConfirmedTransactionRpcResult = jsonRpcResult(nullable(type({
5435
+ const GetTransactionRpcResult = jsonRpcResult(nullable(type({
5412
5436
  slot: number(),
5413
5437
  meta: ConfirmedTransactionMetaResult,
5414
5438
  blockTime: optional(nullable(number())),
5415
5439
  transaction: ConfirmedTransactionResult
5416
5440
  })));
5417
5441
  /**
5418
- * Expected JSON RPC response for the "getConfirmedTransaction" message
5442
+ * Expected parsed JSON RPC response for the "getTransaction" message
5419
5443
  */
5420
5444
 
5421
- const GetParsedConfirmedTransactionRpcResult = jsonRpcResult(nullable(type({
5445
+ const GetParsedTransactionRpcResult = jsonRpcResult(nullable(type({
5422
5446
  slot: number(),
5423
5447
  transaction: ParsedConfirmedTransactionResult,
5424
5448
  meta: nullable(ParsedConfirmedTransactionMetaResult),
@@ -5426,6 +5450,8 @@ const GetParsedConfirmedTransactionRpcResult = jsonRpcResult(nullable(type({
5426
5450
  })));
5427
5451
  /**
5428
5452
  * Expected JSON RPC response for the "getRecentBlockhash" message
5453
+ *
5454
+ * @deprecated Deprecated since Solana v1.8.0. Please use {@link GetLatestBlockhashRpcResult} instead.
5429
5455
  */
5430
5456
 
5431
5457
  const GetRecentBlockhashAndContextRpcResult = jsonRpcResultAndContext(type({
@@ -5434,6 +5460,14 @@ const GetRecentBlockhashAndContextRpcResult = jsonRpcResultAndContext(type({
5434
5460
  lamportsPerSignature: number()
5435
5461
  })
5436
5462
  }));
5463
+ /**
5464
+ * Expected JSON RPC response for the "getLatestBlockhash" message
5465
+ */
5466
+
5467
+ const GetLatestBlockhashRpcResult = jsonRpcResultAndContext(type({
5468
+ blockhash: string(),
5469
+ lastValidBlockHeight: number()
5470
+ }));
5437
5471
  const PerfSampleResult = type({
5438
5472
  slot: number(),
5439
5473
  numTransactions: number(),
@@ -6378,6 +6412,8 @@ class Connection {
6378
6412
  /**
6379
6413
  * Fetch a recent blockhash from the cluster, return with context
6380
6414
  * @return {Promise<RpcResponseAndContext<{blockhash: Blockhash, feeCalculator: FeeCalculator}>>}
6415
+ *
6416
+ * @deprecated Deprecated since Solana v1.8.0. Please use {@link getLatestBlockhash} instead.
6381
6417
  */
6382
6418
 
6383
6419
 
@@ -6413,6 +6449,8 @@ class Connection {
6413
6449
  }
6414
6450
  /**
6415
6451
  * Fetch the fee calculator for a recent blockhash from the cluster, return with context
6452
+ *
6453
+ * @deprecated Deprecated since Solana v1.8.0. Please use {@link getFeeForMessage} instead.
6416
6454
  */
6417
6455
 
6418
6456
 
@@ -6461,6 +6499,8 @@ class Connection {
6461
6499
  /**
6462
6500
  * Fetch a recent blockhash from the cluster
6463
6501
  * @return {Promise<{blockhash: Blockhash, feeCalculator: FeeCalculator}>}
6502
+ *
6503
+ * @deprecated Deprecated since Solana v1.8.0. Please use {@link getLatestBlockhash} instead.
6464
6504
  */
6465
6505
 
6466
6506
 
@@ -6472,6 +6512,38 @@ class Connection {
6472
6512
  throw new Error('failed to get recent blockhash: ' + e);
6473
6513
  }
6474
6514
  }
6515
+ /**
6516
+ * Fetch the latest blockhash from the cluster
6517
+ * @return {Promise<{blockhash: Blockhash, lastValidBlockHeight: number}>}
6518
+ */
6519
+
6520
+
6521
+ async getLatestBlockhash(commitment) {
6522
+ try {
6523
+ const res = await this.getLatestBlockhashAndContext(commitment);
6524
+ return res.value;
6525
+ } catch (e) {
6526
+ throw new Error('failed to get recent blockhash: ' + e);
6527
+ }
6528
+ }
6529
+ /**
6530
+ * Fetch the latest blockhash from the cluster
6531
+ * @return {Promise<{blockhash: Blockhash, lastValidBlockHeight: number}>}
6532
+ */
6533
+
6534
+
6535
+ async getLatestBlockhashAndContext(commitment) {
6536
+ const args = this._buildArgs([], commitment);
6537
+
6538
+ const unsafeRes = await this._rpcRequest('getLatestBlockhash', args);
6539
+ const res = create(unsafeRes, GetLatestBlockhashRpcResult);
6540
+
6541
+ if ('error' in res) {
6542
+ throw new Error('failed to get latest blockhash: ' + res.error.message);
6543
+ }
6544
+
6545
+ return res.result;
6546
+ }
6475
6547
  /**
6476
6548
  * Fetch the node version
6477
6549
  */
@@ -6510,8 +6582,8 @@ class Connection {
6510
6582
  async getBlock(slot, opts) {
6511
6583
  const args = this._buildArgsAtLeastConfirmed([slot], opts && opts.commitment);
6512
6584
 
6513
- const unsafeRes = await this._rpcRequest('getConfirmedBlock', args);
6514
- const res = create(unsafeRes, GetConfirmedBlockRpcResult);
6585
+ const unsafeRes = await this._rpcRequest('getBlock', args);
6586
+ const res = create(unsafeRes, GetBlockRpcResult);
6515
6587
 
6516
6588
  if ('error' in res) {
6517
6589
  throw new Error('failed to get confirmed block: ' + res.error.message);
@@ -6535,18 +6607,18 @@ class Connection {
6535
6607
  };
6536
6608
  }
6537
6609
  /**
6538
- * Fetch a processed transaction from the cluster.
6610
+ * Fetch a confirmed or finalized transaction from the cluster.
6539
6611
  */
6540
6612
 
6541
6613
 
6542
6614
  async getTransaction(signature, opts) {
6543
6615
  const args = this._buildArgsAtLeastConfirmed([signature], opts && opts.commitment);
6544
6616
 
6545
- const unsafeRes = await this._rpcRequest('getConfirmedTransaction', args);
6546
- const res = create(unsafeRes, GetConfirmedTransactionRpcResult);
6617
+ const unsafeRes = await this._rpcRequest('getTransaction', args);
6618
+ const res = create(unsafeRes, GetTransactionRpcResult);
6547
6619
 
6548
6620
  if ('error' in res) {
6549
- throw new Error('failed to get confirmed transaction: ' + res.error.message);
6621
+ throw new Error('failed to get transaction: ' + res.error.message);
6550
6622
  }
6551
6623
 
6552
6624
  const result = res.result;
@@ -6557,6 +6629,49 @@ class Connection {
6557
6629
  }
6558
6630
  };
6559
6631
  }
6632
+ /**
6633
+ * Fetch parsed transaction details for a confirmed or finalized transaction
6634
+ */
6635
+
6636
+
6637
+ async getParsedTransaction(signature, commitment) {
6638
+ const args = this._buildArgsAtLeastConfirmed([signature], commitment, 'jsonParsed');
6639
+
6640
+ const unsafeRes = await this._rpcRequest('getTransaction', args);
6641
+ const res = create(unsafeRes, GetParsedTransactionRpcResult);
6642
+
6643
+ if ('error' in res) {
6644
+ throw new Error('failed to get transaction: ' + res.error.message);
6645
+ }
6646
+
6647
+ return res.result;
6648
+ }
6649
+ /**
6650
+ * Fetch parsed transaction details for a batch of confirmed transactions
6651
+ */
6652
+
6653
+
6654
+ async getParsedTransactions(signatures, commitment) {
6655
+ const batch = signatures.map(signature => {
6656
+ const args = this._buildArgsAtLeastConfirmed([signature], commitment, 'jsonParsed');
6657
+
6658
+ return {
6659
+ methodName: 'getTransaction',
6660
+ args
6661
+ };
6662
+ });
6663
+ const unsafeRes = await this._rpcBatchRequest(batch);
6664
+ const res = unsafeRes.map(unsafeRes => {
6665
+ const res = create(unsafeRes, GetParsedTransactionRpcResult);
6666
+
6667
+ if ('error' in res) {
6668
+ throw new Error('failed to get transactions: ' + res.error.message);
6669
+ }
6670
+
6671
+ return res.result;
6672
+ });
6673
+ return res;
6674
+ }
6560
6675
  /**
6561
6676
  * Fetch a list of Transactions and transaction statuses from the cluster
6562
6677
  * for a confirmed block.
@@ -6566,18 +6681,39 @@ class Connection {
6566
6681
 
6567
6682
 
6568
6683
  async getConfirmedBlock(slot, commitment) {
6569
- const result = await this.getBlock(slot, {
6570
- commitment
6571
- });
6684
+ const args = this._buildArgsAtLeastConfirmed([slot], commitment);
6685
+
6686
+ const unsafeRes = await this._rpcRequest('getConfirmedBlock', args);
6687
+ const res = create(unsafeRes, GetConfirmedBlockRpcResult);
6688
+
6689
+ if ('error' in res) {
6690
+ throw new Error('failed to get confirmed block: ' + res.error.message);
6691
+ }
6692
+
6693
+ const result = res.result;
6572
6694
 
6573
6695
  if (!result) {
6574
6696
  throw new Error('Confirmed block ' + slot + ' not found');
6575
6697
  }
6576
6698
 
6577
- return { ...result,
6699
+ const block = { ...result,
6578
6700
  transactions: result.transactions.map(({
6579
6701
  transaction,
6580
6702
  meta
6703
+ }) => {
6704
+ const message = new Message(transaction.message);
6705
+ return {
6706
+ meta,
6707
+ transaction: { ...transaction,
6708
+ message
6709
+ }
6710
+ };
6711
+ })
6712
+ };
6713
+ return { ...block,
6714
+ transactions: block.transactions.map(({
6715
+ transaction,
6716
+ meta
6581
6717
  }) => {
6582
6718
  return {
6583
6719
  meta,
@@ -6594,7 +6730,7 @@ class Connection {
6594
6730
  async getBlocks(startSlot, endSlot, commitment) {
6595
6731
  const args = this._buildArgsAtLeastConfirmed(endSlot !== undefined ? [startSlot, endSlot] : [startSlot], commitment);
6596
6732
 
6597
- const unsafeRes = await this._rpcRequest('getConfirmedBlocks', args);
6733
+ const unsafeRes = await this._rpcRequest('getBlocks', args);
6598
6734
  const res = create(unsafeRes, jsonRpcResult(array(number())));
6599
6735
 
6600
6736
  if ('error' in res) {
@@ -6603,8 +6739,36 @@ class Connection {
6603
6739
 
6604
6740
  return res.result;
6605
6741
  }
6742
+ /**
6743
+ * Fetch a list of Signatures from the cluster for a block, excluding rewards
6744
+ */
6745
+
6746
+
6747
+ async getBlockSignatures(slot, commitment) {
6748
+ const args = this._buildArgsAtLeastConfirmed([slot], commitment, undefined, {
6749
+ transactionDetails: 'signatures',
6750
+ rewards: false
6751
+ });
6752
+
6753
+ const unsafeRes = await this._rpcRequest('getBlock', args);
6754
+ const res = create(unsafeRes, GetBlockSignaturesRpcResult);
6755
+
6756
+ if ('error' in res) {
6757
+ throw new Error('failed to get block: ' + res.error.message);
6758
+ }
6759
+
6760
+ const result = res.result;
6761
+
6762
+ if (!result) {
6763
+ throw new Error('Block ' + slot + ' not found');
6764
+ }
6765
+
6766
+ return result;
6767
+ }
6606
6768
  /**
6607
6769
  * Fetch a list of Signatures from the cluster for a confirmed block, excluding rewards
6770
+ *
6771
+ * @deprecated Deprecated since Solana v1.8.0. Please use {@link getBlockSignatures} instead.
6608
6772
  */
6609
6773
 
6610
6774
 
@@ -6615,7 +6779,7 @@ class Connection {
6615
6779
  });
6616
6780
 
6617
6781
  const unsafeRes = await this._rpcRequest('getConfirmedBlock', args);
6618
- const res = create(unsafeRes, GetConfirmedBlockSignaturesRpcResult);
6782
+ const res = create(unsafeRes, GetBlockSignaturesRpcResult);
6619
6783
 
6620
6784
  if ('error' in res) {
6621
6785
  throw new Error('failed to get confirmed block: ' + res.error.message);
@@ -6631,24 +6795,33 @@ class Connection {
6631
6795
  }
6632
6796
  /**
6633
6797
  * Fetch a transaction details for a confirmed transaction
6798
+ *
6799
+ * @deprecated Deprecated since Solana v1.8.0. Please use {@link getTransaction} instead.
6634
6800
  */
6635
6801
 
6636
6802
 
6637
6803
  async getConfirmedTransaction(signature, commitment) {
6638
- const result = await this.getTransaction(signature, {
6639
- commitment
6640
- });
6804
+ const args = this._buildArgsAtLeastConfirmed([signature], commitment);
6805
+
6806
+ const unsafeRes = await this._rpcRequest('getConfirmedTransaction', args);
6807
+ const res = create(unsafeRes, GetTransactionRpcResult);
6808
+
6809
+ if ('error' in res) {
6810
+ throw new Error('failed to get transaction: ' + res.error.message);
6811
+ }
6812
+
6813
+ const result = res.result;
6641
6814
  if (!result) return result;
6642
- const {
6643
- message,
6644
- signatures
6645
- } = result.transaction;
6815
+ const message = new Message(result.transaction.message);
6816
+ const signatures = result.transaction.signatures;
6646
6817
  return { ...result,
6647
6818
  transaction: Transaction.populate(message, signatures)
6648
6819
  };
6649
6820
  }
6650
6821
  /**
6651
6822
  * Fetch parsed transaction details for a confirmed transaction
6823
+ *
6824
+ * @deprecated Deprecated since Solana v1.8.0. Please use {@link getParsedTransaction} instead.
6652
6825
  */
6653
6826
 
6654
6827
 
@@ -6656,7 +6829,7 @@ class Connection {
6656
6829
  const args = this._buildArgsAtLeastConfirmed([signature], commitment, 'jsonParsed');
6657
6830
 
6658
6831
  const unsafeRes = await this._rpcRequest('getConfirmedTransaction', args);
6659
- const res = create(unsafeRes, GetParsedConfirmedTransactionRpcResult);
6832
+ const res = create(unsafeRes, GetParsedTransactionRpcResult);
6660
6833
 
6661
6834
  if ('error' in res) {
6662
6835
  throw new Error('failed to get confirmed transaction: ' + res.error.message);
@@ -6666,6 +6839,8 @@ class Connection {
6666
6839
  }
6667
6840
  /**
6668
6841
  * Fetch parsed transaction details for a batch of confirmed transactions
6842
+ *
6843
+ * @deprecated Deprecated since Solana v1.8.0. Please use {@link getParsedTransactions} instead.
6669
6844
  */
6670
6845
 
6671
6846
 
@@ -6680,7 +6855,7 @@ class Connection {
6680
6855
  });
6681
6856
  const unsafeRes = await this._rpcBatchRequest(batch);
6682
6857
  const res = unsafeRes.map(unsafeRes => {
6683
- const res = create(unsafeRes, GetParsedConfirmedTransactionRpcResult);
6858
+ const res = create(unsafeRes, GetParsedTransactionRpcResult);
6684
6859
 
6685
6860
  if ('error' in res) {
6686
6861
  throw new Error('failed to get confirmed transactions: ' + res.error.message);
@@ -7070,6 +7245,10 @@ class Connection {
7070
7245
  const skipPreflight = options && options.skipPreflight;
7071
7246
  const preflightCommitment = options && options.preflightCommitment || this.commitment;
7072
7247
 
7248
+ if (options && options.maxRetries) {
7249
+ config.maxRetries = options.maxRetries;
7250
+ }
7251
+
7073
7252
  if (skipPreflight) {
7074
7253
  config.skipPreflight = skipPreflight;
7075
7254
  }
@@ -9064,12 +9243,12 @@ const endpoint = {
9064
9243
  http: {
9065
9244
  devnet: 'http://api.devnet.solana.com',
9066
9245
  testnet: 'http://api.testnet.solana.com',
9067
- 'mainnet-beta': 'http://api.mainnet-beta.solana.com'
9246
+ 'mainnet-beta': 'http://api.mainnet-beta.solana.com/'
9068
9247
  },
9069
9248
  https: {
9070
9249
  devnet: 'https://api.devnet.solana.com',
9071
9250
  testnet: 'https://api.testnet.solana.com',
9072
- 'mainnet-beta': 'https://api.mainnet-beta.solana.com'
9251
+ 'mainnet-beta': 'https://api.mainnet-beta.solana.com/'
9073
9252
  }
9074
9253
  };
9075
9254