Skip to content

Commit

Permalink
⛽ Avoid calling estimateGas in useContractFunction when gasLimit is p…
Browse files Browse the repository at this point in the history
…assed explicitly (#1008)
  • Loading branch information
D-Ig committed Oct 31, 2022
1 parent cd47856 commit 14c271f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/spotty-cows-exist.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@usedapp/core": patch
---

⛽ Avoid calling estimateGas in useContractFunction when gasLimit is passed explicitly
10 changes: 8 additions & 2 deletions packages/core/src/hooks/useContractFunction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,14 @@ export function useContractFunction<T extends TypedContract, FN extends Contract
const opts = hasOpts ? args[args.length - 1] : undefined

const gasLimit =
(await estimateContractFunctionGasLimit(contractWithSigner, functionName, args, gasLimitBufferPercentage)) ??
BigNumber.from(0)
typeof opts === 'object' && Object.prototype.hasOwnProperty.call(opts, 'gasLimit')
? opts.gasLimit
: (await estimateContractFunctionGasLimit(
contractWithSigner,
functionName,
args,
gasLimitBufferPercentage
)) ?? BigNumber.from(0)

const modifiedOpts = {
gasLimit,
Expand Down

2 comments on commit 14c271f

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

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

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

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

Please sign in to comment.