Skip to content

Commit 22a8361

Browse files
committed
Fix confirmTransaction function
1 parent 22a3996 commit 22a8361

File tree

4 files changed

+12
-6
lines changed

4 files changed

+12
-6
lines changed

CHANGELOG.md

+7
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
## 2.6
2+
3+
- Added Transaction send helpers. `prepareTransactionWithCompute()` and `sendTransactionWithRetry()`
4+
- Added Transaction Parser helper functions `getIdlParsedAccountData()`, `parseAnchorTransactionEvents()` and `getIdlParsedInstructionData()`
5+
- Fixed `createAccountsMintsAndTokenAccounts()` function to use correct commitment and not `max` blockhash
6+
- Fixed `confirmTransaction()` to not use correct commitment
7+
18
## 2.5
29

310
- Add `makeTokenMint()`

src/lib/token.ts

+2-3
Original file line numberDiff line numberDiff line change
@@ -250,12 +250,11 @@ const makeAndSendAndConfirmTransaction = async (
250250
signers: Array<Signer>,
251251
payer: Keypair,
252252
) => {
253-
const latestBlockhash = (await connection.getLatestBlockhash("max"))
254-
.blockhash;
253+
const latestBlockhash = await connection.getLatestBlockhash("confirmed");
255254

256255
const messageV0 = new TransactionMessage({
257256
payerKey: payer.publicKey,
258-
recentBlockhash: latestBlockhash,
257+
recentBlockhash: latestBlockhash.blockhash,
259258
instructions,
260259
}).compileToV0Message();
261260
const transaction = new VersionedTransaction(messageV0);

src/lib/transaction.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ export const confirmTransaction = async (
3232
signature: string,
3333
commitment: Commitment = "confirmed",
3434
): Promise<string> => {
35-
const block = await connection.getLatestBlockhash();
35+
const block = await connection.getLatestBlockhash(commitment);
3636
const rpcResponse = await connection.confirmTransaction(
3737
{
3838
signature,
@@ -213,7 +213,7 @@ export async function sendTransactionWithRetry(
213213
let status: SignatureStatus | null = null;
214214
let retries = 0;
215215
// Setting a minimum to decrease spam and for the confirmation to work
216-
let delayBetweenRetries = Math.max(initialDelayMs, 500);
216+
let delayBetweenRetries = Math.max(initialDelayMs, 500);
217217

218218
while (retries < maxRetries) {
219219
try {

tests/src/token.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ describe("makeTokenMint", () => {
7272
describe("createAccountsMintsAndTokenAccounts", () => {
7373
test("createAccountsMintsAndTokenAccounts works", async () => {
7474
const payer = Keypair.generate();
75-
const connection = new Connection(LOCALHOST);
75+
const connection = new Connection(LOCALHOST, "confirmed");
7676
await airdropIfRequired(
7777
connection,
7878
payer.publicKey,

0 commit comments

Comments
 (0)