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

feat: allow passing gasPrice to getTransactionCost #3608

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

danielbate
Copy link
Member

@danielbate danielbate commented Jan 22, 2025

Release notes

In this release, we:

  • Allowed passing gasPrice to getTransactionCost functions to reduce possible network calls

Summary

In the Fuel Wallet, a user can set a custom gas limit or tip for a transaction. It then checks if that changes the fee. If it has, it will re-estimate and fund the transaction.

This leads to two gas price fetches. One in the initial fee calculation, and one in the re-estimation.

By allowing the getTransactionCost to take a gasPrice parameter, we can reduce the number of network calls for this flow.

The expected flow could then look like so:

// Some user input that could change the fee
const tip = userInput.tip;
transactionRequest.tip = tip;

// Calculate the new fee, also fetches and returns the gas price
const { maxFee, gasPrice } = await provider.estimateTxGasAndFee({
    transactionRequest,
});

// Check if the fee has increased and if so, re-estimate and re-fund
if (maxFee.gt(transactionRequest.maxFee)) {
    const cost = await wallet.getTransactionCost(proposedTxRequest, {
        estimateTxDependencies: true,
        gasPrice, // passing this means we will not fetch gas price again
    });
    await wallet.fund(proposedTxRequest, { cost });
}

Checklist

  • All changes are covered by tests (or not applicable)
  • All changes are documented (or not applicable)
  • I reviewed the entire PR myself (preferably, on GH UI)
  • I described all Breaking Changes (or there's none)

@danielbate danielbate added the feat Issue is a feature label Jan 22, 2025
@danielbate danielbate self-assigned this Jan 22, 2025
Copy link

vercel bot commented Jan 22, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
fuels-template ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jan 22, 2025 0:26am
ts-docs ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jan 22, 2025 0:26am
ts-docs-api ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jan 22, 2025 0:26am

Copy link
Contributor

Coverage Report:

Lines Branches Functions Statements
77.05%(+0.01%) 70.65%(+0.01%) 75.1%(+0%) 77.05%(+0.01%)
Changed Files:
Ok File (✨=New File) Lines Branches Functions Statements
🔴 packages/account/src/providers/provider.ts 68.46%
(-0.09%)
59%
(+0.54%)
69.89%
(+0%)
68.2%
(-0.08%)

Comment on lines +1002 to +1003
transactionRequest: TransactionRequest,
{ gasPrice: gasPriceParam }: EstimateTxDependenciesParams = {}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thoughts on breaking change and having a single object parameter?

@danielbate danielbate marked this pull request as ready for review January 22, 2025 17:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feat Issue is a feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant