@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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@solana/web3.js",
3
- "version": "1.55.0",
3
+ "version": "1.56.2",
4
4
  "description": "Solana Javascript API",
5
5
  "keywords": [
6
6
  "api",
package/src/connection.ts CHANGED
@@ -32,8 +32,12 @@ import {NonceAccount} from './nonce-account';
32
32
  import {PublicKey} from './publickey';
33
33
  import {Signer} from './keypair';
34
34
  import {MS_PER_SLOT} from './timing';
35
- import {Transaction, TransactionStatus} from './transaction';
36
- import {Message} from './message';
35
+ import {
36
+ Transaction,
37
+ TransactionStatus,
38
+ TransactionVersion,
39
+ } from './transaction';
40
+ import {Message, MessageHeader, MessageV0, VersionedMessage} from './message';
37
41
  import {AddressLookupTableAccount} from './programs/address-lookup-table/state';
38
42
  import assert from './utils/assert';
39
43
  import {sleep} from './utils/sleep';
@@ -395,6 +399,32 @@ function notificationResultAndContext<T, U>(value: Struct<T, U>) {
395
399
  });
396
400
  }
397
401
 
402
+ /**
403
+ * @internal
404
+ */
405
+ function versionedMessageFromResponse(
406
+ version: TransactionVersion | undefined,
407
+ response: MessageResponse,
408
+ ): VersionedMessage {
409
+ if (version === 0) {
410
+ return new MessageV0({
411
+ header: response.header,
412
+ staticAccountKeys: response.accountKeys.map(
413
+ accountKey => new PublicKey(accountKey),
414
+ ),
415
+ recentBlockhash: response.recentBlockhash,
416
+ compiledInstructions: response.instructions.map(ix => ({
417
+ programIdIndex: ix.programIdIndex,
418
+ accountKeyIndexes: ix.accounts,
419
+ data: bs58.decode(ix.data),
420
+ })),
421
+ addressTableLookups: response.addressTableLookups!,
422
+ });
423
+ } else {
424
+ return new Message(response);
425
+ }
426
+ }
427
+
398
428
  /**
399
429
  * The level of commitment desired when querying state
400
430
  * <pre>
@@ -457,6 +487,14 @@ export type GetBalanceConfig = {
457
487
  export type GetBlockConfig = {
458
488
  /** The level of finality desired */
459
489
  commitment?: Finality;
490
+ };
491
+
492
+ /**
493
+ * Configuration object for changing `getBlock` query behavior
494
+ */
495
+ export type GetVersionedBlockConfig = {
496
+ /** The level of finality desired */
497
+ commitment?: Finality;
460
498
  /** The max transaction version to return in responses. If the requested transaction is a higher version, an error will be returned */
461
499
  maxSupportedTransactionVersion?: number;
462
500
  };
@@ -537,6 +575,14 @@ export type GetSlotLeaderConfig = {
537
575
  export type GetTransactionConfig = {
538
576
  /** The level of finality desired */
539
577
  commitment?: Finality;
578
+ };
579
+
580
+ /**
581
+ * Configuration object for changing `getTransaction` query behavior
582
+ */
583
+ export type GetVersionedTransactionConfig = {
584
+ /** The level of finality desired */
585
+ commitment?: Finality;
540
586
  /** The max transaction version to return in responses. If the requested transaction is a higher version, an error will be returned */
541
587
  maxSupportedTransactionVersion?: number;
542
588
  };
@@ -842,6 +888,8 @@ export type ParsedTransactionMeta = {
842
888
  err: TransactionError | null;
843
889
  /** The collection of addresses loaded using address lookup tables */
844
890
  loadedAddresses?: LoadedAddresses;
891
+ /** The compute units consumed after processing the transaction */
892
+ computeUnitsConsumed?: number;
845
893
  };
846
894
 
847
895
  export type CompiledInnerInstruction = {
@@ -869,6 +917,10 @@ export type ConfirmedTransactionMeta = {
869
917
  postTokenBalances?: Array<TokenBalance> | null;
870
918
  /** The error result of transaction processing */
871
919
  err: TransactionError | null;
920
+ /** The collection of addresses loaded using address lookup tables */
921
+ loadedAddresses?: LoadedAddresses;
922
+ /** The compute units consumed after processing the transaction */
923
+ computeUnitsConsumed?: number;
872
924
  };
873
925
 
874
926
  /**
@@ -890,6 +942,38 @@ export type TransactionResponse = {
890
942
  blockTime?: number | null;
891
943
  };
892
944
 
945
+ /**
946
+ * A processed transaction from the RPC API
947
+ */
948
+ export type VersionedTransactionResponse = {
949
+ /** The slot during which the transaction was processed */
950
+ slot: number;
951
+ /** The transaction */
952
+ transaction: {
953
+ /** The transaction message */
954
+ message: VersionedMessage;
955
+ /** The transaction signatures */
956
+ signatures: string[];
957
+ };
958
+ /** Metadata produced from the transaction */
959
+ meta: ConfirmedTransactionMeta | null;
960
+ /** The unix timestamp of when the transaction was processed */
961
+ blockTime?: number | null;
962
+ /** The transaction version */
963
+ version?: TransactionVersion;
964
+ };
965
+
966
+ /**
967
+ * A processed transaction message from the RPC API
968
+ */
969
+ type MessageResponse = {
970
+ accountKeys: string[];
971
+ header: MessageHeader;
972
+ instructions: CompiledInstruction[];
973
+ recentBlockhash: string;
974
+ addressTableLookups?: ParsedAddressTableLookup[];
975
+ };
976
+
893
977
  /**
894
978
  * A confirmed transaction on the ledger
895
979
  *
@@ -942,6 +1026,18 @@ export type ParsedInstruction = {
942
1026
  parsed: any;
943
1027
  };
944
1028
 
1029
+ /**
1030
+ * A parsed address table lookup
1031
+ */
1032
+ export type ParsedAddressTableLookup = {
1033
+ /** Address lookup table account key */
1034
+ accountKey: PublicKey;
1035
+ /** Parsed instruction info */
1036
+ writableIndexes: number[];
1037
+ /** Parsed instruction info */
1038
+ readonlyIndexes: number[];
1039
+ };
1040
+
945
1041
  /**
946
1042
  * A parsed transaction message
947
1043
  */
@@ -952,6 +1048,8 @@ export type ParsedMessage = {
952
1048
  instructions: (ParsedInstruction | PartiallyDecodedInstruction)[];
953
1049
  /** Recent blockhash */
954
1050
  recentBlockhash: string;
1051
+ /** Address table lookups used to load additional accounts */
1052
+ addressTableLookups?: ParsedAddressTableLookup[] | null;
955
1053
  };
956
1054
 
957
1055
  /**
@@ -983,6 +1081,8 @@ export type ParsedTransactionWithMeta = {
983
1081
  meta: ParsedTransactionMeta | null;
984
1082
  /** The unix timestamp of when the transaction was processed */
985
1083
  blockTime?: number | null;
1084
+ /** The version of the transaction message */
1085
+ version?: TransactionVersion;
986
1086
  };
987
1087
 
988
1088
  /**
@@ -1006,6 +1106,47 @@ export type BlockResponse = {
1006
1106
  };
1007
1107
  /** Metadata produced from the transaction */
1008
1108
  meta: ConfirmedTransactionMeta | null;
1109
+ /** The transaction version */
1110
+ version?: TransactionVersion;
1111
+ }>;
1112
+ /** Vector of block rewards */
1113
+ rewards?: Array<{
1114
+ /** Public key of reward recipient */
1115
+ pubkey: string;
1116
+ /** Reward value in lamports */
1117
+ lamports: number;
1118
+ /** Account balance after reward is applied */
1119
+ postBalance: number | null;
1120
+ /** Type of reward received */
1121
+ rewardType: string | null;
1122
+ }>;
1123
+ /** The unix timestamp of when the block was processed */
1124
+ blockTime: number | null;
1125
+ };
1126
+
1127
+ /**
1128
+ * A processed block fetched from the RPC API
1129
+ */
1130
+ export type VersionedBlockResponse = {
1131
+ /** Blockhash of this block */
1132
+ blockhash: Blockhash;
1133
+ /** Blockhash of this block's parent */
1134
+ previousBlockhash: Blockhash;
1135
+ /** Slot index of this block's parent */
1136
+ parentSlot: number;
1137
+ /** Vector of transactions with status meta and original message */
1138
+ transactions: Array<{
1139
+ /** The transaction */
1140
+ transaction: {
1141
+ /** The transaction message */
1142
+ message: VersionedMessage;
1143
+ /** The transaction signatures */
1144
+ signatures: string[];
1145
+ };
1146
+ /** Metadata produced from the transaction */
1147
+ meta: ConfirmedTransactionMeta | null;
1148
+ /** The transaction version */
1149
+ version?: TransactionVersion;
1009
1150
  }>;
1010
1151
  /** Vector of block rewards */
1011
1152
  rewards?: Array<{
@@ -1728,6 +1869,12 @@ const GetSignatureStatusesRpcResult = jsonRpcResultAndContext(
1728
1869
  */
1729
1870
  const GetMinimumBalanceForRentExemptionRpcResult = jsonRpcResult(number());
1730
1871
 
1872
+ const AddressTableLookupStruct = pick({
1873
+ accountKey: PublicKeyFromString,
1874
+ writableIndexes: array(number()),
1875
+ readonlyIndexes: array(number()),
1876
+ });
1877
+
1731
1878
  const ConfirmedTransactionResult = pick({
1732
1879
  signatures: array(string()),
1733
1880
  message: pick({
@@ -1745,6 +1892,7 @@ const ConfirmedTransactionResult = pick({
1745
1892
  }),
1746
1893
  ),
1747
1894
  recentBlockhash: string(),
1895
+ addressTableLookups: optional(array(AddressTableLookupStruct)),
1748
1896
  }),
1749
1897
  });
1750
1898
 
@@ -1805,6 +1953,7 @@ const ParsedConfirmedTransactionResult = pick({
1805
1953
  ),
1806
1954
  instructions: array(ParsedOrRawInstruction),
1807
1955
  recentBlockhash: string(),
1956
+ addressTableLookups: optional(nullable(array(AddressTableLookupStruct))),
1808
1957
  }),
1809
1958
  });
1810
1959
 
@@ -1848,6 +1997,7 @@ const ConfirmedTransactionMetaResult = pick({
1848
1997
  preTokenBalances: optional(nullable(array(TokenBalanceResult))),
1849
1998
  postTokenBalances: optional(nullable(array(TokenBalanceResult))),
1850
1999
  loadedAddresses: optional(LoadedAddressesResult),
2000
+ computeUnitsConsumed: optional(number()),
1851
2001
  });
1852
2002
 
1853
2003
  /**
@@ -1872,8 +2022,11 @@ const ParsedConfirmedTransactionMetaResult = pick({
1872
2022
  preTokenBalances: optional(nullable(array(TokenBalanceResult))),
1873
2023
  postTokenBalances: optional(nullable(array(TokenBalanceResult))),
1874
2024
  loadedAddresses: optional(LoadedAddressesResult),
2025
+ computeUnitsConsumed: optional(number()),
1875
2026
  });
1876
2027
 
2028
+ const TransactionVersionStruct = union([literal(0), literal('legacy')]);
2029
+
1877
2030
  /**
1878
2031
  * Expected JSON RPC response for the "getBlock" message
1879
2032
  */
@@ -1887,6 +2040,7 @@ const GetBlockRpcResult = jsonRpcResult(
1887
2040
  pick({
1888
2041
  transaction: ConfirmedTransactionResult,
1889
2042
  meta: nullable(ConfirmedTransactionMetaResult),
2043
+ version: optional(TransactionVersionStruct),
1890
2044
  }),
1891
2045
  ),
1892
2046
  rewards: optional(
@@ -1962,6 +2116,7 @@ const GetTransactionRpcResult = jsonRpcResult(
1962
2116
  meta: ConfirmedTransactionMetaResult,
1963
2117
  blockTime: optional(nullable(number())),
1964
2118
  transaction: ConfirmedTransactionResult,
2119
+ version: optional(TransactionVersionStruct),
1965
2120
  }),
1966
2121
  ),
1967
2122
  );
@@ -1976,6 +2131,7 @@ const GetParsedTransactionRpcResult = jsonRpcResult(
1976
2131
  transaction: ParsedConfirmedTransactionResult,
1977
2132
  meta: nullable(ParsedConfirmedTransactionMetaResult),
1978
2133
  blockTime: optional(nullable(number())),
2134
+ version: optional(TransactionVersionStruct),
1979
2135
  }),
1980
2136
  ),
1981
2137
  );
@@ -3644,11 +3800,32 @@ export class Connection {
3644
3800
 
3645
3801
  /**
3646
3802
  * Fetch a processed block from the cluster.
3803
+ *
3804
+ * @deprecated Instead, call `getBlock` using a `GetVersionedBlockConfig` by
3805
+ * setting the `maxSupportedTransactionVersion` property.
3647
3806
  */
3648
3807
  async getBlock(
3649
3808
  slot: number,
3650
3809
  rawConfig?: GetBlockConfig,
3651
- ): Promise<BlockResponse | null> {
3810
+ ): Promise<BlockResponse | null>;
3811
+
3812
+ /**
3813
+ * Fetch a processed block from the cluster.
3814
+ */
3815
+ // eslint-disable-next-line no-dupe-class-members
3816
+ async getBlock(
3817
+ slot: number,
3818
+ rawConfig?: GetVersionedBlockConfig,
3819
+ ): Promise<VersionedBlockResponse | null>;
3820
+
3821
+ /**
3822
+ * Fetch a processed block from the cluster.
3823
+ */
3824
+ // eslint-disable-next-line no-dupe-class-members
3825
+ async getBlock(
3826
+ slot: number,
3827
+ rawConfig?: GetVersionedBlockConfig,
3828
+ ): Promise<VersionedBlockResponse | null> {
3652
3829
  const {commitment, config} = extractCommitmentFromConfig(rawConfig);
3653
3830
  const args = this._buildArgsAtLeastConfirmed(
3654
3831
  [slot],
@@ -3668,16 +3845,14 @@ export class Connection {
3668
3845
 
3669
3846
  return {
3670
3847
  ...result,
3671
- transactions: result.transactions.map(({transaction, meta}) => {
3672
- const message = new Message(transaction.message);
3673
- return {
3674
- meta,
3675
- transaction: {
3676
- ...transaction,
3677
- message,
3678
- },
3679
- };
3680
- }),
3848
+ transactions: result.transactions.map(({transaction, meta, version}) => ({
3849
+ meta,
3850
+ transaction: {
3851
+ ...transaction,
3852
+ message: versionedMessageFromResponse(version, transaction.message),
3853
+ },
3854
+ version,
3855
+ })),
3681
3856
  };
3682
3857
  }
3683
3858
 
@@ -3739,11 +3914,33 @@ export class Connection {
3739
3914
 
3740
3915
  /**
3741
3916
  * Fetch a confirmed or finalized transaction from the cluster.
3917
+ *
3918
+ * @deprecated Instead, call `getTransaction` using a
3919
+ * `GetVersionedTransactionConfig` by setting the
3920
+ * `maxSupportedTransactionVersion` property.
3742
3921
  */
3743
3922
  async getTransaction(
3744
3923
  signature: string,
3745
3924
  rawConfig?: GetTransactionConfig,
3746
- ): Promise<TransactionResponse | null> {
3925
+ ): Promise<TransactionResponse | null>;
3926
+
3927
+ /**
3928
+ * Fetch a confirmed or finalized transaction from the cluster.
3929
+ */
3930
+ // eslint-disable-next-line no-dupe-class-members
3931
+ async getTransaction(
3932
+ signature: string,
3933
+ rawConfig: GetVersionedTransactionConfig,
3934
+ ): Promise<VersionedTransactionResponse | null>;
3935
+
3936
+ /**
3937
+ * Fetch a confirmed or finalized transaction from the cluster.
3938
+ */
3939
+ // eslint-disable-next-line no-dupe-class-members
3940
+ async getTransaction(
3941
+ signature: string,
3942
+ rawConfig?: GetVersionedTransactionConfig,
3943
+ ): Promise<VersionedTransactionResponse | null> {
3747
3944
  const {commitment, config} = extractCommitmentFromConfig(rawConfig);
3748
3945
  const args = this._buildArgsAtLeastConfirmed(
3749
3946
  [signature],
@@ -3764,7 +3961,10 @@ export class Connection {
3764
3961
  ...result,
3765
3962
  transaction: {
3766
3963
  ...result.transaction,
3767
- message: new Message(result.transaction.message),
3964
+ message: versionedMessageFromResponse(
3965
+ result.version,
3966
+ result.transaction.message,
3967
+ ),
3768
3968
  },
3769
3969
  };
3770
3970
  }
@@ -3774,8 +3974,8 @@ export class Connection {
3774
3974
  */
3775
3975
  async getParsedTransaction(
3776
3976
  signature: TransactionSignature,
3777
- commitmentOrConfig?: GetTransactionConfig | Finality,
3778
- ): Promise<ParsedConfirmedTransaction | null> {
3977
+ commitmentOrConfig?: GetVersionedTransactionConfig | Finality,
3978
+ ): Promise<ParsedTransactionWithMeta | null> {
3779
3979
  const {commitment, config} =
3780
3980
  extractCommitmentFromConfig(commitmentOrConfig);
3781
3981
  const args = this._buildArgsAtLeastConfirmed(
@@ -3797,8 +3997,8 @@ export class Connection {
3797
3997
  */
3798
3998
  async getParsedTransactions(
3799
3999
  signatures: TransactionSignature[],
3800
- commitmentOrConfig?: GetTransactionConfig | Finality,
3801
- ): Promise<(ParsedConfirmedTransaction | null)[]> {
4000
+ commitmentOrConfig?: GetVersionedTransactionConfig | Finality,
4001
+ ): Promise<(ParsedTransactionWithMeta | null)[]> {
3802
4002
  const {commitment, config} =
3803
4003
  extractCommitmentFromConfig(commitmentOrConfig);
3804
4004
  const batch = signatures.map(signature => {
@@ -3829,11 +4029,37 @@ export class Connection {
3829
4029
  /**
3830
4030
  * Fetch transaction details for a batch of confirmed transactions.
3831
4031
  * Similar to {@link getParsedTransactions} but returns a {@link TransactionResponse}.
4032
+ *
4033
+ * @deprecated Instead, call `getTransactions` using a
4034
+ * `GetVersionedTransactionConfig` by setting the
4035
+ * `maxSupportedTransactionVersion` property.
3832
4036
  */
3833
4037
  async getTransactions(
3834
4038
  signatures: TransactionSignature[],
3835
4039
  commitmentOrConfig?: GetTransactionConfig | Finality,
3836
- ): Promise<(TransactionResponse | null)[]> {
4040
+ ): Promise<(TransactionResponse | null)[]>;
4041
+
4042
+ /**
4043
+ * Fetch transaction details for a batch of confirmed transactions.
4044
+ * Similar to {@link getParsedTransactions} but returns a {@link
4045
+ * VersionedTransactionResponse}.
4046
+ */
4047
+ // eslint-disable-next-line no-dupe-class-members
4048
+ async getTransactions(
4049
+ signatures: TransactionSignature[],
4050
+ commitmentOrConfig: GetVersionedTransactionConfig | Finality,
4051
+ ): Promise<(VersionedTransactionResponse | null)[]>;
4052
+
4053
+ /**
4054
+ * Fetch transaction details for a batch of confirmed transactions.
4055
+ * Similar to {@link getParsedTransactions} but returns a {@link
4056
+ * VersionedTransactionResponse}.
4057
+ */
4058
+ // eslint-disable-next-line no-dupe-class-members
4059
+ async getTransactions(
4060
+ signatures: TransactionSignature[],
4061
+ commitmentOrConfig: GetVersionedTransactionConfig | Finality,
4062
+ ): Promise<(VersionedTransactionResponse | null)[]> {
3837
4063
  const {commitment, config} =
3838
4064
  extractCommitmentFromConfig(commitmentOrConfig);
3839
4065
  const batch = signatures.map(signature => {
@@ -3862,7 +4088,10 @@ export class Connection {
3862
4088
  ...result,
3863
4089
  transaction: {
3864
4090
  ...result.transaction,
3865
- message: new Message(result.transaction.message),
4091
+ message: versionedMessageFromResponse(
4092
+ result.version,
4093
+ result.transaction.message,
4094
+ ),
3866
4095
  },
3867
4096
  };
3868
4097
  });