Skip to content

useGasEstimate hook#569

Merged
Agilulfo1820 merged 5 commits into
mainfrom
mike/gas-estimation-hook
Dec 22, 2025
Merged

useGasEstimate hook#569
Agilulfo1820 merged 5 commits into
mainfrom
mike/gas-estimation-hook

Conversation

@mikeredmond

@mikeredmond mikeredmond commented Dec 22, 2025

Copy link
Copy Markdown
Contributor

renaming to use this for estimating gas, have tried it out for veworld and smart account txs.

Closes #466

Summary by CodeRabbit

  • Refactor
    • Gas estimation hook has been renamed for improved consistency with library naming conventions.
    • Updated gas estimation function invocation to include additional configuration options for enhanced flexibility in transaction handling.

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai

coderabbitai Bot commented Dec 22, 2025

Copy link
Copy Markdown

Warning

Rate limit exceeded

@Agilulfo1820 has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 10 minutes and 22 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between 74ab58d and d3cffe4.

📒 Files selected for processing (1)
  • packages/vechain-kit/src/hooks/thor/transactions/useSendTransaction.ts

Walkthrough

Renames the gas estimation function from estimateTxGas to useGasEstimate, updates its export in the transactions index file, and modifies the useSendTransaction hook to import and invoke the renamed function with adjusted parameters including signer account address and options object.

Changes

Cohort / File(s) Summary
Gas estimation function rename
packages/vechain-kit/src/hooks/thor/transactions/useGasEstimate.ts
Renames exported function estimateTxGas to useGasEstimate with no changes to parameters or control flow
Transaction hooks export and integration
packages/vechain-kit/src/hooks/thor/transactions/index.ts, packages/vechain-kit/src/hooks/thor/transactions/useSendTransaction.ts
Adds re-export of useGasEstimate in index file; updates useSendTransaction to import and call renamed function with signerAccountAddress and options object (revision NEXT, optional gasPadding); adds requestTransaction to dependency array

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

  • Verify all references to estimateTxGas have been updated to useGasEstimate
  • Confirm the new parameter structure (signerAccountAddress and options object) aligns with the function's implementation
  • Ensure dependency array updates in useSendTransaction are complete and correct

Possibly related PRs

Suggested reviewers

  • Vombato
  • victorkl400

Poem

🐰 A gas hook renamed with care,
From estimateTxGas to the new affair,
useGasEstimate now takes its place,
With padding and revision at a better pace,
Exports aligned, dependencies true—
A refactor complete, all shiny and new! ✨

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title 'useGasEstimate hook' accurately describes the main change: renaming/introducing a hook with this name. It's concise and clearly indicates the primary modification.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
packages/vechain-kit/src/hooks/thor/transactions/useGasEstimate.ts (1)

4-12: Critical: Rename to remove "use" prefix - this is not a React hook.

The function is named useGasEstimate but it's actually a plain async utility function, not a React hook. In React, the "use" prefix is reserved for hooks that use other React hooks internally and follow the Rules of Hooks. This function:

  • Returns a Promise<number>, not hook state
  • Uses no React hooks internally
  • Is meant to be called inside callbacks/async functions

This naming violation:

  • Triggers false-positive static analysis errors (see Biome warning on line 156 in useSendTransaction.ts)
  • Confuses developers about proper usage patterns
  • Violates React naming conventions
🔎 Proposed fix: Rename to follow proper conventions
-export const useGasEstimate = async (
+export const estimateGas = async (
     thor: ThorClient,
     clauses: TransactionClause[],
     caller: string,
     options?: {
         revision?: Revision;
         gasPadding?: number;
     },
 ) => {

You'll also need to update the import in useSendTransaction.ts and the export in index.ts.

📜 Review details

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 5d98ffd and 74ab58d.

📒 Files selected for processing (3)
  • packages/vechain-kit/src/hooks/thor/transactions/index.ts
  • packages/vechain-kit/src/hooks/thor/transactions/useGasEstimate.ts
  • packages/vechain-kit/src/hooks/thor/transactions/useSendTransaction.ts
🧰 Additional context used
📓 Path-based instructions (1)
**/*.{ts,tsx}

📄 CodeRabbit inference engine (.cursor/rules/migration-guide-to-v2.mdc)

**/*.{ts,tsx}: In VeChain Kit Version 2, use useThor instead of useConnex for contract interactions
For single contract read operations, use the useCallClause hook with the pattern: import dependencies, define ABI and method as const, create query key function using getCallClauseQueryKeyWithArgs, and wrap with useCallClause including data transformation in the select option
For multiple parallel contract calls, use the executeMultipleClausesCall utility wrapped in a useQuery hook with the pattern: define query key function, use executeMultipleClausesCall in queryFn mapping items to clause objects, and transform results
For transaction building and sending, use the useBuildTransaction hook with a clauseBuilder function that returns an array of clauses with optional comment fields describing the transaction action
Always provide an arguments array for contract calls, even when no parameters are required - use an empty array for parameter-less functions to enable TypeScript type checking
Always conditionally enable queries using the enabled property to prevent unnecessary contract calls, checking for all required parameters: enabled: !!requiredParam && !!otherRequiredParam
Use the select option in useCallClause or transform data in queryFn to handle data transformation, particularly for converting BigInt values to strings and normalizing contract return data
Maintain consistent query key patterns: use getCallClauseQueryKeyWithArgs for contract calls with arguments and getCallClauseQueryKey for calls without arguments to ensure proper caching and invalidation
Use TypeScript as const assertions for method names and as 0x${string}`` assertions for Ethereum addresses to ensure type safety in contract interactions

Files:

  • packages/vechain-kit/src/hooks/thor/transactions/index.ts
  • packages/vechain-kit/src/hooks/thor/transactions/useSendTransaction.ts
  • packages/vechain-kit/src/hooks/thor/transactions/useGasEstimate.ts
🧠 Learnings (3)
📚 Learning: 2025-12-01T13:01:33.771Z
Learnt from: CR
Repo: vechain/vechain-kit PR: 0
File: .cursor/rules/migration-guide-to-v2.mdc:0-0
Timestamp: 2025-12-01T13:01:33.771Z
Learning: Applies to **/*.{ts,tsx} : In VeChain Kit Version 2, use `useThor` instead of `useConnex` for contract interactions

Applied to files:

  • packages/vechain-kit/src/hooks/thor/transactions/index.ts
  • packages/vechain-kit/src/hooks/thor/transactions/useSendTransaction.ts
  • packages/vechain-kit/src/hooks/thor/transactions/useGasEstimate.ts
📚 Learning: 2025-12-01T13:01:33.771Z
Learnt from: CR
Repo: vechain/vechain-kit PR: 0
File: .cursor/rules/migration-guide-to-v2.mdc:0-0
Timestamp: 2025-12-01T13:01:33.771Z
Learning: Applies to **/*.{ts,tsx} : For transaction building and sending, use the `useBuildTransaction` hook with a clauseBuilder function that returns an array of clauses with optional comment fields describing the transaction action

Applied to files:

  • packages/vechain-kit/src/hooks/thor/transactions/useSendTransaction.ts
  • packages/vechain-kit/src/hooks/thor/transactions/useGasEstimate.ts
📚 Learning: 2025-12-01T13:01:33.771Z
Learnt from: CR
Repo: vechain/vechain-kit PR: 0
File: .cursor/rules/migration-guide-to-v2.mdc:0-0
Timestamp: 2025-12-01T13:01:33.771Z
Learning: Applies to **/*.{ts,tsx} : For single contract read operations, use the `useCallClause` hook with the pattern: import dependencies, define ABI and method as const, create query key function using `getCallClauseQueryKeyWithArgs`, and wrap with useCallClause including data transformation in the select option

Applied to files:

  • packages/vechain-kit/src/hooks/thor/transactions/useGasEstimate.ts
🧬 Code graph analysis (1)
packages/vechain-kit/src/hooks/thor/transactions/useSendTransaction.ts (1)
packages/vechain-kit/src/hooks/thor/transactions/useGasEstimate.ts (1)
  • useGasEstimate (4-28)
🪛 Biome (2.1.2)
packages/vechain-kit/src/hooks/thor/transactions/useSendTransaction.ts

[error] 156-157: This hook is being called conditionally, but all hooks must be called in the exact same order in every component render.

For React to preserve state between calls, hooks needs to be called unconditionally and always in the same order.
See https://reactjs.org/docs/hooks-rules.html#only-call-hooks-at-the-top-level

(lint/correctness/useHookAtTopLevel)

⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (4)
  • GitHub Check: Lint & Build
  • GitHub Check: e2e-test
  • GitHub Check: build-size-check
  • GitHub Check: deploy
🔇 Additional comments (2)
packages/vechain-kit/src/hooks/thor/transactions/useSendTransaction.ts (2)

156-164: Static analysis error is caused by misleading function name.

The Biome linter correctly flags this as calling a hook conditionally, but this is a false positive caused by the naming of useGasEstimate. The function is not actually a React hook—it's a plain async utility function. Once renamed (see comment on useGasEstimate.ts), this static analysis error will resolve.

The actual usage pattern here is correct for an async utility function: proper try-catch error handling and appropriate parameter passing.


195-195: Good addition to dependency array.

Adding requestTransaction to the dependency array is correct since it's used in the callback at line 169. This ensures the callback is recreated when requestTransaction changes.

@github-actions

github-actions Bot commented Dec 22, 2025

Copy link
Copy Markdown
Contributor

Size Change: +926 B (+0.02%)

Total Size: 5.74 MB

Filename Size Change
packages/vechain-kit/dist/index-BSnj7JHh.d.mts 0 B -150 kB (removed) 🏆
packages/vechain-kit/dist/index-BSnj7JHh.d.mts.map 0 B -43.7 kB (removed) 🏆
packages/vechain-kit/dist/index-BvXcZ0Kc.d.cts 0 B -150 kB (removed) 🏆
packages/vechain-kit/dist/index-BvXcZ0Kc.d.cts.map 0 B -43.7 kB (removed) 🏆
packages/vechain-kit/dist/index-C8Uj8ple.d.cts 0 B -5.63 kB (removed) 🏆
packages/vechain-kit/dist/index-C8Uj8ple.d.cts.map 0 B -2.99 kB (removed) 🏆
packages/vechain-kit/dist/index-BuyXDAs9.d.mts 151 kB +151 kB (new file) 🆕
packages/vechain-kit/dist/index-BuyXDAs9.d.mts.map 43.8 kB +43.8 kB (new file) 🆕
packages/vechain-kit/dist/index-DSMUkHcK.d.cts 5.63 kB +5.63 kB (new file) 🆕
packages/vechain-kit/dist/index-DSMUkHcK.d.cts.map 2.99 kB +2.99 kB (new file) 🆕
packages/vechain-kit/dist/index-uKfnc_S6.d.cts 150 kB +150 kB (new file) 🆕
packages/vechain-kit/dist/index-uKfnc_S6.d.cts.map 43.8 kB +43.8 kB (new file) 🆕
ℹ️ View Unchanged
Filename Size Change
packages/vechain-kit/dist/assets 4.1 kB 0 B
packages/vechain-kit/dist/assets-aAdDxPJu.mjs 50.1 kB 0 B
packages/vechain-kit/dist/assets-aAdDxPJu.mjs.map 70.2 kB 0 B
packages/vechain-kit/dist/assets-DXVXPy3w.cjs 54.8 kB 0 B
packages/vechain-kit/dist/assets-DXVXPy3w.cjs.map 71.6 kB 0 B
packages/vechain-kit/dist/assets/index.cjs 716 B 0 B
packages/vechain-kit/dist/assets/index.d.cts 973 B 0 B
packages/vechain-kit/dist/assets/index.d.mts 973 B 0 B
packages/vechain-kit/dist/assets/index.mjs 718 B 0 B
packages/vechain-kit/dist/index--hSO7Xv4.d.mts 5.63 kB 0 B
packages/vechain-kit/dist/index--hSO7Xv4.d.mts.map 2.99 kB 0 B
packages/vechain-kit/dist/index.cjs 611 kB +28 B (0%)
packages/vechain-kit/dist/index.cjs.map 1.86 MB +37 B (0%)
packages/vechain-kit/dist/index.d.cts 20.5 kB +38 B (+0.19%)
packages/vechain-kit/dist/index.d.mts 20.5 kB +38 B (+0.19%)
packages/vechain-kit/dist/index.mjs 577 kB +23 B (0%)
packages/vechain-kit/dist/index.mjs.map 1.81 MB +37 B (0%)
packages/vechain-kit/dist/utils 4.1 kB 0 B
packages/vechain-kit/dist/utils-Bl-JeVTg.cjs 26.2 kB 0 B
packages/vechain-kit/dist/utils-Bl-JeVTg.cjs.map 63 kB 0 B
packages/vechain-kit/dist/utils-DAs6kMGs.mjs 21.1 kB 0 B
packages/vechain-kit/dist/utils-DAs6kMGs.mjs.map 62.7 kB 0 B
packages/vechain-kit/dist/utils/index.cjs 1.91 kB 0 B
packages/vechain-kit/dist/utils/index.d.cts 2.94 kB 0 B
packages/vechain-kit/dist/utils/index.d.mts 2.94 kB 0 B
packages/vechain-kit/dist/utils/index.mjs 1.93 kB 0 B

compressed-size-action

@Agilulfo1820 Agilulfo1820 merged commit 6a82e74 into main Dec 22, 2025
8 checks passed
@Agilulfo1820 Agilulfo1820 deleted the mike/gas-estimation-hook branch December 22, 2025 15:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

💡 [REQUEST] - add VTHO Fee Estimator Helper

2 participants