Skip to content

Commit

Permalink
fix(common): use feeRef for sendTransaction calls (#2725)
Browse files Browse the repository at this point in the history
Kooshaba authored Apr 25, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
1 parent bf16e72 commit 375d902
Showing 2 changed files with 18 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/angry-ties-travel.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@latticexyz/common": patch
---

Added asynchronous polling for current fees to `sendTransaction`.
14 changes: 13 additions & 1 deletion packages/common/src/sendTransaction.ts
Original file line number Diff line number Diff line change
@@ -13,6 +13,7 @@ import pRetry from "p-retry";
import { debug as parentDebug } from "./debug";
import { getNonceManager } from "./getNonceManager";
import { parseAccount } from "viem/accounts";
import { getFeeRef } from "./getFeeRef";

const debug = parentDebug.extend("sendTransaction");

@@ -49,6 +50,7 @@ export async function sendTransaction<
throw new Error("No account provided");
}
const account = parseAccount(rawAccount);
const chain = client.chain;

const nonceManager = await getNonceManager({
client: opts.publicClient ?? client,
@@ -57,6 +59,12 @@ export async function sendTransaction<
queueConcurrency: opts.queueConcurrency,
});

const feeRef = await getFeeRef({
client: opts.publicClient ?? client,
refreshInterval: 10000,
args: { chain },
});

async function prepare(): Promise<SendTransactionParameters<chain, account, chainOverride>> {
if (request.gas) {
debug("gas provided, skipping simulate", request.to);
@@ -85,7 +93,11 @@ export async function sendTransaction<

const nonce = nonceManager.nextNonce();
debug("sending tx with nonce", nonce, "to", preparedRequest.to);
const parameters: SendTransactionParameters<chain, account, chainOverride> = { nonce, ...preparedRequest };
const parameters: SendTransactionParameters<chain, account, chainOverride> = {
...preparedRequest,
nonce,
...feeRef.fees,
};
return await viem_sendTransaction(client, parameters);
},
{

0 comments on commit 375d902

Please sign in to comment.