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!: autoCost for transaction estimation and funding #3539

Merged
merged 3 commits into from
Jan 4, 2025

Conversation

danielbate
Copy link
Member

@danielbate danielbate commented Jan 3, 2025

Release notes

In this release, we:

  • Added the autoCost method to easily estimate and fund transactions
  • Migrated fundWithRequiredCoins -> autoCost for contract and script calls

Summary

Added a helper method to the ScriptTransactionRequest to easily estimate and fund a transaction. This allows consumers to easily bundle transactions before submission. This will form part of the optimisation docs in #3535.

// before
const txCost = await wallet.getTransactionCost(request);
request.gasLimit = txCost.gasUsed;
request.maxFee = txCost.maxFee;
await wallet.fund(request, txCost);

// after
await request.autoCost(wallet);

Breaking Changes

To be brought inline with autoCost, funding a contract and script call has been migrated from fundWithRequiredCoins to autoCost:

// before
const request: ScriptTransactionRequest = contract.functions.add(1).fundWithRequiredCoins();

// after
const request: ScriptTransactionRequest = contract.functions.add(1).autoCost(wallet);

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 3, 2025
@danielbate danielbate self-assigned this Jan 3, 2025
Copy link

vercel bot commented Jan 3, 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 3, 2025 6:00pm
ts-docs ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jan 3, 2025 6:00pm
ts-docs-api ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jan 3, 2025 6:00pm

@danielbate danielbate changed the title feat: add autoCost for script transactions feat: add autoCost for transactions Jan 3, 2025
@danielbate danielbate changed the title feat: add autoCost for transactions feat!: add autoCost for transactions Jan 3, 2025
@danielbate danielbate changed the title feat!: add autoCost for transactions feat!: add autoCost for transaction estimation and funding Jan 3, 2025
@danielbate danielbate changed the title feat!: add autoCost for transaction estimation and funding feat!: autoCost for transaction estimation and funding Jan 3, 2025
Copy link
Contributor

github-actions bot commented Jan 3, 2025

Coverage Report:

Lines Branches Functions Statements
77.79%(+0.01%) 70.46%(+0.02%) 75.38%(+0.01%) 77.75%(+0.01%)
Changed Files:
Ok File (✨=New File) Lines Branches Functions Statements
🔴 packages/account/src/providers/transaction-request/script-transaction-request.ts 50%
(+6.42%)
64.28%
(+5.95%)
42.1%
(+3.22%)
48.88%
(+6.38%)

Copy link
Member

@arboleya arboleya left a comment

Choose a reason for hiding this comment

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

Surgical, minimal footprint. Well done. 🎯

Copy link
Contributor

@nedsalk nedsalk left a comment

Choose a reason for hiding this comment

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

Nice one 👍

@petertonysmith94 petertonysmith94 merged commit 8d8452e into master Jan 4, 2025
54 of 56 checks passed
@petertonysmith94 petertonysmith94 deleted the db/feat/autocost-tx branch January 4, 2025 13:07
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.

Introduce the autoCost helper for transaction requests
4 participants