From 3f12ff5828a7df134deea93465ef8efd55556d4d Mon Sep 17 00:00:00 2001 From: franm Date: Tue, 5 Nov 2024 13:55:40 -0300 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20gasEstimation:=20add=20try=20cat?= =?UTF-8?q?ch=20in=20gas=20estimation?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- hooks/useEstimateGas.ts | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/hooks/useEstimateGas.ts b/hooks/useEstimateGas.ts index afa64841a..ce356984d 100644 --- a/hooks/useEstimateGas.ts +++ b/hooks/useEstimateGas.ts @@ -13,20 +13,28 @@ export default function useEstimateGas() { async (request?: EstimateContractGasParameters) => { if (!publicClient) return; + const DEFAULT_L1_GAS = 555_555_555_555n; + let l1Gas = 0n; if (chain.id === optimism.id) { if (request) { const data = encodeFunctionData(request); - l1Gas = await publicClient.readContract({ - abi: l1GasPriceOracleABI, - address: '0x420000000000000000000000000000000000000F', - functionName: 'getL1Fee', - args: [data], - }); + + try { + l1Gas = await publicClient.readContract({ + abi: l1GasPriceOracleABI, + address: '0x420000000000000000000000000000000000000F', + functionName: 'getL1Fee', + args: [data], + }); + } catch (l1FeeError) { + l1Gas = DEFAULT_L1_GAS; + } } else { - l1Gas = 555_555_555_555n; + l1Gas = DEFAULT_L1_GAS; } } + const gasPrice = await publicClient.getGasPrice(); const gasUsed = request ? await publicClient.estimateContractGas(request) : 500_000n;