From fa35267d55649d7d4244e82a0c98e1988baeb34f Mon Sep 17 00:00:00 2001 From: Joaquim Verges Date: Tue, 20 Sep 2022 15:36:28 -0700 Subject: [PATCH 1/2] catch gas estimate errors in gasless tx --- packages/sdk/src/core/classes/contract-wrapper.ts | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/packages/sdk/src/core/classes/contract-wrapper.ts b/packages/sdk/src/core/classes/contract-wrapper.ts index 61db4d58ead..db343f7c475 100644 --- a/packages/sdk/src/core/classes/contract-wrapper.ts +++ b/packages/sdk/src/core/classes/contract-wrapper.ts @@ -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); } From f7b82a85d22df97cc366c1a5595e5fd23947775d Mon Sep 17 00:00:00 2001 From: Joaquim Verges Date: Tue, 20 Sep 2022 15:37:31 -0700 Subject: [PATCH 2/2] add changeset --- .changeset/poor-news-compete.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/poor-news-compete.md diff --git a/.changeset/poor-news-compete.md b/.changeset/poor-news-compete.md new file mode 100644 index 00000000000..b4f145279a6 --- /dev/null +++ b/.changeset/poor-news-compete.md @@ -0,0 +1,5 @@ +--- +"@thirdweb-dev/sdk": patch +--- + +Catch gas estimate errors in gasless tx