Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/poor-news-compete.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@thirdweb-dev/sdk": patch
---

Catch gas estimate errors in gasless tx
15 changes: 10 additions & 5 deletions packages/sdk/src/core/classes/contract-wrapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -434,14 +434,19 @@ export class ContractWrapper<
args as any,
);

const gasEstimate = await (this.writeContract.estimateGas as any)[fn](
...args,
);
let gas = gasEstimate.mul(2);
let gas = BigNumber.from(0);
try {
const gasEstimate = await (this.readContract.estimateGas as any)[fn](
...args,
);
gas = gasEstimate.mul(2);
} catch (e) {
// ignore
}

// in some cases WalletConnect doesn't properly gives an estimate for how much gas it would actually use.
// as a fix, we're setting it to a high arbitrary number (500k) as the gas limit that should cover for most function calls.
if (gasEstimate.lt(50000)) {
if (gas.lt(100000)) {
gas = BigNumber.from(500000);
}

Expand Down