@solana/web3.js 1.55.0 → 1.56.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.d.ts CHANGED
@@ -835,6 +835,13 @@ declare module '@solana/web3.js' {
835
835
  export type GetBlockConfig = {
836
836
  /** The level of finality desired */
837
837
  commitment?: Finality;
838
+ };
839
+ /**
840
+ * Configuration object for changing `getBlock` query behavior
841
+ */
842
+ export type GetVersionedBlockConfig = {
843
+ /** The level of finality desired */
844
+ commitment?: Finality;
838
845
  /** The max transaction version to return in responses. If the requested transaction is a higher version, an error will be returned */
839
846
  maxSupportedTransactionVersion?: number;
840
847
  };
@@ -907,6 +914,13 @@ declare module '@solana/web3.js' {
907
914
  export type GetTransactionConfig = {
908
915
  /** The level of finality desired */
909
916
  commitment?: Finality;
917
+ };
918
+ /**
919
+ * Configuration object for changing `getTransaction` query behavior
920
+ */
921
+ export type GetVersionedTransactionConfig = {
922
+ /** The level of finality desired */
923
+ commitment?: Finality;
910
924
  /** The max transaction version to return in responses. If the requested transaction is a higher version, an error will be returned */
911
925
  maxSupportedTransactionVersion?: number;
912
926
  };
@@ -1122,6 +1136,8 @@ declare module '@solana/web3.js' {
1122
1136
  postTokenBalances?: Array<TokenBalance> | null;
1123
1137
  /** The error result of transaction processing */
1124
1138
  err: TransactionError | null;
1139
+ /** The collection of addresses loaded using address lookup tables */
1140
+ loadedAddresses?: LoadedAddresses;
1125
1141
  };
1126
1142
  /**
1127
1143
  * A processed transaction from the RPC API
@@ -1141,6 +1157,26 @@ declare module '@solana/web3.js' {
1141
1157
  /** The unix timestamp of when the transaction was processed */
1142
1158
  blockTime?: number | null;
1143
1159
  };
1160
+ /**
1161
+ * A processed transaction from the RPC API
1162
+ */
1163
+ export type VersionedTransactionResponse = {
1164
+ /** The slot during which the transaction was processed */
1165
+ slot: number;
1166
+ /** The transaction */
1167
+ transaction: {
1168
+ /** The transaction message */
1169
+ message: VersionedMessage;
1170
+ /** The transaction signatures */
1171
+ signatures: string[];
1172
+ };
1173
+ /** Metadata produced from the transaction */
1174
+ meta: ConfirmedTransactionMeta | null;
1175
+ /** The unix timestamp of when the transaction was processed */
1176
+ blockTime?: number | null;
1177
+ /** The transaction version */
1178
+ version?: TransactionVersion;
1179
+ };
1144
1180
  /**
1145
1181
  * A confirmed transaction on the ledger
1146
1182
  *
@@ -1189,6 +1225,17 @@ declare module '@solana/web3.js' {
1189
1225
  /** Parsed instruction info */
1190
1226
  parsed: any;
1191
1227
  };
1228
+ /**
1229
+ * A parsed address table lookup
1230
+ */
1231
+ export type ParsedAddressTableLookup = {
1232
+ /** Address lookup table account key */
1233
+ accountKey: PublicKey;
1234
+ /** Parsed instruction info */
1235
+ writableIndexes: number[];
1236
+ /** Parsed instruction info */
1237
+ readonlyIndexes: number[];
1238
+ };
1192
1239
  /**
1193
1240
  * A parsed transaction message
1194
1241
  */
@@ -1199,6 +1246,8 @@ declare module '@solana/web3.js' {
1199
1246
  instructions: (ParsedInstruction | PartiallyDecodedInstruction)[];
1200
1247
  /** Recent blockhash */
1201
1248
  recentBlockhash: string;
1249
+ /** Address table lookups used to load additional accounts */
1250
+ addressTableLookups?: ParsedAddressTableLookup[] | null;
1202
1251
  };
1203
1252
  /**
1204
1253
  * A parsed transaction
@@ -1227,6 +1276,8 @@ declare module '@solana/web3.js' {
1227
1276
  meta: ParsedTransactionMeta | null;
1228
1277
  /** The unix timestamp of when the transaction was processed */
1229
1278
  blockTime?: number | null;
1279
+ /** The version of the transaction message */
1280
+ version?: TransactionVersion;
1230
1281
  };
1231
1282
  /**
1232
1283
  * A processed block fetched from the RPC API
@@ -1249,6 +1300,46 @@ declare module '@solana/web3.js' {
1249
1300
  };
1250
1301
  /** Metadata produced from the transaction */
1251
1302
  meta: ConfirmedTransactionMeta | null;
1303
+ /** The transaction version */
1304
+ version?: TransactionVersion;
1305
+ }>;
1306
+ /** Vector of block rewards */
1307
+ rewards?: Array<{
1308
+ /** Public key of reward recipient */
1309
+ pubkey: string;
1310
+ /** Reward value in lamports */
1311
+ lamports: number;
1312
+ /** Account balance after reward is applied */
1313
+ postBalance: number | null;
1314
+ /** Type of reward received */
1315
+ rewardType: string | null;
1316
+ }>;
1317
+ /** The unix timestamp of when the block was processed */
1318
+ blockTime: number | null;
1319
+ };
1320
+ /**
1321
+ * A processed block fetched from the RPC API
1322
+ */
1323
+ export type VersionedBlockResponse = {
1324
+ /** Blockhash of this block */
1325
+ blockhash: Blockhash;
1326
+ /** Blockhash of this block's parent */
1327
+ previousBlockhash: Blockhash;
1328
+ /** Slot index of this block's parent */
1329
+ parentSlot: number;
1330
+ /** Vector of transactions with status meta and original message */
1331
+ transactions: Array<{
1332
+ /** The transaction */
1333
+ transaction: {
1334
+ /** The transaction message */
1335
+ message: VersionedMessage;
1336
+ /** The transaction signatures */
1337
+ signatures: string[];
1338
+ };
1339
+ /** Metadata produced from the transaction */
1340
+ meta: ConfirmedTransactionMeta | null;
1341
+ /** The transaction version */
1342
+ version?: TransactionVersion;
1252
1343
  }>;
1253
1344
  /** Vector of block rewards */
1254
1345
  rewards?: Array<{
@@ -2122,11 +2213,21 @@ declare module '@solana/web3.js' {
2122
2213
  getGenesisHash(): Promise<string>;
2123
2214
  /**
2124
2215
  * Fetch a processed block from the cluster.
2216
+ *
2217
+ * @deprecated Instead, call `getBlock` using a `GetVersionedBlockConfig` by
2218
+ * setting the `maxSupportedTransactionVersion` property.
2125
2219
  */
2126
2220
  getBlock(
2127
2221
  slot: number,
2128
2222
  rawConfig?: GetBlockConfig,
2129
2223
  ): Promise<BlockResponse | null>;
2224
+ /**
2225
+ * Fetch a processed block from the cluster.
2226
+ */
2227
+ getBlock(
2228
+ slot: number,
2229
+ rawConfig?: GetVersionedBlockConfig,
2230
+ ): Promise<VersionedBlockResponse | null>;
2130
2231
  getBlockHeight(
2131
2232
  commitmentOrConfig?: Commitment | GetBlockHeightConfig,
2132
2233
  ): Promise<number>;
@@ -2135,33 +2236,57 @@ declare module '@solana/web3.js' {
2135
2236
  ): Promise<RpcResponseAndContext<BlockProduction>>;
2136
2237
  /**
2137
2238
  * Fetch a confirmed or finalized transaction from the cluster.
2239
+ *
2240
+ * @deprecated Instead, call `getTransaction` using a
2241
+ * `GetVersionedTransactionConfig` by setting the
2242
+ * `maxSupportedTransactionVersion` property.
2138
2243
  */
2139
2244
  getTransaction(
2140
2245
  signature: string,
2141
2246
  rawConfig?: GetTransactionConfig,
2142
2247
  ): Promise<TransactionResponse | null>;
2248
+ /**
2249
+ * Fetch a confirmed or finalized transaction from the cluster.
2250
+ */
2251
+ getTransaction(
2252
+ signature: string,
2253
+ rawConfig: GetVersionedTransactionConfig,
2254
+ ): Promise<VersionedTransactionResponse | null>;
2143
2255
  /**
2144
2256
  * Fetch parsed transaction details for a confirmed or finalized transaction
2145
2257
  */
2146
2258
  getParsedTransaction(
2147
2259
  signature: TransactionSignature,
2148
- commitmentOrConfig?: GetTransactionConfig | Finality,
2149
- ): Promise<ParsedConfirmedTransaction | null>;
2260
+ commitmentOrConfig?: GetVersionedTransactionConfig | Finality,
2261
+ ): Promise<ParsedTransactionWithMeta | null>;
2150
2262
  /**
2151
2263
  * Fetch parsed transaction details for a batch of confirmed transactions
2152
2264
  */
2153
2265
  getParsedTransactions(
2154
2266
  signatures: TransactionSignature[],
2155
- commitmentOrConfig?: GetTransactionConfig | Finality,
2156
- ): Promise<(ParsedConfirmedTransaction | null)[]>;
2267
+ commitmentOrConfig?: GetVersionedTransactionConfig | Finality,
2268
+ ): Promise<(ParsedTransactionWithMeta | null)[]>;
2157
2269
  /**
2158
2270
  * Fetch transaction details for a batch of confirmed transactions.
2159
2271
  * Similar to {@link getParsedTransactions} but returns a {@link TransactionResponse}.
2272
+ *
2273
+ * @deprecated Instead, call `getTransactions` using a
2274
+ * `GetVersionedTransactionConfig` by setting the
2275
+ * `maxSupportedTransactionVersion` property.
2160
2276
  */
2161
2277
  getTransactions(
2162
2278
  signatures: TransactionSignature[],
2163
2279
  commitmentOrConfig?: GetTransactionConfig | Finality,
2164
2280
  ): Promise<(TransactionResponse | null)[]>;
2281
+ /**
2282
+ * Fetch transaction details for a batch of confirmed transactions.
2283
+ * Similar to {@link getParsedTransactions} but returns a {@link
2284
+ * VersionedTransactionResponse}.
2285
+ */
2286
+ getTransactions(
2287
+ signatures: TransactionSignature[],
2288
+ commitmentOrConfig: GetVersionedTransactionConfig | Finality,
2289
+ ): Promise<(VersionedTransactionResponse | null)[]>;
2165
2290
  /**
2166
2291
  * Fetch a list of Transactions and transaction statuses from the cluster
2167
2292
  * for a confirmed block.
package/lib/index.esm.js CHANGED
@@ -3263,6 +3263,28 @@ function notificationResultAndContext(value) {
3263
3263
  value
3264
3264
  });
3265
3265
  }
3266
+ /**
3267
+ * @internal
3268
+ */
3269
+
3270
+
3271
+ function versionedMessageFromResponse(version, response) {
3272
+ if (version === 0) {
3273
+ return new MessageV0({
3274
+ header: response.header,
3275
+ staticAccountKeys: response.accountKeys.map(accountKey => new PublicKey(accountKey)),
3276
+ recentBlockhash: response.recentBlockhash,
3277
+ compiledInstructions: response.instructions.map(ix => ({
3278
+ programIdIndex: ix.programIdIndex,
3279
+ accountKeyIndexes: ix.accounts,
3280
+ data: bs58.decode(ix.data)
3281
+ })),
3282
+ addressTableLookups: response.addressTableLookups
3283
+ });
3284
+ } else {
3285
+ return new Message(response);
3286
+ }
3287
+ }
3266
3288
  /**
3267
3289
  * The level of commitment desired when querying state
3268
3290
  * <pre>
@@ -3826,6 +3848,11 @@ const GetSignatureStatusesRpcResult = jsonRpcResultAndContext(array(nullable(Sig
3826
3848
  */
3827
3849
 
3828
3850
  const GetMinimumBalanceForRentExemptionRpcResult = jsonRpcResult(number());
3851
+ const AddressTableLookupStruct = type({
3852
+ accountKey: PublicKeyFromString,
3853
+ writableIndexes: array(number()),
3854
+ readonlyIndexes: array(number())
3855
+ });
3829
3856
  const ConfirmedTransactionResult = type({
3830
3857
  signatures: array(string()),
3831
3858
  message: type({
@@ -3840,7 +3867,8 @@ const ConfirmedTransactionResult = type({
3840
3867
  data: string(),
3841
3868
  programIdIndex: number()
3842
3869
  })),
3843
- recentBlockhash: string()
3870
+ recentBlockhash: string(),
3871
+ addressTableLookups: optional(array(AddressTableLookupStruct))
3844
3872
  })
3845
3873
  });
3846
3874
  const ParsedInstructionResult = type({
@@ -3883,7 +3911,8 @@ const ParsedConfirmedTransactionResult = type({
3883
3911
  writable: boolean()
3884
3912
  })),
3885
3913
  instructions: array(ParsedOrRawInstruction),
3886
- recentBlockhash: string()
3914
+ recentBlockhash: string(),
3915
+ addressTableLookups: optional(nullable(array(AddressTableLookupStruct)))
3887
3916
  })
3888
3917
  });
3889
3918
  const TokenBalanceResult = type({
@@ -3936,6 +3965,7 @@ const ParsedConfirmedTransactionMetaResult = type({
3936
3965
  postTokenBalances: optional(nullable(array(TokenBalanceResult))),
3937
3966
  loadedAddresses: optional(LoadedAddressesResult)
3938
3967
  });
3968
+ const TransactionVersionStruct = union([literal(0), literal('legacy')]);
3939
3969
  /**
3940
3970
  * Expected JSON RPC response for the "getBlock" message
3941
3971
  */
@@ -3946,7 +3976,8 @@ const GetBlockRpcResult = jsonRpcResult(nullable(type({
3946
3976
  parentSlot: number(),
3947
3977
  transactions: array(type({
3948
3978
  transaction: ConfirmedTransactionResult,
3949
- meta: nullable(ConfirmedTransactionMetaResult)
3979
+ meta: nullable(ConfirmedTransactionMetaResult),
3980
+ version: optional(TransactionVersionStruct)
3950
3981
  })),
3951
3982
  rewards: optional(array(type({
3952
3983
  pubkey: string(),
@@ -3998,7 +4029,8 @@ const GetTransactionRpcResult = jsonRpcResult(nullable(type({
3998
4029
  slot: number(),
3999
4030
  meta: ConfirmedTransactionMetaResult,
4000
4031
  blockTime: optional(nullable(number())),
4001
- transaction: ConfirmedTransactionResult
4032
+ transaction: ConfirmedTransactionResult,
4033
+ version: optional(TransactionVersionStruct)
4002
4034
  })));
4003
4035
  /**
4004
4036
  * Expected parsed JSON RPC response for the "getTransaction" message
@@ -4008,7 +4040,8 @@ const GetParsedTransactionRpcResult = jsonRpcResult(nullable(type({
4008
4040
  slot: number(),
4009
4041
  transaction: ParsedConfirmedTransactionResult,
4010
4042
  meta: nullable(ParsedConfirmedTransactionMetaResult),
4011
- blockTime: optional(nullable(number()))
4043
+ blockTime: optional(nullable(number())),
4044
+ version: optional(TransactionVersionStruct)
4012
4045
  })));
4013
4046
  /**
4014
4047
  * Expected JSON RPC response for the "getRecentBlockhash" message
@@ -5251,9 +5284,16 @@ class Connection {
5251
5284
  }
5252
5285
  /**
5253
5286
  * Fetch a processed block from the cluster.
5287
+ *
5288
+ * @deprecated Instead, call `getBlock` using a `GetVersionedBlockConfig` by
5289
+ * setting the `maxSupportedTransactionVersion` property.
5254
5290
  */
5255
5291
 
5256
5292
 
5293
+ /**
5294
+ * Fetch a processed block from the cluster.
5295
+ */
5296
+ // eslint-disable-next-line no-dupe-class-members
5257
5297
  async getBlock(slot, rawConfig) {
5258
5298
  const {
5259
5299
  commitment,
@@ -5276,16 +5316,15 @@ class Connection {
5276
5316
  return { ...result,
5277
5317
  transactions: result.transactions.map(({
5278
5318
  transaction,
5279
- meta
5280
- }) => {
5281
- const message = new Message(transaction.message);
5282
- return {
5283
- meta,
5284
- transaction: { ...transaction,
5285
- message
5286
- }
5287
- };
5288
- })
5319
+ meta,
5320
+ version
5321
+ }) => ({
5322
+ meta,
5323
+ transaction: { ...transaction,
5324
+ message: versionedMessageFromResponse(version, transaction.message)
5325
+ },
5326
+ version
5327
+ }))
5289
5328
  };
5290
5329
  }
5291
5330
  /*
@@ -5345,9 +5384,17 @@ class Connection {
5345
5384
  }
5346
5385
  /**
5347
5386
  * Fetch a confirmed or finalized transaction from the cluster.
5387
+ *
5388
+ * @deprecated Instead, call `getTransaction` using a
5389
+ * `GetVersionedTransactionConfig` by setting the
5390
+ * `maxSupportedTransactionVersion` property.
5348
5391
  */
5349
5392
 
5350
5393
 
5394
+ /**
5395
+ * Fetch a confirmed or finalized transaction from the cluster.
5396
+ */
5397
+ // eslint-disable-next-line no-dupe-class-members
5351
5398
  async getTransaction(signature, rawConfig) {
5352
5399
  const {
5353
5400
  commitment,
@@ -5369,7 +5416,7 @@ class Connection {
5369
5416
  if (!result) return result;
5370
5417
  return { ...result,
5371
5418
  transaction: { ...result.transaction,
5372
- message: new Message(result.transaction.message)
5419
+ message: versionedMessageFromResponse(result.version, result.transaction.message)
5373
5420
  }
5374
5421
  };
5375
5422
  }
@@ -5428,9 +5475,19 @@ class Connection {
5428
5475
  /**
5429
5476
  * Fetch transaction details for a batch of confirmed transactions.
5430
5477
  * Similar to {@link getParsedTransactions} but returns a {@link TransactionResponse}.
5478
+ *
5479
+ * @deprecated Instead, call `getTransactions` using a
5480
+ * `GetVersionedTransactionConfig` by setting the
5481
+ * `maxSupportedTransactionVersion` property.
5431
5482
  */
5432
5483
 
5433
5484
 
5485
+ /**
5486
+ * Fetch transaction details for a batch of confirmed transactions.
5487
+ * Similar to {@link getParsedTransactions} but returns a {@link
5488
+ * VersionedTransactionResponse}.
5489
+ */
5490
+ // eslint-disable-next-line no-dupe-class-members
5434
5491
  async getTransactions(signatures, commitmentOrConfig) {
5435
5492
  const {
5436
5493
  commitment,
@@ -5458,7 +5515,7 @@ class Connection {
5458
5515
  if (!result) return result;
5459
5516
  return { ...result,
5460
5517
  transaction: { ...result.transaction,
5461
- message: new Message(result.transaction.message)
5518
+ message: versionedMessageFromResponse(result.version, result.transaction.message)
5462
5519
  }
5463
5520
  };
5464
5521
  });