@solana/web3.js 1.54.1 → 1.56.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.d.ts CHANGED
@@ -395,6 +395,7 @@ declare module '@solana/web3.js' {
395
395
 
396
396
  export type VersionedMessage = Message | MessageV0;
397
397
  export const VersionedMessage: {
398
+ deserializeMessageVersion(serializedMessage: Uint8Array): 'legacy' | number;
398
399
  deserialize: (serializedMessage: Uint8Array) => VersionedMessage;
399
400
  };
400
401
 
@@ -834,6 +835,13 @@ declare module '@solana/web3.js' {
834
835
  export type GetBlockConfig = {
835
836
  /** The level of finality desired */
836
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;
837
845
  /** The max transaction version to return in responses. If the requested transaction is a higher version, an error will be returned */
838
846
  maxSupportedTransactionVersion?: number;
839
847
  };
@@ -906,6 +914,13 @@ declare module '@solana/web3.js' {
906
914
  export type GetTransactionConfig = {
907
915
  /** The level of finality desired */
908
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;
909
924
  /** The max transaction version to return in responses. If the requested transaction is a higher version, an error will be returned */
910
925
  maxSupportedTransactionVersion?: number;
911
926
  };
@@ -1121,6 +1136,8 @@ declare module '@solana/web3.js' {
1121
1136
  postTokenBalances?: Array<TokenBalance> | null;
1122
1137
  /** The error result of transaction processing */
1123
1138
  err: TransactionError | null;
1139
+ /** The collection of addresses loaded using address lookup tables */
1140
+ loadedAddresses?: LoadedAddresses;
1124
1141
  };
1125
1142
  /**
1126
1143
  * A processed transaction from the RPC API
@@ -1140,6 +1157,26 @@ declare module '@solana/web3.js' {
1140
1157
  /** The unix timestamp of when the transaction was processed */
1141
1158
  blockTime?: number | null;
1142
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
+ };
1143
1180
  /**
1144
1181
  * A confirmed transaction on the ledger
1145
1182
  *
@@ -1188,6 +1225,17 @@ declare module '@solana/web3.js' {
1188
1225
  /** Parsed instruction info */
1189
1226
  parsed: any;
1190
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
+ };
1191
1239
  /**
1192
1240
  * A parsed transaction message
1193
1241
  */
@@ -1198,6 +1246,8 @@ declare module '@solana/web3.js' {
1198
1246
  instructions: (ParsedInstruction | PartiallyDecodedInstruction)[];
1199
1247
  /** Recent blockhash */
1200
1248
  recentBlockhash: string;
1249
+ /** Address table lookups used to load additional accounts */
1250
+ addressTableLookups?: ParsedAddressTableLookup[] | null;
1201
1251
  };
1202
1252
  /**
1203
1253
  * A parsed transaction
@@ -1226,6 +1276,8 @@ declare module '@solana/web3.js' {
1226
1276
  meta: ParsedTransactionMeta | null;
1227
1277
  /** The unix timestamp of when the transaction was processed */
1228
1278
  blockTime?: number | null;
1279
+ /** The version of the transaction message */
1280
+ version?: TransactionVersion;
1229
1281
  };
1230
1282
  /**
1231
1283
  * A processed block fetched from the RPC API
@@ -1248,6 +1300,46 @@ declare module '@solana/web3.js' {
1248
1300
  };
1249
1301
  /** Metadata produced from the transaction */
1250
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;
1251
1343
  }>;
1252
1344
  /** Vector of block rewards */
1253
1345
  rewards?: Array<{
@@ -2121,11 +2213,21 @@ declare module '@solana/web3.js' {
2121
2213
  getGenesisHash(): Promise<string>;
2122
2214
  /**
2123
2215
  * Fetch a processed block from the cluster.
2216
+ *
2217
+ * @deprecated Instead, call `getBlock` using a `GetVersionedBlockConfig` by
2218
+ * setting the `maxSupportedTransactionVersion` property.
2124
2219
  */
2125
2220
  getBlock(
2126
2221
  slot: number,
2127
2222
  rawConfig?: GetBlockConfig,
2128
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>;
2129
2231
  getBlockHeight(
2130
2232
  commitmentOrConfig?: Commitment | GetBlockHeightConfig,
2131
2233
  ): Promise<number>;
@@ -2134,33 +2236,57 @@ declare module '@solana/web3.js' {
2134
2236
  ): Promise<RpcResponseAndContext<BlockProduction>>;
2135
2237
  /**
2136
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.
2137
2243
  */
2138
2244
  getTransaction(
2139
2245
  signature: string,
2140
2246
  rawConfig?: GetTransactionConfig,
2141
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>;
2142
2255
  /**
2143
2256
  * Fetch parsed transaction details for a confirmed or finalized transaction
2144
2257
  */
2145
2258
  getParsedTransaction(
2146
2259
  signature: TransactionSignature,
2147
- commitmentOrConfig?: GetTransactionConfig | Finality,
2148
- ): Promise<ParsedConfirmedTransaction | null>;
2260
+ commitmentOrConfig?: GetVersionedTransactionConfig | Finality,
2261
+ ): Promise<ParsedTransactionWithMeta | null>;
2149
2262
  /**
2150
2263
  * Fetch parsed transaction details for a batch of confirmed transactions
2151
2264
  */
2152
2265
  getParsedTransactions(
2153
2266
  signatures: TransactionSignature[],
2154
- commitmentOrConfig?: GetTransactionConfig | Finality,
2155
- ): Promise<(ParsedConfirmedTransaction | null)[]>;
2267
+ commitmentOrConfig?: GetVersionedTransactionConfig | Finality,
2268
+ ): Promise<(ParsedTransactionWithMeta | null)[]>;
2156
2269
  /**
2157
2270
  * Fetch transaction details for a batch of confirmed transactions.
2158
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.
2159
2276
  */
2160
2277
  getTransactions(
2161
2278
  signatures: TransactionSignature[],
2162
2279
  commitmentOrConfig?: GetTransactionConfig | Finality,
2163
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)[]>;
2164
2290
  /**
2165
2291
  * Fetch a list of Transactions and transaction statuses from the cluster
2166
2292
  * for a confirmed block.
package/lib/index.esm.js CHANGED
@@ -862,16 +862,24 @@ class MessageV0 {
862
862
 
863
863
  // eslint-disable-next-line no-redeclare
864
864
  const VersionedMessage = {
865
- deserialize: serializedMessage => {
865
+ deserializeMessageVersion(serializedMessage) {
866
866
  const prefix = serializedMessage[0];
867
867
  const maskedPrefix = prefix & VERSION_PREFIX_MASK; // if the highest bit of the prefix is not set, the message is not versioned
868
868
 
869
869
  if (maskedPrefix === prefix) {
870
- return Message.from(serializedMessage);
870
+ return 'legacy';
871
871
  } // the lower 7 bits of the prefix indicate the message version
872
872
 
873
873
 
874
- const version = maskedPrefix;
874
+ return maskedPrefix;
875
+ },
876
+
877
+ deserialize: serializedMessage => {
878
+ const version = VersionedMessage.deserializeMessageVersion(serializedMessage);
879
+
880
+ if (version === 'legacy') {
881
+ return Message.from(serializedMessage);
882
+ }
875
883
 
876
884
  if (version === 0) {
877
885
  return MessageV0.deserialize(serializedMessage);
@@ -3255,6 +3263,28 @@ function notificationResultAndContext(value) {
3255
3263
  value
3256
3264
  });
3257
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
+ }
3258
3288
  /**
3259
3289
  * The level of commitment desired when querying state
3260
3290
  * <pre>
@@ -3818,6 +3848,11 @@ const GetSignatureStatusesRpcResult = jsonRpcResultAndContext(array(nullable(Sig
3818
3848
  */
3819
3849
 
3820
3850
  const GetMinimumBalanceForRentExemptionRpcResult = jsonRpcResult(number());
3851
+ const AddressTableLookupStruct = type({
3852
+ accountKey: PublicKeyFromString,
3853
+ writableIndexes: array(number()),
3854
+ readonlyIndexes: array(number())
3855
+ });
3821
3856
  const ConfirmedTransactionResult = type({
3822
3857
  signatures: array(string()),
3823
3858
  message: type({
@@ -3832,7 +3867,8 @@ const ConfirmedTransactionResult = type({
3832
3867
  data: string(),
3833
3868
  programIdIndex: number()
3834
3869
  })),
3835
- recentBlockhash: string()
3870
+ recentBlockhash: string(),
3871
+ addressTableLookups: optional(array(AddressTableLookupStruct))
3836
3872
  })
3837
3873
  });
3838
3874
  const ParsedInstructionResult = type({
@@ -3875,7 +3911,8 @@ const ParsedConfirmedTransactionResult = type({
3875
3911
  writable: boolean()
3876
3912
  })),
3877
3913
  instructions: array(ParsedOrRawInstruction),
3878
- recentBlockhash: string()
3914
+ recentBlockhash: string(),
3915
+ addressTableLookups: optional(nullable(array(AddressTableLookupStruct)))
3879
3916
  })
3880
3917
  });
3881
3918
  const TokenBalanceResult = type({
@@ -3928,6 +3965,7 @@ const ParsedConfirmedTransactionMetaResult = type({
3928
3965
  postTokenBalances: optional(nullable(array(TokenBalanceResult))),
3929
3966
  loadedAddresses: optional(LoadedAddressesResult)
3930
3967
  });
3968
+ const TransactionVersionStruct = union([literal(0), literal('legacy')]);
3931
3969
  /**
3932
3970
  * Expected JSON RPC response for the "getBlock" message
3933
3971
  */
@@ -3938,7 +3976,8 @@ const GetBlockRpcResult = jsonRpcResult(nullable(type({
3938
3976
  parentSlot: number(),
3939
3977
  transactions: array(type({
3940
3978
  transaction: ConfirmedTransactionResult,
3941
- meta: nullable(ConfirmedTransactionMetaResult)
3979
+ meta: nullable(ConfirmedTransactionMetaResult),
3980
+ version: optional(TransactionVersionStruct)
3942
3981
  })),
3943
3982
  rewards: optional(array(type({
3944
3983
  pubkey: string(),
@@ -3990,7 +4029,8 @@ const GetTransactionRpcResult = jsonRpcResult(nullable(type({
3990
4029
  slot: number(),
3991
4030
  meta: ConfirmedTransactionMetaResult,
3992
4031
  blockTime: optional(nullable(number())),
3993
- transaction: ConfirmedTransactionResult
4032
+ transaction: ConfirmedTransactionResult,
4033
+ version: optional(TransactionVersionStruct)
3994
4034
  })));
3995
4035
  /**
3996
4036
  * Expected parsed JSON RPC response for the "getTransaction" message
@@ -4000,7 +4040,8 @@ const GetParsedTransactionRpcResult = jsonRpcResult(nullable(type({
4000
4040
  slot: number(),
4001
4041
  transaction: ParsedConfirmedTransactionResult,
4002
4042
  meta: nullable(ParsedConfirmedTransactionMetaResult),
4003
- blockTime: optional(nullable(number()))
4043
+ blockTime: optional(nullable(number())),
4044
+ version: optional(TransactionVersionStruct)
4004
4045
  })));
4005
4046
  /**
4006
4047
  * Expected JSON RPC response for the "getRecentBlockhash" message
@@ -5243,9 +5284,16 @@ class Connection {
5243
5284
  }
5244
5285
  /**
5245
5286
  * Fetch a processed block from the cluster.
5287
+ *
5288
+ * @deprecated Instead, call `getBlock` using a `GetVersionedBlockConfig` by
5289
+ * setting the `maxSupportedTransactionVersion` property.
5246
5290
  */
5247
5291
 
5248
5292
 
5293
+ /**
5294
+ * Fetch a processed block from the cluster.
5295
+ */
5296
+ // eslint-disable-next-line no-dupe-class-members
5249
5297
  async getBlock(slot, rawConfig) {
5250
5298
  const {
5251
5299
  commitment,
@@ -5268,16 +5316,15 @@ class Connection {
5268
5316
  return { ...result,
5269
5317
  transactions: result.transactions.map(({
5270
5318
  transaction,
5271
- meta
5272
- }) => {
5273
- const message = new Message(transaction.message);
5274
- return {
5275
- meta,
5276
- transaction: { ...transaction,
5277
- message
5278
- }
5279
- };
5280
- })
5319
+ meta,
5320
+ version
5321
+ }) => ({
5322
+ meta,
5323
+ transaction: { ...transaction,
5324
+ message: versionedMessageFromResponse(version, transaction.message)
5325
+ },
5326
+ version
5327
+ }))
5281
5328
  };
5282
5329
  }
5283
5330
  /*
@@ -5337,9 +5384,17 @@ class Connection {
5337
5384
  }
5338
5385
  /**
5339
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.
5340
5391
  */
5341
5392
 
5342
5393
 
5394
+ /**
5395
+ * Fetch a confirmed or finalized transaction from the cluster.
5396
+ */
5397
+ // eslint-disable-next-line no-dupe-class-members
5343
5398
  async getTransaction(signature, rawConfig) {
5344
5399
  const {
5345
5400
  commitment,
@@ -5361,7 +5416,7 @@ class Connection {
5361
5416
  if (!result) return result;
5362
5417
  return { ...result,
5363
5418
  transaction: { ...result.transaction,
5364
- message: new Message(result.transaction.message)
5419
+ message: versionedMessageFromResponse(result.version, result.transaction.message)
5365
5420
  }
5366
5421
  };
5367
5422
  }
@@ -5420,9 +5475,19 @@ class Connection {
5420
5475
  /**
5421
5476
  * Fetch transaction details for a batch of confirmed transactions.
5422
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.
5423
5482
  */
5424
5483
 
5425
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
5426
5491
  async getTransactions(signatures, commitmentOrConfig) {
5427
5492
  const {
5428
5493
  commitment,
@@ -5450,7 +5515,7 @@ class Connection {
5450
5515
  if (!result) return result;
5451
5516
  return { ...result,
5452
5517
  transaction: { ...result.transaction,
5453
- message: new Message(result.transaction.message)
5518
+ message: versionedMessageFromResponse(result.version, result.transaction.message)
5454
5519
  }
5455
5520
  };
5456
5521
  });