Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

replaced the deprecated getRecentBlockhash with getLatestBlockhash #243

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions core/src/createTransfer.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { createTransferCheckedInstruction, getAccount, getAssociatedTokenAddress, getMint } from '@solana/spl-token';
import type { Commitment, Connection, PublicKey } from '@solana/web3.js';
import type { Commitment, Connection, GetLatestBlockhashConfig, PublicKey } from '@solana/web3.js';
import { LAMPORTS_PER_SOL, SystemProgram, Transaction, TransactionInstruction } from '@solana/web3.js';
import BigNumber from 'bignumber.js';
import { MEMO_PROGRAM_ID, SOL_DECIMALS, TEN } from './constants.js';
Expand Down Expand Up @@ -34,15 +34,15 @@ export interface CreateTransferFields {
* @param connection - A connection to the cluster.
* @param sender - Account that will send the transfer.
* @param fields - Fields of a Solana Pay transfer request URL.
* @param options - Options for `getRecentBlockhash`.
* @param options - Options for `getLatestBlockhash`.
*
* @throws {CreateTransferError}
*/
export async function createTransfer(
connection: Connection,
sender: PublicKey,
{ recipient, amount, splToken, reference, memo }: CreateTransferFields,
{ commitment }: { commitment?: Commitment } = {}
{ commitment }: { commitment?: Commitment | GetLatestBlockhashConfig } = {}
): Promise<Transaction> {
// Check that the sender and recipient accounts exist
const senderInfo = await connection.getAccountInfo(sender);
Expand Down Expand Up @@ -70,7 +70,7 @@ export async function createTransfer(
// Create the transaction
const transaction = new Transaction();
transaction.feePayer = sender;
transaction.recentBlockhash = (await connection.getRecentBlockhash(commitment)).blockhash;
transaction.recentBlockhash = (await connection.getLatestBlockhash(commitment)).blockhash;

// If a memo is provided, add it to the transaction before adding the transfer instruction
if (memo != null) {
Expand Down
10 changes: 5 additions & 5 deletions core/src/fetchTransaction.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { Commitment, Connection, PublicKey } from '@solana/web3.js';
import type { Commitment, Connection, GetLatestBlockhashConfig, PublicKey } from '@solana/web3.js';
import { Transaction } from '@solana/web3.js';
import fetch from 'cross-fetch';
import { toUint8Array } from 'js-base64';
Expand All @@ -17,15 +17,15 @@ export class FetchTransactionError extends Error {
* @param connection - A connection to the cluster.
* @param account - Account that may sign the transaction.
* @param link - `link` in the [Solana Pay spec](https://github.com/solana-labs/solana-pay/blob/master/SPEC.md#link).
* @param options - Options for `getRecentBlockhash`.
* @param options - Options for `getLatestBlockhash`.
*
* @throws {FetchTransactionError}
*/
export async function fetchTransaction(
connection: Connection,
account: PublicKey,
link: string | URL,
{ commitment }: { commitment?: Commitment } = {}
{ commitment }: { commitment?: Commitment | GetLatestBlockhashConfig } = {}
): Promise<Transaction> {
const response = await fetch(String(link), {
method: 'POST',
Expand Down Expand Up @@ -60,7 +60,7 @@ export async function fetchTransaction(
} else if (publicKey.equals(account)) {
// If the only signature expected is for `account`, ignore the recent blockhash in the transaction.
if (signatures.length === 1) {
transaction.recentBlockhash = (await connection.getRecentBlockhash(commitment)).blockhash;
transaction.recentBlockhash = (await connection.getLatestBlockhash(commitment)).blockhash;
}
} else {
throw new FetchTransactionError('missing signature');
Expand All @@ -69,7 +69,7 @@ export async function fetchTransaction(
} else {
// Ignore the fee payer and recent blockhash in the transaction and initialize them.
transaction.feePayer = account;
transaction.recentBlockhash = (await connection.getRecentBlockhash(commitment)).blockhash;
transaction.recentBlockhash = (await connection.getLatestBlockhash(commitment)).blockhash;
}

return transaction;
Expand Down