Skip to content

Commit

Permalink
feat(berajs): add simple nonce calculation
Browse files Browse the repository at this point in the history
  • Loading branch information
BrownBrownBear committed Dec 23, 2024
1 parent 38f9fa7 commit 10b5153
Showing 1 changed file with 9 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,21 @@ const useBeraContractWrite = ({
dispatch({ type: ActionEnum.LOADING });
onLoading?.();
let receipt: Awaited<ReturnType<typeof sendTransactionAsync>>;
if (!publicClient) return;
if (!publicClient || !account) return;
try {
// Get the next nonce for the account
const nonce = await publicClient.getTransactionCount({
address: account,
blockTag: "pending",
});

if (data) {
receipt = await sendTransactionAsync({
data,
to: address,
value,
gas: gasLimit,
nonce: nonce + 1,
});
} else {
// Run simulation and gas estimation in parallel
Expand Down Expand Up @@ -87,6 +94,7 @@ const useBeraContractWrite = ({
...request,
gas:
increaseByPercentage(wagmiPubEstimateContractGas, 10) ?? gasLimit,
nonce: nonce + 1,
});
}

Expand Down

0 comments on commit 10b5153

Please sign in to comment.