Skip to content
This repository was archived by the owner on Mar 6, 2025. It is now read-only.

feat: add simulation step on execute #19

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 1 addition & 1 deletion components/CreateTransactionButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ const CreateTransaction = ({
),
}),
],
payerKey: vaultAddress,
payerKey: wallet.publicKey as PublicKey,
recentBlockhash: (await connection.getLatestBlockhash()).blockhash,
});

Expand Down
15 changes: 13 additions & 2 deletions components/ExecuteButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -127,10 +127,10 @@ const ExecuteButton = ({
}

const priorityFeeInstruction = ComputeBudgetProgram.setComputeUnitPrice({
microLamports: priorityFeeLamports,
microLamports: priorityFeeLamports > 0 ? priorityFeeLamports : 1,
});
const computeUnitInstruction = ComputeBudgetProgram.setComputeUnitLimit({
units: computeUnitBudget,
units: computeUnitBudget > 0 ? computeUnitBudget : 200_000,
});

let blockhash = (await connection.getLatestBlockhash()).blockhash;
Expand All @@ -147,6 +147,17 @@ const ExecuteButton = ({

const execTx = new VersionedTransaction(executeMessage);

try {
const { value } = await connection.simulateTransaction(execTx, {
commitment: "confirmed",
sigVerify: false,
});

console.info("Simulation result:", value);
} catch (error) {
console.error(error);
}

const signature = await wallet.sendTransaction(execTx, connection, {
skipPreflight: true,
});
Expand Down