@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.
package/lib/index.cjs.js CHANGED
@@ -2964,7 +2964,8 @@ const SYSVAR_STAKE_HISTORY_PUBKEY = new PublicKey('SysvarStakeHistory11111111111
2964
2964
  async function sendAndConfirmTransaction(connection, transaction, signers, options) {
2965
2965
  const sendOptions = options && {
2966
2966
  skipPreflight: options.skipPreflight,
2967
- preflightCommitment: options.preflightCommitment || options.commitment
2967
+ preflightCommitment: options.preflightCommitment || options.commitment,
2968
+ maxRetries: options.maxRetries
2968
2969
  };
2969
2970
  const signature = await connection.sendTransaction(transaction, signers, sendOptions);
2970
2971
  const status = (await connection.confirmTransaction(signature, options && options.commitment)).value;
@@ -4909,8 +4910,31 @@ const ParsedConfirmedTransactionMetaResult = superstruct.type({
4909
4910
  preTokenBalances: superstruct.optional(superstruct.nullable(superstruct.array(TokenBalanceResult))),
4910
4911
  postTokenBalances: superstruct.optional(superstruct.nullable(superstruct.array(TokenBalanceResult)))
4911
4912
  });
4913
+ /**
4914
+ * Expected JSON RPC response for the "getBlock" message
4915
+ */
4916
+
4917
+ const GetBlockRpcResult = jsonRpcResult(superstruct.nullable(superstruct.type({
4918
+ blockhash: superstruct.string(),
4919
+ previousBlockhash: superstruct.string(),
4920
+ parentSlot: superstruct.number(),
4921
+ transactions: superstruct.array(superstruct.type({
4922
+ transaction: ConfirmedTransactionResult,
4923
+ meta: superstruct.nullable(ConfirmedTransactionMetaResult)
4924
+ })),
4925
+ rewards: superstruct.optional(superstruct.array(superstruct.type({
4926
+ pubkey: superstruct.string(),
4927
+ lamports: superstruct.number(),
4928
+ postBalance: superstruct.nullable(superstruct.number()),
4929
+ rewardType: superstruct.nullable(superstruct.string())
4930
+ }))),
4931
+ blockTime: superstruct.nullable(superstruct.number()),
4932
+ blockHeight: superstruct.nullable(superstruct.number())
4933
+ })));
4912
4934
  /**
4913
4935
  * Expected JSON RPC response for the "getConfirmedBlock" message
4936
+ *
4937
+ * @deprecated Deprecated since Solana v1.8.0. Please use {@link GetBlockRpcResult} instead.
4914
4938
  */
4915
4939
 
4916
4940
  const GetConfirmedBlockRpcResult = jsonRpcResult(superstruct.nullable(superstruct.type({
@@ -4930,10 +4954,10 @@ const GetConfirmedBlockRpcResult = jsonRpcResult(superstruct.nullable(superstruc
4930
4954
  blockTime: superstruct.nullable(superstruct.number())
4931
4955
  })));
4932
4956
  /**
4933
- * Expected JSON RPC response for the "getConfirmedBlockSignatures" message
4957
+ * Expected JSON RPC response for the "getBlock" message
4934
4958
  */
4935
4959
 
4936
- const GetConfirmedBlockSignaturesRpcResult = jsonRpcResult(superstruct.nullable(superstruct.type({
4960
+ const GetBlockSignaturesRpcResult = jsonRpcResult(superstruct.nullable(superstruct.type({
4937
4961
  blockhash: superstruct.string(),
4938
4962
  previousBlockhash: superstruct.string(),
4939
4963
  parentSlot: superstruct.number(),
@@ -4941,20 +4965,20 @@ const GetConfirmedBlockSignaturesRpcResult = jsonRpcResult(superstruct.nullable(
4941
4965
  blockTime: superstruct.nullable(superstruct.number())
4942
4966
  })));
4943
4967
  /**
4944
- * Expected JSON RPC response for the "getConfirmedTransaction" message
4968
+ * Expected JSON RPC response for the "getTransaction" message
4945
4969
  */
4946
4970
 
4947
- const GetConfirmedTransactionRpcResult = jsonRpcResult(superstruct.nullable(superstruct.type({
4971
+ const GetTransactionRpcResult = jsonRpcResult(superstruct.nullable(superstruct.type({
4948
4972
  slot: superstruct.number(),
4949
4973
  meta: ConfirmedTransactionMetaResult,
4950
4974
  blockTime: superstruct.optional(superstruct.nullable(superstruct.number())),
4951
4975
  transaction: ConfirmedTransactionResult
4952
4976
  })));
4953
4977
  /**
4954
- * Expected JSON RPC response for the "getConfirmedTransaction" message
4978
+ * Expected parsed JSON RPC response for the "getTransaction" message
4955
4979
  */
4956
4980
 
4957
- const GetParsedConfirmedTransactionRpcResult = jsonRpcResult(superstruct.nullable(superstruct.type({
4981
+ const GetParsedTransactionRpcResult = jsonRpcResult(superstruct.nullable(superstruct.type({
4958
4982
  slot: superstruct.number(),
4959
4983
  transaction: ParsedConfirmedTransactionResult,
4960
4984
  meta: superstruct.nullable(ParsedConfirmedTransactionMetaResult),
@@ -4962,6 +4986,8 @@ const GetParsedConfirmedTransactionRpcResult = jsonRpcResult(superstruct.nullabl
4962
4986
  })));
4963
4987
  /**
4964
4988
  * Expected JSON RPC response for the "getRecentBlockhash" message
4989
+ *
4990
+ * @deprecated Deprecated since Solana v1.8.0. Please use {@link GetLatestBlockhashRpcResult} instead.
4965
4991
  */
4966
4992
 
4967
4993
  const GetRecentBlockhashAndContextRpcResult = jsonRpcResultAndContext(superstruct.type({
@@ -4970,6 +4996,14 @@ const GetRecentBlockhashAndContextRpcResult = jsonRpcResultAndContext(superstruc
4970
4996
  lamportsPerSignature: superstruct.number()
4971
4997
  })
4972
4998
  }));
4999
+ /**
5000
+ * Expected JSON RPC response for the "getLatestBlockhash" message
5001
+ */
5002
+
5003
+ const GetLatestBlockhashRpcResult = jsonRpcResultAndContext(superstruct.type({
5004
+ blockhash: superstruct.string(),
5005
+ lastValidBlockHeight: superstruct.number()
5006
+ }));
4973
5007
  const PerfSampleResult = superstruct.type({
4974
5008
  slot: superstruct.number(),
4975
5009
  numTransactions: superstruct.number(),
@@ -5914,6 +5948,8 @@ class Connection {
5914
5948
  /**
5915
5949
  * Fetch a recent blockhash from the cluster, return with context
5916
5950
  * @return {Promise<RpcResponseAndContext<{blockhash: Blockhash, feeCalculator: FeeCalculator}>>}
5951
+ *
5952
+ * @deprecated Deprecated since Solana v1.8.0. Please use {@link getLatestBlockhash} instead.
5917
5953
  */
5918
5954
 
5919
5955
 
@@ -5949,6 +5985,8 @@ class Connection {
5949
5985
  }
5950
5986
  /**
5951
5987
  * Fetch the fee calculator for a recent blockhash from the cluster, return with context
5988
+ *
5989
+ * @deprecated Deprecated since Solana v1.8.0. Please use {@link getFeeForMessage} instead.
5952
5990
  */
5953
5991
 
5954
5992
 
@@ -5997,6 +6035,8 @@ class Connection {
5997
6035
  /**
5998
6036
  * Fetch a recent blockhash from the cluster
5999
6037
  * @return {Promise<{blockhash: Blockhash, feeCalculator: FeeCalculator}>}
6038
+ *
6039
+ * @deprecated Deprecated since Solana v1.8.0. Please use {@link getLatestBlockhash} instead.
6000
6040
  */
6001
6041
 
6002
6042
 
@@ -6008,6 +6048,38 @@ class Connection {
6008
6048
  throw new Error('failed to get recent blockhash: ' + e);
6009
6049
  }
6010
6050
  }
6051
+ /**
6052
+ * Fetch the latest blockhash from the cluster
6053
+ * @return {Promise<{blockhash: Blockhash, lastValidBlockHeight: number}>}
6054
+ */
6055
+
6056
+
6057
+ async getLatestBlockhash(commitment) {
6058
+ try {
6059
+ const res = await this.getLatestBlockhashAndContext(commitment);
6060
+ return res.value;
6061
+ } catch (e) {
6062
+ throw new Error('failed to get recent blockhash: ' + e);
6063
+ }
6064
+ }
6065
+ /**
6066
+ * Fetch the latest blockhash from the cluster
6067
+ * @return {Promise<{blockhash: Blockhash, lastValidBlockHeight: number}>}
6068
+ */
6069
+
6070
+
6071
+ async getLatestBlockhashAndContext(commitment) {
6072
+ const args = this._buildArgs([], commitment);
6073
+
6074
+ const unsafeRes = await this._rpcRequest('getLatestBlockhash', args);
6075
+ const res = superstruct.create(unsafeRes, GetLatestBlockhashRpcResult);
6076
+
6077
+ if ('error' in res) {
6078
+ throw new Error('failed to get latest blockhash: ' + res.error.message);
6079
+ }
6080
+
6081
+ return res.result;
6082
+ }
6011
6083
  /**
6012
6084
  * Fetch the node version
6013
6085
  */
@@ -6046,8 +6118,8 @@ class Connection {
6046
6118
  async getBlock(slot, opts) {
6047
6119
  const args = this._buildArgsAtLeastConfirmed([slot], opts && opts.commitment);
6048
6120
 
6049
- const unsafeRes = await this._rpcRequest('getConfirmedBlock', args);
6050
- const res = superstruct.create(unsafeRes, GetConfirmedBlockRpcResult);
6121
+ const unsafeRes = await this._rpcRequest('getBlock', args);
6122
+ const res = superstruct.create(unsafeRes, GetBlockRpcResult);
6051
6123
 
6052
6124
  if ('error' in res) {
6053
6125
  throw new Error('failed to get confirmed block: ' + res.error.message);
@@ -6071,18 +6143,18 @@ class Connection {
6071
6143
  };
6072
6144
  }
6073
6145
  /**
6074
- * Fetch a processed transaction from the cluster.
6146
+ * Fetch a confirmed or finalized transaction from the cluster.
6075
6147
  */
6076
6148
 
6077
6149
 
6078
6150
  async getTransaction(signature, opts) {
6079
6151
  const args = this._buildArgsAtLeastConfirmed([signature], opts && opts.commitment);
6080
6152
 
6081
- const unsafeRes = await this._rpcRequest('getConfirmedTransaction', args);
6082
- const res = superstruct.create(unsafeRes, GetConfirmedTransactionRpcResult);
6153
+ const unsafeRes = await this._rpcRequest('getTransaction', args);
6154
+ const res = superstruct.create(unsafeRes, GetTransactionRpcResult);
6083
6155
 
6084
6156
  if ('error' in res) {
6085
- throw new Error('failed to get confirmed transaction: ' + res.error.message);
6157
+ throw new Error('failed to get transaction: ' + res.error.message);
6086
6158
  }
6087
6159
 
6088
6160
  const result = res.result;
@@ -6093,6 +6165,49 @@ class Connection {
6093
6165
  }
6094
6166
  };
6095
6167
  }
6168
+ /**
6169
+ * Fetch parsed transaction details for a confirmed or finalized transaction
6170
+ */
6171
+
6172
+
6173
+ async getParsedTransaction(signature, commitment) {
6174
+ const args = this._buildArgsAtLeastConfirmed([signature], commitment, 'jsonParsed');
6175
+
6176
+ const unsafeRes = await this._rpcRequest('getTransaction', args);
6177
+ const res = superstruct.create(unsafeRes, GetParsedTransactionRpcResult);
6178
+
6179
+ if ('error' in res) {
6180
+ throw new Error('failed to get transaction: ' + res.error.message);
6181
+ }
6182
+
6183
+ return res.result;
6184
+ }
6185
+ /**
6186
+ * Fetch parsed transaction details for a batch of confirmed transactions
6187
+ */
6188
+
6189
+
6190
+ async getParsedTransactions(signatures, commitment) {
6191
+ const batch = signatures.map(signature => {
6192
+ const args = this._buildArgsAtLeastConfirmed([signature], commitment, 'jsonParsed');
6193
+
6194
+ return {
6195
+ methodName: 'getTransaction',
6196
+ args
6197
+ };
6198
+ });
6199
+ const unsafeRes = await this._rpcBatchRequest(batch);
6200
+ const res = unsafeRes.map(unsafeRes => {
6201
+ const res = superstruct.create(unsafeRes, GetParsedTransactionRpcResult);
6202
+
6203
+ if ('error' in res) {
6204
+ throw new Error('failed to get transactions: ' + res.error.message);
6205
+ }
6206
+
6207
+ return res.result;
6208
+ });
6209
+ return res;
6210
+ }
6096
6211
  /**
6097
6212
  * Fetch a list of Transactions and transaction statuses from the cluster
6098
6213
  * for a confirmed block.
@@ -6102,18 +6217,39 @@ class Connection {
6102
6217
 
6103
6218
 
6104
6219
  async getConfirmedBlock(slot, commitment) {
6105
- const result = await this.getBlock(slot, {
6106
- commitment
6107
- });
6220
+ const args = this._buildArgsAtLeastConfirmed([slot], commitment);
6221
+
6222
+ const unsafeRes = await this._rpcRequest('getConfirmedBlock', args);
6223
+ const res = superstruct.create(unsafeRes, GetConfirmedBlockRpcResult);
6224
+
6225
+ if ('error' in res) {
6226
+ throw new Error('failed to get confirmed block: ' + res.error.message);
6227
+ }
6228
+
6229
+ const result = res.result;
6108
6230
 
6109
6231
  if (!result) {
6110
6232
  throw new Error('Confirmed block ' + slot + ' not found');
6111
6233
  }
6112
6234
 
6113
- return { ...result,
6235
+ const block = { ...result,
6114
6236
  transactions: result.transactions.map(({
6115
6237
  transaction,
6116
6238
  meta
6239
+ }) => {
6240
+ const message = new Message(transaction.message);
6241
+ return {
6242
+ meta,
6243
+ transaction: { ...transaction,
6244
+ message
6245
+ }
6246
+ };
6247
+ })
6248
+ };
6249
+ return { ...block,
6250
+ transactions: block.transactions.map(({
6251
+ transaction,
6252
+ meta
6117
6253
  }) => {
6118
6254
  return {
6119
6255
  meta,
@@ -6130,7 +6266,7 @@ class Connection {
6130
6266
  async getBlocks(startSlot, endSlot, commitment) {
6131
6267
  const args = this._buildArgsAtLeastConfirmed(endSlot !== undefined ? [startSlot, endSlot] : [startSlot], commitment);
6132
6268
 
6133
- const unsafeRes = await this._rpcRequest('getConfirmedBlocks', args);
6269
+ const unsafeRes = await this._rpcRequest('getBlocks', args);
6134
6270
  const res = superstruct.create(unsafeRes, jsonRpcResult(superstruct.array(superstruct.number())));
6135
6271
 
6136
6272
  if ('error' in res) {
@@ -6139,8 +6275,36 @@ class Connection {
6139
6275
 
6140
6276
  return res.result;
6141
6277
  }
6278
+ /**
6279
+ * Fetch a list of Signatures from the cluster for a block, excluding rewards
6280
+ */
6281
+
6282
+
6283
+ async getBlockSignatures(slot, commitment) {
6284
+ const args = this._buildArgsAtLeastConfirmed([slot], commitment, undefined, {
6285
+ transactionDetails: 'signatures',
6286
+ rewards: false
6287
+ });
6288
+
6289
+ const unsafeRes = await this._rpcRequest('getBlock', args);
6290
+ const res = superstruct.create(unsafeRes, GetBlockSignaturesRpcResult);
6291
+
6292
+ if ('error' in res) {
6293
+ throw new Error('failed to get block: ' + res.error.message);
6294
+ }
6295
+
6296
+ const result = res.result;
6297
+
6298
+ if (!result) {
6299
+ throw new Error('Block ' + slot + ' not found');
6300
+ }
6301
+
6302
+ return result;
6303
+ }
6142
6304
  /**
6143
6305
  * Fetch a list of Signatures from the cluster for a confirmed block, excluding rewards
6306
+ *
6307
+ * @deprecated Deprecated since Solana v1.8.0. Please use {@link getBlockSignatures} instead.
6144
6308
  */
6145
6309
 
6146
6310
 
@@ -6151,7 +6315,7 @@ class Connection {
6151
6315
  });
6152
6316
 
6153
6317
  const unsafeRes = await this._rpcRequest('getConfirmedBlock', args);
6154
- const res = superstruct.create(unsafeRes, GetConfirmedBlockSignaturesRpcResult);
6318
+ const res = superstruct.create(unsafeRes, GetBlockSignaturesRpcResult);
6155
6319
 
6156
6320
  if ('error' in res) {
6157
6321
  throw new Error('failed to get confirmed block: ' + res.error.message);
@@ -6167,24 +6331,33 @@ class Connection {
6167
6331
  }
6168
6332
  /**
6169
6333
  * Fetch a transaction details for a confirmed transaction
6334
+ *
6335
+ * @deprecated Deprecated since Solana v1.8.0. Please use {@link getTransaction} instead.
6170
6336
  */
6171
6337
 
6172
6338
 
6173
6339
  async getConfirmedTransaction(signature, commitment) {
6174
- const result = await this.getTransaction(signature, {
6175
- commitment
6176
- });
6340
+ const args = this._buildArgsAtLeastConfirmed([signature], commitment);
6341
+
6342
+ const unsafeRes = await this._rpcRequest('getConfirmedTransaction', args);
6343
+ const res = superstruct.create(unsafeRes, GetTransactionRpcResult);
6344
+
6345
+ if ('error' in res) {
6346
+ throw new Error('failed to get transaction: ' + res.error.message);
6347
+ }
6348
+
6349
+ const result = res.result;
6177
6350
  if (!result) return result;
6178
- const {
6179
- message,
6180
- signatures
6181
- } = result.transaction;
6351
+ const message = new Message(result.transaction.message);
6352
+ const signatures = result.transaction.signatures;
6182
6353
  return { ...result,
6183
6354
  transaction: Transaction.populate(message, signatures)
6184
6355
  };
6185
6356
  }
6186
6357
  /**
6187
6358
  * Fetch parsed transaction details for a confirmed transaction
6359
+ *
6360
+ * @deprecated Deprecated since Solana v1.8.0. Please use {@link getParsedTransaction} instead.
6188
6361
  */
6189
6362
 
6190
6363
 
@@ -6192,7 +6365,7 @@ class Connection {
6192
6365
  const args = this._buildArgsAtLeastConfirmed([signature], commitment, 'jsonParsed');
6193
6366
 
6194
6367
  const unsafeRes = await this._rpcRequest('getConfirmedTransaction', args);
6195
- const res = superstruct.create(unsafeRes, GetParsedConfirmedTransactionRpcResult);
6368
+ const res = superstruct.create(unsafeRes, GetParsedTransactionRpcResult);
6196
6369
 
6197
6370
  if ('error' in res) {
6198
6371
  throw new Error('failed to get confirmed transaction: ' + res.error.message);
@@ -6202,6 +6375,8 @@ class Connection {
6202
6375
  }
6203
6376
  /**
6204
6377
  * Fetch parsed transaction details for a batch of confirmed transactions
6378
+ *
6379
+ * @deprecated Deprecated since Solana v1.8.0. Please use {@link getParsedTransactions} instead.
6205
6380
  */
6206
6381
 
6207
6382
 
@@ -6216,7 +6391,7 @@ class Connection {
6216
6391
  });
6217
6392
  const unsafeRes = await this._rpcBatchRequest(batch);
6218
6393
  const res = unsafeRes.map(unsafeRes => {
6219
- const res = superstruct.create(unsafeRes, GetParsedConfirmedTransactionRpcResult);
6394
+ const res = superstruct.create(unsafeRes, GetParsedTransactionRpcResult);
6220
6395
 
6221
6396
  if ('error' in res) {
6222
6397
  throw new Error('failed to get confirmed transactions: ' + res.error.message);
@@ -6606,6 +6781,10 @@ class Connection {
6606
6781
  const skipPreflight = options && options.skipPreflight;
6607
6782
  const preflightCommitment = options && options.preflightCommitment || this.commitment;
6608
6783
 
6784
+ if (options && options.maxRetries) {
6785
+ config.maxRetries = options.maxRetries;
6786
+ }
6787
+
6609
6788
  if (skipPreflight) {
6610
6789
  config.skipPreflight = skipPreflight;
6611
6790
  }
@@ -8600,12 +8779,12 @@ const endpoint = {
8600
8779
  http: {
8601
8780
  devnet: 'http://api.devnet.solana.com',
8602
8781
  testnet: 'http://api.testnet.solana.com',
8603
- 'mainnet-beta': 'http://api.mainnet-beta.solana.com'
8782
+ 'mainnet-beta': 'http://api.mainnet-beta.solana.com/'
8604
8783
  },
8605
8784
  https: {
8606
8785
  devnet: 'https://api.devnet.solana.com',
8607
8786
  testnet: 'https://api.testnet.solana.com',
8608
- 'mainnet-beta': 'https://api.mainnet-beta.solana.com'
8787
+ 'mainnet-beta': 'https://api.mainnet-beta.solana.com/'
8609
8788
  }
8610
8789
  };
8611
8790