@solana/web3.js 1.30.1 → 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/src/connection.ts CHANGED
@@ -99,6 +99,8 @@ export type SendOptions = {
99
99
  skipPreflight?: boolean;
100
100
  /** preflight commitment level */
101
101
  preflightCommitment?: Commitment;
102
+ /** Maximum number of times for the RPC node to retry sending the transaction to the leader. */
103
+ maxRetries?: number;
102
104
  };
103
105
 
104
106
  /**
@@ -111,6 +113,8 @@ export type ConfirmOptions = {
111
113
  commitment?: Commitment;
112
114
  /** preflight commitment level */
113
115
  preflightCommitment?: Commitment;
116
+ /** Maximum number of times for the RPC node to retry sending the transaction to the leader. */
117
+ maxRetries?: number;
114
118
  };
115
119
 
116
120
  /**
@@ -498,13 +502,21 @@ export type ParsedInnerInstruction = {
498
502
  export type TokenBalance = {
499
503
  accountIndex: number;
500
504
  mint: string;
505
+ owner?: string;
501
506
  uiTokenAmount: TokenAmount;
502
507
  };
503
508
 
504
509
  /**
505
510
  * Metadata for a parsed confirmed transaction on the ledger
511
+ *
512
+ * @deprecated Deprecated since Solana v1.8.0. Please use {@link ParsedTransactionMeta} instead.
506
513
  */
507
- export type ParsedConfirmedTransactionMeta = {
514
+ export type ParsedConfirmedTransactionMeta = ParsedTransactionMeta;
515
+
516
+ /**
517
+ * Metadata for a parsed transaction on the ledger
518
+ */
519
+ export type ParsedTransactionMeta = {
508
520
  /** The fee charged for processing the transaction */
509
521
  fee: number;
510
522
  /** An array of cross program invoked parsed instructions */
@@ -643,14 +655,21 @@ export type ParsedTransaction = {
643
655
 
644
656
  /**
645
657
  * A parsed and confirmed transaction on the ledger
658
+ *
659
+ * @deprecated Deprecated since Solana v1.8.0. Please use {@link ParsedTransactionWithMeta} instead.
646
660
  */
647
- export type ParsedConfirmedTransaction = {
661
+ export type ParsedConfirmedTransaction = ParsedTransactionWithMeta;
662
+
663
+ /**
664
+ * A parsed transaction on the ledger with meta
665
+ */
666
+ export type ParsedTransactionWithMeta = {
648
667
  /** The slot during which the transaction was processed */
649
668
  slot: number;
650
669
  /** The details of the transaction */
651
670
  transaction: ParsedTransaction;
652
671
  /** Metadata produced from the transaction */
653
- meta: ParsedConfirmedTransactionMeta | null;
672
+ meta: ParsedTransactionMeta | null;
654
673
  /** The unix timestamp of when the transaction was processed */
655
674
  blockTime?: number | null;
656
675
  };
@@ -719,9 +738,9 @@ export type ConfirmedBlock = {
719
738
  };
720
739
 
721
740
  /**
722
- * A ConfirmedBlock on the ledger with signatures only
741
+ * A Block on the ledger with signatures only
723
742
  */
724
- export type ConfirmedBlockSignatures = {
743
+ export type BlockSignatures = {
725
744
  /** Blockhash of this block */
726
745
  blockhash: Blockhash;
727
746
  /** Blockhash of this block's parent */
@@ -760,19 +779,24 @@ function createRpcClient(
760
779
  agentManager = new AgentManager(useHttps);
761
780
  }
762
781
 
763
- let fetchWithMiddleware: (url: string, options: any) => Promise<Response>;
782
+ let fetchWithMiddleware:
783
+ | ((url: string, options: any) => Promise<Response>)
784
+ | undefined;
764
785
 
765
786
  if (fetchMiddleware) {
766
- fetchWithMiddleware = (url: string, options: any) => {
767
- return new Promise<Response>((resolve, reject) => {
768
- fetchMiddleware(url, options, async (url: string, options: any) => {
787
+ fetchWithMiddleware = async (url: string, options: any) => {
788
+ const modifiedFetchArgs = await new Promise<[string, any]>(
789
+ (resolve, reject) => {
769
790
  try {
770
- resolve(await fetch(url, options));
791
+ fetchMiddleware(url, options, (modifiedUrl, modifiedOptions) =>
792
+ resolve([modifiedUrl, modifiedOptions]),
793
+ );
771
794
  } catch (error) {
772
795
  reject(error);
773
796
  }
774
- });
775
- });
797
+ },
798
+ );
799
+ return await fetch(...modifiedFetchArgs);
776
800
  };
777
801
  }
778
802
 
@@ -1432,6 +1456,7 @@ const ParsedConfirmedTransactionResult = pick({
1432
1456
  const TokenBalanceResult = pick({
1433
1457
  accountIndex: number(),
1434
1458
  mint: string(),
1459
+ owner: optional(string()),
1435
1460
  uiTokenAmount: TokenAmountResult,
1436
1461
  });
1437
1462
 
@@ -1487,8 +1512,41 @@ const ParsedConfirmedTransactionMetaResult = pick({
1487
1512
  postTokenBalances: optional(nullable(array(TokenBalanceResult))),
1488
1513
  });
1489
1514
 
1515
+ /**
1516
+ * Expected JSON RPC response for the "getBlock" message
1517
+ */
1518
+ const GetBlockRpcResult = jsonRpcResult(
1519
+ nullable(
1520
+ pick({
1521
+ blockhash: string(),
1522
+ previousBlockhash: string(),
1523
+ parentSlot: number(),
1524
+ transactions: array(
1525
+ pick({
1526
+ transaction: ConfirmedTransactionResult,
1527
+ meta: nullable(ConfirmedTransactionMetaResult),
1528
+ }),
1529
+ ),
1530
+ rewards: optional(
1531
+ array(
1532
+ pick({
1533
+ pubkey: string(),
1534
+ lamports: number(),
1535
+ postBalance: nullable(number()),
1536
+ rewardType: nullable(string()),
1537
+ }),
1538
+ ),
1539
+ ),
1540
+ blockTime: nullable(number()),
1541
+ blockHeight: nullable(number()),
1542
+ }),
1543
+ ),
1544
+ );
1545
+
1490
1546
  /**
1491
1547
  * Expected JSON RPC response for the "getConfirmedBlock" message
1548
+ *
1549
+ * @deprecated Deprecated since Solana v1.8.0. Please use {@link GetBlockRpcResult} instead.
1492
1550
  */
1493
1551
  const GetConfirmedBlockRpcResult = jsonRpcResult(
1494
1552
  nullable(
@@ -1518,9 +1576,9 @@ const GetConfirmedBlockRpcResult = jsonRpcResult(
1518
1576
  );
1519
1577
 
1520
1578
  /**
1521
- * Expected JSON RPC response for the "getConfirmedBlockSignatures" message
1579
+ * Expected JSON RPC response for the "getBlock" message
1522
1580
  */
1523
- const GetConfirmedBlockSignaturesRpcResult = jsonRpcResult(
1581
+ const GetBlockSignaturesRpcResult = jsonRpcResult(
1524
1582
  nullable(
1525
1583
  pick({
1526
1584
  blockhash: string(),
@@ -1533,9 +1591,9 @@ const GetConfirmedBlockSignaturesRpcResult = jsonRpcResult(
1533
1591
  );
1534
1592
 
1535
1593
  /**
1536
- * Expected JSON RPC response for the "getConfirmedTransaction" message
1594
+ * Expected JSON RPC response for the "getTransaction" message
1537
1595
  */
1538
- const GetConfirmedTransactionRpcResult = jsonRpcResult(
1596
+ const GetTransactionRpcResult = jsonRpcResult(
1539
1597
  nullable(
1540
1598
  pick({
1541
1599
  slot: number(),
@@ -1547,9 +1605,9 @@ const GetConfirmedTransactionRpcResult = jsonRpcResult(
1547
1605
  );
1548
1606
 
1549
1607
  /**
1550
- * Expected JSON RPC response for the "getConfirmedTransaction" message
1608
+ * Expected parsed JSON RPC response for the "getTransaction" message
1551
1609
  */
1552
- const GetParsedConfirmedTransactionRpcResult = jsonRpcResult(
1610
+ const GetParsedTransactionRpcResult = jsonRpcResult(
1553
1611
  nullable(
1554
1612
  pick({
1555
1613
  slot: number(),
@@ -1562,6 +1620,8 @@ const GetParsedConfirmedTransactionRpcResult = jsonRpcResult(
1562
1620
 
1563
1621
  /**
1564
1622
  * Expected JSON RPC response for the "getRecentBlockhash" message
1623
+ *
1624
+ * @deprecated Deprecated since Solana v1.8.0. Please use {@link GetLatestBlockhashRpcResult} instead.
1565
1625
  */
1566
1626
  const GetRecentBlockhashAndContextRpcResult = jsonRpcResultAndContext(
1567
1627
  pick({
@@ -1572,6 +1632,16 @@ const GetRecentBlockhashAndContextRpcResult = jsonRpcResultAndContext(
1572
1632
  }),
1573
1633
  );
1574
1634
 
1635
+ /**
1636
+ * Expected JSON RPC response for the "getLatestBlockhash" message
1637
+ */
1638
+ const GetLatestBlockhashRpcResult = jsonRpcResultAndContext(
1639
+ pick({
1640
+ blockhash: string(),
1641
+ lastValidBlockHeight: number(),
1642
+ }),
1643
+ );
1644
+
1575
1645
  const PerfSampleResult = pick({
1576
1646
  slot: number(),
1577
1647
  numTransactions: number(),
@@ -1706,6 +1776,16 @@ export type GetParsedProgramAccountsConfig = {
1706
1776
  filters?: GetProgramAccountsFilter[];
1707
1777
  };
1708
1778
 
1779
+ /**
1780
+ * Configuration object for getMultipleAccounts
1781
+ */
1782
+ export type GetMultipleAccountsConfig = {
1783
+ /** Optional commitment level */
1784
+ commitment?: Commitment;
1785
+ /** Optional encoding for account data (default base64) */
1786
+ encoding?: 'base64' | 'jsonParsed';
1787
+ };
1788
+
1709
1789
  /**
1710
1790
  * Information describing an account
1711
1791
  */
@@ -1718,7 +1798,7 @@ export type AccountInfo<T> = {
1718
1798
  lamports: number;
1719
1799
  /** Optional data assigned to the account */
1720
1800
  data: T;
1721
- /** Optional rent epoch infor for account */
1801
+ /** Optional rent epoch info for account */
1722
1802
  rentEpoch?: number;
1723
1803
  };
1724
1804
 
@@ -1972,7 +2052,7 @@ export type HttpHeaders = {[header: string]: string};
1972
2052
  export type FetchMiddleware = (
1973
2053
  url: string,
1974
2054
  options: any,
1975
- fetch: Function,
2055
+ fetch: (modifiedUrl: string, modifiedOptions: any) => void,
1976
2056
  ) => void;
1977
2057
 
1978
2058
  /**
@@ -2474,14 +2554,27 @@ export class Connection {
2474
2554
  */
2475
2555
  async getMultipleAccountsInfo(
2476
2556
  publicKeys: PublicKey[],
2477
- commitment?: Commitment,
2478
- ): Promise<(AccountInfo<Buffer> | null)[]> {
2557
+ configOrCommitment?: GetMultipleAccountsConfig | Commitment,
2558
+ ): Promise<(AccountInfo<Buffer | ParsedAccountData> | null)[]> {
2479
2559
  const keys = publicKeys.map(key => key.toBase58());
2480
- const args = this._buildArgs([keys], commitment, 'base64');
2560
+
2561
+ let commitment;
2562
+ let encoding: 'base64' | 'jsonParsed' = 'base64';
2563
+ if (configOrCommitment) {
2564
+ if (typeof configOrCommitment === 'string') {
2565
+ commitment = configOrCommitment;
2566
+ encoding = 'base64';
2567
+ } else {
2568
+ commitment = configOrCommitment.commitment;
2569
+ encoding = configOrCommitment.encoding || 'base64';
2570
+ }
2571
+ }
2572
+
2573
+ const args = this._buildArgs([keys], commitment, encoding);
2481
2574
  const unsafeRes = await this._rpcRequest('getMultipleAccounts', args);
2482
2575
  const res = create(
2483
2576
  unsafeRes,
2484
- jsonRpcResultAndContext(array(nullable(AccountInfoResult))),
2577
+ jsonRpcResultAndContext(array(nullable(ParsedAccountInfoResult))),
2485
2578
  );
2486
2579
  if ('error' in res) {
2487
2580
  throw new Error(
@@ -2932,6 +3025,8 @@ export class Connection {
2932
3025
  /**
2933
3026
  * Fetch a recent blockhash from the cluster, return with context
2934
3027
  * @return {Promise<RpcResponseAndContext<{blockhash: Blockhash, feeCalculator: FeeCalculator}>>}
3028
+ *
3029
+ * @deprecated Deprecated since Solana v1.8.0. Please use {@link getLatestBlockhash} instead.
2935
3030
  */
2936
3031
  async getRecentBlockhashAndContext(
2937
3032
  commitment?: Commitment,
@@ -2971,6 +3066,8 @@ export class Connection {
2971
3066
 
2972
3067
  /**
2973
3068
  * Fetch the fee calculator for a recent blockhash from the cluster, return with context
3069
+ *
3070
+ * @deprecated Deprecated since Solana v1.8.0. Please use {@link getFeeForMessage} instead.
2974
3071
  */
2975
3072
  async getFeeCalculatorForBlockhash(
2976
3073
  blockhash: Blockhash,
@@ -2993,9 +3090,32 @@ export class Connection {
2993
3090
  };
2994
3091
  }
2995
3092
 
3093
+ /**
3094
+ * Fetch the fee for a message from the cluster, return with context
3095
+ */
3096
+ async getFeeForMessage(
3097
+ message: Message,
3098
+ commitment?: Commitment,
3099
+ ): Promise<RpcResponseAndContext<number>> {
3100
+ const wireMessage = message.serialize().toString('base64');
3101
+ const args = this._buildArgs([wireMessage], commitment);
3102
+ const unsafeRes = await this._rpcRequest('getFeeForMessage', args);
3103
+
3104
+ const res = create(unsafeRes, jsonRpcResultAndContext(nullable(number())));
3105
+ if ('error' in res) {
3106
+ throw new Error('failed to get slot: ' + res.error.message);
3107
+ }
3108
+ if (res.result === null) {
3109
+ throw new Error('invalid blockhash');
3110
+ }
3111
+ return res.result as unknown as RpcResponseAndContext<number>;
3112
+ }
3113
+
2996
3114
  /**
2997
3115
  * Fetch a recent blockhash from the cluster
2998
3116
  * @return {Promise<{blockhash: Blockhash, feeCalculator: FeeCalculator}>}
3117
+ *
3118
+ * @deprecated Deprecated since Solana v1.8.0. Please use {@link getLatestBlockhash} instead.
2999
3119
  */
3000
3120
  async getRecentBlockhash(
3001
3121
  commitment?: Commitment,
@@ -3008,6 +3128,39 @@ export class Connection {
3008
3128
  }
3009
3129
  }
3010
3130
 
3131
+ /**
3132
+ * Fetch the latest blockhash from the cluster
3133
+ * @return {Promise<{blockhash: Blockhash, lastValidBlockHeight: number}>}
3134
+ */
3135
+ async getLatestBlockhash(
3136
+ commitment?: Commitment,
3137
+ ): Promise<{blockhash: Blockhash; lastValidBlockHeight: number}> {
3138
+ try {
3139
+ const res = await this.getLatestBlockhashAndContext(commitment);
3140
+ return res.value;
3141
+ } catch (e) {
3142
+ throw new Error('failed to get recent blockhash: ' + e);
3143
+ }
3144
+ }
3145
+
3146
+ /**
3147
+ * Fetch the latest blockhash from the cluster
3148
+ * @return {Promise<{blockhash: Blockhash, lastValidBlockHeight: number}>}
3149
+ */
3150
+ async getLatestBlockhashAndContext(
3151
+ commitment?: Commitment,
3152
+ ): Promise<
3153
+ RpcResponseAndContext<{blockhash: Blockhash; lastValidBlockHeight: number}>
3154
+ > {
3155
+ const args = this._buildArgs([], commitment);
3156
+ const unsafeRes = await this._rpcRequest('getLatestBlockhash', args);
3157
+ const res = create(unsafeRes, GetLatestBlockhashRpcResult);
3158
+ if ('error' in res) {
3159
+ throw new Error('failed to get latest blockhash: ' + res.error.message);
3160
+ }
3161
+ return res.result;
3162
+ }
3163
+
3011
3164
  /**
3012
3165
  * Fetch the node version
3013
3166
  */
@@ -3043,8 +3196,8 @@ export class Connection {
3043
3196
  [slot],
3044
3197
  opts && opts.commitment,
3045
3198
  );
3046
- const unsafeRes = await this._rpcRequest('getConfirmedBlock', args);
3047
- const res = create(unsafeRes, GetConfirmedBlockRpcResult);
3199
+ const unsafeRes = await this._rpcRequest('getBlock', args);
3200
+ const res = create(unsafeRes, GetBlockRpcResult);
3048
3201
 
3049
3202
  if ('error' in res) {
3050
3203
  throw new Error('failed to get confirmed block: ' + res.error.message);
@@ -3069,7 +3222,7 @@ export class Connection {
3069
3222
  }
3070
3223
 
3071
3224
  /**
3072
- * Fetch a processed transaction from the cluster.
3225
+ * Fetch a confirmed or finalized transaction from the cluster.
3073
3226
  */
3074
3227
  async getTransaction(
3075
3228
  signature: string,
@@ -3079,12 +3232,10 @@ export class Connection {
3079
3232
  [signature],
3080
3233
  opts && opts.commitment,
3081
3234
  );
3082
- const unsafeRes = await this._rpcRequest('getConfirmedTransaction', args);
3083
- const res = create(unsafeRes, GetConfirmedTransactionRpcResult);
3235
+ const unsafeRes = await this._rpcRequest('getTransaction', args);
3236
+ const res = create(unsafeRes, GetTransactionRpcResult);
3084
3237
  if ('error' in res) {
3085
- throw new Error(
3086
- 'failed to get confirmed transaction: ' + res.error.message,
3087
- );
3238
+ throw new Error('failed to get transaction: ' + res.error.message);
3088
3239
  }
3089
3240
 
3090
3241
  const result = res.result;
@@ -3099,6 +3250,57 @@ export class Connection {
3099
3250
  };
3100
3251
  }
3101
3252
 
3253
+ /**
3254
+ * Fetch parsed transaction details for a confirmed or finalized transaction
3255
+ */
3256
+ async getParsedTransaction(
3257
+ signature: TransactionSignature,
3258
+ commitment?: Finality,
3259
+ ): Promise<ParsedConfirmedTransaction | null> {
3260
+ const args = this._buildArgsAtLeastConfirmed(
3261
+ [signature],
3262
+ commitment,
3263
+ 'jsonParsed',
3264
+ );
3265
+ const unsafeRes = await this._rpcRequest('getTransaction', args);
3266
+ const res = create(unsafeRes, GetParsedTransactionRpcResult);
3267
+ if ('error' in res) {
3268
+ throw new Error('failed to get transaction: ' + res.error.message);
3269
+ }
3270
+ return res.result;
3271
+ }
3272
+
3273
+ /**
3274
+ * Fetch parsed transaction details for a batch of confirmed transactions
3275
+ */
3276
+ async getParsedTransactions(
3277
+ signatures: TransactionSignature[],
3278
+ commitment?: Finality,
3279
+ ): Promise<(ParsedConfirmedTransaction | null)[]> {
3280
+ const batch = signatures.map(signature => {
3281
+ const args = this._buildArgsAtLeastConfirmed(
3282
+ [signature],
3283
+ commitment,
3284
+ 'jsonParsed',
3285
+ );
3286
+ return {
3287
+ methodName: 'getTransaction',
3288
+ args,
3289
+ };
3290
+ });
3291
+
3292
+ const unsafeRes = await this._rpcBatchRequest(batch);
3293
+ const res = unsafeRes.map((unsafeRes: any) => {
3294
+ const res = create(unsafeRes, GetParsedTransactionRpcResult);
3295
+ if ('error' in res) {
3296
+ throw new Error('failed to get transactions: ' + res.error.message);
3297
+ }
3298
+ return res.result;
3299
+ });
3300
+
3301
+ return res;
3302
+ }
3303
+
3102
3304
  /**
3103
3305
  * Fetch a list of Transactions and transaction statuses from the cluster
3104
3306
  * for a confirmed block.
@@ -3109,14 +3311,36 @@ export class Connection {
3109
3311
  slot: number,
3110
3312
  commitment?: Finality,
3111
3313
  ): Promise<ConfirmedBlock> {
3112
- const result = await this.getBlock(slot, {commitment});
3314
+ const args = this._buildArgsAtLeastConfirmed([slot], commitment);
3315
+ const unsafeRes = await this._rpcRequest('getConfirmedBlock', args);
3316
+ const res = create(unsafeRes, GetConfirmedBlockRpcResult);
3317
+
3318
+ if ('error' in res) {
3319
+ throw new Error('failed to get confirmed block: ' + res.error.message);
3320
+ }
3321
+
3322
+ const result = res.result;
3113
3323
  if (!result) {
3114
3324
  throw new Error('Confirmed block ' + slot + ' not found');
3115
3325
  }
3116
3326
 
3117
- return {
3327
+ const block = {
3118
3328
  ...result,
3119
3329
  transactions: result.transactions.map(({transaction, meta}) => {
3330
+ const message = new Message(transaction.message);
3331
+ return {
3332
+ meta,
3333
+ transaction: {
3334
+ ...transaction,
3335
+ message,
3336
+ },
3337
+ };
3338
+ }),
3339
+ };
3340
+
3341
+ return {
3342
+ ...block,
3343
+ transactions: block.transactions.map(({transaction, meta}) => {
3120
3344
  return {
3121
3345
  meta,
3122
3346
  transaction: Transaction.populate(
@@ -3140,7 +3364,7 @@ export class Connection {
3140
3364
  endSlot !== undefined ? [startSlot, endSlot] : [startSlot],
3141
3365
  commitment,
3142
3366
  );
3143
- const unsafeRes = await this._rpcRequest('getConfirmedBlocks', args);
3367
+ const unsafeRes = await this._rpcRequest('getBlocks', args);
3144
3368
  const res = create(unsafeRes, jsonRpcResult(array(number())));
3145
3369
  if ('error' in res) {
3146
3370
  throw new Error('failed to get blocks: ' + res.error.message);
@@ -3148,13 +3372,43 @@ export class Connection {
3148
3372
  return res.result;
3149
3373
  }
3150
3374
 
3375
+ /**
3376
+ * Fetch a list of Signatures from the cluster for a block, excluding rewards
3377
+ */
3378
+ async getBlockSignatures(
3379
+ slot: number,
3380
+ commitment?: Finality,
3381
+ ): Promise<BlockSignatures> {
3382
+ const args = this._buildArgsAtLeastConfirmed(
3383
+ [slot],
3384
+ commitment,
3385
+ undefined,
3386
+ {
3387
+ transactionDetails: 'signatures',
3388
+ rewards: false,
3389
+ },
3390
+ );
3391
+ const unsafeRes = await this._rpcRequest('getBlock', args);
3392
+ const res = create(unsafeRes, GetBlockSignaturesRpcResult);
3393
+ if ('error' in res) {
3394
+ throw new Error('failed to get block: ' + res.error.message);
3395
+ }
3396
+ const result = res.result;
3397
+ if (!result) {
3398
+ throw new Error('Block ' + slot + ' not found');
3399
+ }
3400
+ return result;
3401
+ }
3402
+
3151
3403
  /**
3152
3404
  * Fetch a list of Signatures from the cluster for a confirmed block, excluding rewards
3405
+ *
3406
+ * @deprecated Deprecated since Solana v1.8.0. Please use {@link getBlockSignatures} instead.
3153
3407
  */
3154
3408
  async getConfirmedBlockSignatures(
3155
3409
  slot: number,
3156
3410
  commitment?: Finality,
3157
- ): Promise<ConfirmedBlockSignatures> {
3411
+ ): Promise<BlockSignatures> {
3158
3412
  const args = this._buildArgsAtLeastConfirmed(
3159
3413
  [slot],
3160
3414
  commitment,
@@ -3165,7 +3419,7 @@ export class Connection {
3165
3419
  },
3166
3420
  );
3167
3421
  const unsafeRes = await this._rpcRequest('getConfirmedBlock', args);
3168
- const res = create(unsafeRes, GetConfirmedBlockSignaturesRpcResult);
3422
+ const res = create(unsafeRes, GetBlockSignaturesRpcResult);
3169
3423
  if ('error' in res) {
3170
3424
  throw new Error('failed to get confirmed block: ' + res.error.message);
3171
3425
  }
@@ -3178,14 +3432,25 @@ export class Connection {
3178
3432
 
3179
3433
  /**
3180
3434
  * Fetch a transaction details for a confirmed transaction
3435
+ *
3436
+ * @deprecated Deprecated since Solana v1.8.0. Please use {@link getTransaction} instead.
3181
3437
  */
3182
3438
  async getConfirmedTransaction(
3183
3439
  signature: TransactionSignature,
3184
3440
  commitment?: Finality,
3185
3441
  ): Promise<ConfirmedTransaction | null> {
3186
- const result = await this.getTransaction(signature, {commitment});
3442
+ const args = this._buildArgsAtLeastConfirmed([signature], commitment);
3443
+ const unsafeRes = await this._rpcRequest('getConfirmedTransaction', args);
3444
+ const res = create(unsafeRes, GetTransactionRpcResult);
3445
+ if ('error' in res) {
3446
+ throw new Error('failed to get transaction: ' + res.error.message);
3447
+ }
3448
+
3449
+ const result = res.result;
3187
3450
  if (!result) return result;
3188
- const {message, signatures} = result.transaction;
3451
+
3452
+ const message = new Message(result.transaction.message);
3453
+ const signatures = result.transaction.signatures;
3189
3454
  return {
3190
3455
  ...result,
3191
3456
  transaction: Transaction.populate(message, signatures),
@@ -3194,6 +3459,8 @@ export class Connection {
3194
3459
 
3195
3460
  /**
3196
3461
  * Fetch parsed transaction details for a confirmed transaction
3462
+ *
3463
+ * @deprecated Deprecated since Solana v1.8.0. Please use {@link getParsedTransaction} instead.
3197
3464
  */
3198
3465
  async getParsedConfirmedTransaction(
3199
3466
  signature: TransactionSignature,
@@ -3205,7 +3472,7 @@ export class Connection {
3205
3472
  'jsonParsed',
3206
3473
  );
3207
3474
  const unsafeRes = await this._rpcRequest('getConfirmedTransaction', args);
3208
- const res = create(unsafeRes, GetParsedConfirmedTransactionRpcResult);
3475
+ const res = create(unsafeRes, GetParsedTransactionRpcResult);
3209
3476
  if ('error' in res) {
3210
3477
  throw new Error(
3211
3478
  'failed to get confirmed transaction: ' + res.error.message,
@@ -3216,6 +3483,8 @@ export class Connection {
3216
3483
 
3217
3484
  /**
3218
3485
  * Fetch parsed transaction details for a batch of confirmed transactions
3486
+ *
3487
+ * @deprecated Deprecated since Solana v1.8.0. Please use {@link getParsedTransactions} instead.
3219
3488
  */
3220
3489
  async getParsedConfirmedTransactions(
3221
3490
  signatures: TransactionSignature[],
@@ -3235,7 +3504,7 @@ export class Connection {
3235
3504
 
3236
3505
  const unsafeRes = await this._rpcBatchRequest(batch);
3237
3506
  const res = unsafeRes.map((unsafeRes: any) => {
3238
- const res = create(unsafeRes, GetParsedConfirmedTransactionRpcResult);
3507
+ const res = create(unsafeRes, GetParsedTransactionRpcResult);
3239
3508
  if ('error' in res) {
3240
3509
  throw new Error(
3241
3510
  'failed to get confirmed transactions: ' + res.error.message,
@@ -3666,6 +3935,9 @@ export class Connection {
3666
3935
  const preflightCommitment =
3667
3936
  (options && options.preflightCommitment) || this.commitment;
3668
3937
 
3938
+ if (options && options.maxRetries) {
3939
+ config.maxRetries = options.maxRetries;
3940
+ }
3669
3941
  if (skipPreflight) {
3670
3942
  config.skipPreflight = skipPreflight;
3671
3943
  }
package/src/keypair.ts CHANGED
@@ -1,4 +1,4 @@
1
- import * as nacl from 'tweetnacl';
1
+ import nacl from 'tweetnacl';
2
2
 
3
3
  import {PublicKey} from './publickey';
4
4
 
package/src/publickey.ts CHANGED
@@ -87,6 +87,10 @@ export class PublicKey extends Struct {
87
87
  return bs58.encode(this.toBytes());
88
88
  }
89
89
 
90
+ toJSON(): string {
91
+ return this.toBase58();
92
+ }
93
+
90
94
  /**
91
95
  * Return the byte array representation of the public key
92
96
  */
@@ -1,7 +1,7 @@
1
1
  import {Buffer} from 'buffer';
2
2
  import * as BufferLayout from '@solana/buffer-layout';
3
3
  import secp256k1 from 'secp256k1';
4
- import {keccak_256} from 'js-sha3';
4
+ import sha3 from 'js-sha3';
5
5
 
6
6
  import {PublicKey} from './publickey';
7
7
  import {TransactionInstruction} from './transaction';
@@ -86,9 +86,9 @@ export class Secp256k1Program {
86
86
  );
87
87
 
88
88
  try {
89
- return Buffer.from(keccak_256.update(toBuffer(publicKey)).digest()).slice(
90
- -ETHEREUM_ADDRESS_BYTES,
91
- );
89
+ return Buffer.from(
90
+ sha3.keccak_256.update(toBuffer(publicKey)).digest(),
91
+ ).slice(-ETHEREUM_ADDRESS_BYTES);
92
92
  } catch (error) {
93
93
  throw new Error(`Error constructing Ethereum address: ${error}`);
94
94
  }
@@ -197,7 +197,7 @@ export class Secp256k1Program {
197
197
  const privateKey = toBuffer(pkey);
198
198
  const publicKey = publicKeyCreate(privateKey, false).slice(1); // throw away leading byte
199
199
  const messageHash = Buffer.from(
200
- keccak_256.update(toBuffer(message)).digest(),
200
+ sha3.keccak_256.update(toBuffer(message)).digest(),
201
201
  );
202
202
  const {signature, recid: recoveryId} = ecdsaSign(messageHash, privateKey);
203
203