@solana/web3.js 1.55.0 → 1.56.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.
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
  };
@@ -1097,6 +1111,8 @@ declare module '@solana/web3.js' {
1097
1111
  err: TransactionError | null;
1098
1112
  /** The collection of addresses loaded using address lookup tables */
1099
1113
  loadedAddresses?: LoadedAddresses;
1114
+ /** The compute units consumed after processing the transaction */
1115
+ computeUnitsConsumed?: number;
1100
1116
  };
1101
1117
  export type CompiledInnerInstruction = {
1102
1118
  index: number;
@@ -1122,6 +1138,10 @@ declare module '@solana/web3.js' {
1122
1138
  postTokenBalances?: Array<TokenBalance> | null;
1123
1139
  /** The error result of transaction processing */
1124
1140
  err: TransactionError | null;
1141
+ /** The collection of addresses loaded using address lookup tables */
1142
+ loadedAddresses?: LoadedAddresses;
1143
+ /** The compute units consumed after processing the transaction */
1144
+ computeUnitsConsumed?: number;
1125
1145
  };
1126
1146
  /**
1127
1147
  * A processed transaction from the RPC API
@@ -1141,6 +1161,26 @@ declare module '@solana/web3.js' {
1141
1161
  /** The unix timestamp of when the transaction was processed */
1142
1162
  blockTime?: number | null;
1143
1163
  };
1164
+ /**
1165
+ * A processed transaction from the RPC API
1166
+ */
1167
+ export type VersionedTransactionResponse = {
1168
+ /** The slot during which the transaction was processed */
1169
+ slot: number;
1170
+ /** The transaction */
1171
+ transaction: {
1172
+ /** The transaction message */
1173
+ message: VersionedMessage;
1174
+ /** The transaction signatures */
1175
+ signatures: string[];
1176
+ };
1177
+ /** Metadata produced from the transaction */
1178
+ meta: ConfirmedTransactionMeta | null;
1179
+ /** The unix timestamp of when the transaction was processed */
1180
+ blockTime?: number | null;
1181
+ /** The transaction version */
1182
+ version?: TransactionVersion;
1183
+ };
1144
1184
  /**
1145
1185
  * A confirmed transaction on the ledger
1146
1186
  *
@@ -1189,6 +1229,17 @@ declare module '@solana/web3.js' {
1189
1229
  /** Parsed instruction info */
1190
1230
  parsed: any;
1191
1231
  };
1232
+ /**
1233
+ * A parsed address table lookup
1234
+ */
1235
+ export type ParsedAddressTableLookup = {
1236
+ /** Address lookup table account key */
1237
+ accountKey: PublicKey;
1238
+ /** Parsed instruction info */
1239
+ writableIndexes: number[];
1240
+ /** Parsed instruction info */
1241
+ readonlyIndexes: number[];
1242
+ };
1192
1243
  /**
1193
1244
  * A parsed transaction message
1194
1245
  */
@@ -1199,6 +1250,8 @@ declare module '@solana/web3.js' {
1199
1250
  instructions: (ParsedInstruction | PartiallyDecodedInstruction)[];
1200
1251
  /** Recent blockhash */
1201
1252
  recentBlockhash: string;
1253
+ /** Address table lookups used to load additional accounts */
1254
+ addressTableLookups?: ParsedAddressTableLookup[] | null;
1202
1255
  };
1203
1256
  /**
1204
1257
  * A parsed transaction
@@ -1227,6 +1280,8 @@ declare module '@solana/web3.js' {
1227
1280
  meta: ParsedTransactionMeta | null;
1228
1281
  /** The unix timestamp of when the transaction was processed */
1229
1282
  blockTime?: number | null;
1283
+ /** The version of the transaction message */
1284
+ version?: TransactionVersion;
1230
1285
  };
1231
1286
  /**
1232
1287
  * A processed block fetched from the RPC API
@@ -1249,6 +1304,46 @@ declare module '@solana/web3.js' {
1249
1304
  };
1250
1305
  /** Metadata produced from the transaction */
1251
1306
  meta: ConfirmedTransactionMeta | null;
1307
+ /** The transaction version */
1308
+ version?: TransactionVersion;
1309
+ }>;
1310
+ /** Vector of block rewards */
1311
+ rewards?: Array<{
1312
+ /** Public key of reward recipient */
1313
+ pubkey: string;
1314
+ /** Reward value in lamports */
1315
+ lamports: number;
1316
+ /** Account balance after reward is applied */
1317
+ postBalance: number | null;
1318
+ /** Type of reward received */
1319
+ rewardType: string | null;
1320
+ }>;
1321
+ /** The unix timestamp of when the block was processed */
1322
+ blockTime: number | null;
1323
+ };
1324
+ /**
1325
+ * A processed block fetched from the RPC API
1326
+ */
1327
+ export type VersionedBlockResponse = {
1328
+ /** Blockhash of this block */
1329
+ blockhash: Blockhash;
1330
+ /** Blockhash of this block's parent */
1331
+ previousBlockhash: Blockhash;
1332
+ /** Slot index of this block's parent */
1333
+ parentSlot: number;
1334
+ /** Vector of transactions with status meta and original message */
1335
+ transactions: Array<{
1336
+ /** The transaction */
1337
+ transaction: {
1338
+ /** The transaction message */
1339
+ message: VersionedMessage;
1340
+ /** The transaction signatures */
1341
+ signatures: string[];
1342
+ };
1343
+ /** Metadata produced from the transaction */
1344
+ meta: ConfirmedTransactionMeta | null;
1345
+ /** The transaction version */
1346
+ version?: TransactionVersion;
1252
1347
  }>;
1253
1348
  /** Vector of block rewards */
1254
1349
  rewards?: Array<{
@@ -2122,11 +2217,21 @@ declare module '@solana/web3.js' {
2122
2217
  getGenesisHash(): Promise<string>;
2123
2218
  /**
2124
2219
  * Fetch a processed block from the cluster.
2220
+ *
2221
+ * @deprecated Instead, call `getBlock` using a `GetVersionedBlockConfig` by
2222
+ * setting the `maxSupportedTransactionVersion` property.
2125
2223
  */
2126
2224
  getBlock(
2127
2225
  slot: number,
2128
2226
  rawConfig?: GetBlockConfig,
2129
2227
  ): Promise<BlockResponse | null>;
2228
+ /**
2229
+ * Fetch a processed block from the cluster.
2230
+ */
2231
+ getBlock(
2232
+ slot: number,
2233
+ rawConfig?: GetVersionedBlockConfig,
2234
+ ): Promise<VersionedBlockResponse | null>;
2130
2235
  getBlockHeight(
2131
2236
  commitmentOrConfig?: Commitment | GetBlockHeightConfig,
2132
2237
  ): Promise<number>;
@@ -2135,33 +2240,57 @@ declare module '@solana/web3.js' {
2135
2240
  ): Promise<RpcResponseAndContext<BlockProduction>>;
2136
2241
  /**
2137
2242
  * Fetch a confirmed or finalized transaction from the cluster.
2243
+ *
2244
+ * @deprecated Instead, call `getTransaction` using a
2245
+ * `GetVersionedTransactionConfig` by setting the
2246
+ * `maxSupportedTransactionVersion` property.
2138
2247
  */
2139
2248
  getTransaction(
2140
2249
  signature: string,
2141
2250
  rawConfig?: GetTransactionConfig,
2142
2251
  ): Promise<TransactionResponse | null>;
2252
+ /**
2253
+ * Fetch a confirmed or finalized transaction from the cluster.
2254
+ */
2255
+ getTransaction(
2256
+ signature: string,
2257
+ rawConfig: GetVersionedTransactionConfig,
2258
+ ): Promise<VersionedTransactionResponse | null>;
2143
2259
  /**
2144
2260
  * Fetch parsed transaction details for a confirmed or finalized transaction
2145
2261
  */
2146
2262
  getParsedTransaction(
2147
2263
  signature: TransactionSignature,
2148
- commitmentOrConfig?: GetTransactionConfig | Finality,
2149
- ): Promise<ParsedConfirmedTransaction | null>;
2264
+ commitmentOrConfig?: GetVersionedTransactionConfig | Finality,
2265
+ ): Promise<ParsedTransactionWithMeta | null>;
2150
2266
  /**
2151
2267
  * Fetch parsed transaction details for a batch of confirmed transactions
2152
2268
  */
2153
2269
  getParsedTransactions(
2154
2270
  signatures: TransactionSignature[],
2155
- commitmentOrConfig?: GetTransactionConfig | Finality,
2156
- ): Promise<(ParsedConfirmedTransaction | null)[]>;
2271
+ commitmentOrConfig?: GetVersionedTransactionConfig | Finality,
2272
+ ): Promise<(ParsedTransactionWithMeta | null)[]>;
2157
2273
  /**
2158
2274
  * Fetch transaction details for a batch of confirmed transactions.
2159
2275
  * Similar to {@link getParsedTransactions} but returns a {@link TransactionResponse}.
2276
+ *
2277
+ * @deprecated Instead, call `getTransactions` using a
2278
+ * `GetVersionedTransactionConfig` by setting the
2279
+ * `maxSupportedTransactionVersion` property.
2160
2280
  */
2161
2281
  getTransactions(
2162
2282
  signatures: TransactionSignature[],
2163
2283
  commitmentOrConfig?: GetTransactionConfig | Finality,
2164
2284
  ): Promise<(TransactionResponse | null)[]>;
2285
+ /**
2286
+ * Fetch transaction details for a batch of confirmed transactions.
2287
+ * Similar to {@link getParsedTransactions} but returns a {@link
2288
+ * VersionedTransactionResponse}.
2289
+ */
2290
+ getTransactions(
2291
+ signatures: TransactionSignature[],
2292
+ commitmentOrConfig: GetVersionedTransactionConfig | Finality,
2293
+ ): Promise<(VersionedTransactionResponse | null)[]>;
2165
2294
  /**
2166
2295
  * Fetch a list of Transactions and transaction statuses from the cluster
2167
2296
  * 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({
@@ -3916,7 +3945,8 @@ const ConfirmedTransactionMetaResult = type({
3916
3945
  logMessages: optional(nullable(array(string()))),
3917
3946
  preTokenBalances: optional(nullable(array(TokenBalanceResult))),
3918
3947
  postTokenBalances: optional(nullable(array(TokenBalanceResult))),
3919
- loadedAddresses: optional(LoadedAddressesResult)
3948
+ loadedAddresses: optional(LoadedAddressesResult),
3949
+ computeUnitsConsumed: optional(number())
3920
3950
  });
3921
3951
  /**
3922
3952
  * @internal
@@ -3934,8 +3964,10 @@ const ParsedConfirmedTransactionMetaResult = type({
3934
3964
  logMessages: optional(nullable(array(string()))),
3935
3965
  preTokenBalances: optional(nullable(array(TokenBalanceResult))),
3936
3966
  postTokenBalances: optional(nullable(array(TokenBalanceResult))),
3937
- loadedAddresses: optional(LoadedAddressesResult)
3967
+ loadedAddresses: optional(LoadedAddressesResult),
3968
+ computeUnitsConsumed: optional(number())
3938
3969
  });
3970
+ const TransactionVersionStruct = union([literal(0), literal('legacy')]);
3939
3971
  /**
3940
3972
  * Expected JSON RPC response for the "getBlock" message
3941
3973
  */
@@ -3946,7 +3978,8 @@ const GetBlockRpcResult = jsonRpcResult(nullable(type({
3946
3978
  parentSlot: number(),
3947
3979
  transactions: array(type({
3948
3980
  transaction: ConfirmedTransactionResult,
3949
- meta: nullable(ConfirmedTransactionMetaResult)
3981
+ meta: nullable(ConfirmedTransactionMetaResult),
3982
+ version: optional(TransactionVersionStruct)
3950
3983
  })),
3951
3984
  rewards: optional(array(type({
3952
3985
  pubkey: string(),
@@ -3998,7 +4031,8 @@ const GetTransactionRpcResult = jsonRpcResult(nullable(type({
3998
4031
  slot: number(),
3999
4032
  meta: ConfirmedTransactionMetaResult,
4000
4033
  blockTime: optional(nullable(number())),
4001
- transaction: ConfirmedTransactionResult
4034
+ transaction: ConfirmedTransactionResult,
4035
+ version: optional(TransactionVersionStruct)
4002
4036
  })));
4003
4037
  /**
4004
4038
  * Expected parsed JSON RPC response for the "getTransaction" message
@@ -4008,7 +4042,8 @@ const GetParsedTransactionRpcResult = jsonRpcResult(nullable(type({
4008
4042
  slot: number(),
4009
4043
  transaction: ParsedConfirmedTransactionResult,
4010
4044
  meta: nullable(ParsedConfirmedTransactionMetaResult),
4011
- blockTime: optional(nullable(number()))
4045
+ blockTime: optional(nullable(number())),
4046
+ version: optional(TransactionVersionStruct)
4012
4047
  })));
4013
4048
  /**
4014
4049
  * Expected JSON RPC response for the "getRecentBlockhash" message
@@ -5251,9 +5286,16 @@ class Connection {
5251
5286
  }
5252
5287
  /**
5253
5288
  * Fetch a processed block from the cluster.
5289
+ *
5290
+ * @deprecated Instead, call `getBlock` using a `GetVersionedBlockConfig` by
5291
+ * setting the `maxSupportedTransactionVersion` property.
5254
5292
  */
5255
5293
 
5256
5294
 
5295
+ /**
5296
+ * Fetch a processed block from the cluster.
5297
+ */
5298
+ // eslint-disable-next-line no-dupe-class-members
5257
5299
  async getBlock(slot, rawConfig) {
5258
5300
  const {
5259
5301
  commitment,
@@ -5276,16 +5318,15 @@ class Connection {
5276
5318
  return { ...result,
5277
5319
  transactions: result.transactions.map(({
5278
5320
  transaction,
5279
- meta
5280
- }) => {
5281
- const message = new Message(transaction.message);
5282
- return {
5283
- meta,
5284
- transaction: { ...transaction,
5285
- message
5286
- }
5287
- };
5288
- })
5321
+ meta,
5322
+ version
5323
+ }) => ({
5324
+ meta,
5325
+ transaction: { ...transaction,
5326
+ message: versionedMessageFromResponse(version, transaction.message)
5327
+ },
5328
+ version
5329
+ }))
5289
5330
  };
5290
5331
  }
5291
5332
  /*
@@ -5345,9 +5386,17 @@ class Connection {
5345
5386
  }
5346
5387
  /**
5347
5388
  * Fetch a confirmed or finalized transaction from the cluster.
5389
+ *
5390
+ * @deprecated Instead, call `getTransaction` using a
5391
+ * `GetVersionedTransactionConfig` by setting the
5392
+ * `maxSupportedTransactionVersion` property.
5348
5393
  */
5349
5394
 
5350
5395
 
5396
+ /**
5397
+ * Fetch a confirmed or finalized transaction from the cluster.
5398
+ */
5399
+ // eslint-disable-next-line no-dupe-class-members
5351
5400
  async getTransaction(signature, rawConfig) {
5352
5401
  const {
5353
5402
  commitment,
@@ -5369,7 +5418,7 @@ class Connection {
5369
5418
  if (!result) return result;
5370
5419
  return { ...result,
5371
5420
  transaction: { ...result.transaction,
5372
- message: new Message(result.transaction.message)
5421
+ message: versionedMessageFromResponse(result.version, result.transaction.message)
5373
5422
  }
5374
5423
  };
5375
5424
  }
@@ -5428,9 +5477,19 @@ class Connection {
5428
5477
  /**
5429
5478
  * Fetch transaction details for a batch of confirmed transactions.
5430
5479
  * Similar to {@link getParsedTransactions} but returns a {@link TransactionResponse}.
5480
+ *
5481
+ * @deprecated Instead, call `getTransactions` using a
5482
+ * `GetVersionedTransactionConfig` by setting the
5483
+ * `maxSupportedTransactionVersion` property.
5431
5484
  */
5432
5485
 
5433
5486
 
5487
+ /**
5488
+ * Fetch transaction details for a batch of confirmed transactions.
5489
+ * Similar to {@link getParsedTransactions} but returns a {@link
5490
+ * VersionedTransactionResponse}.
5491
+ */
5492
+ // eslint-disable-next-line no-dupe-class-members
5434
5493
  async getTransactions(signatures, commitmentOrConfig) {
5435
5494
  const {
5436
5495
  commitment,
@@ -5458,7 +5517,7 @@ class Connection {
5458
5517
  if (!result) return result;
5459
5518
  return { ...result,
5460
5519
  transaction: { ...result.transaction,
5461
- message: new Message(result.transaction.message)
5520
+ message: versionedMessageFromResponse(result.version, result.transaction.message)
5462
5521
  }
5463
5522
  };
5464
5523
  });