Skip to content

Commit

Permalink
🐛 gasEstimation: add try catch in gas estimation
Browse files Browse the repository at this point in the history
  • Loading branch information
franm91 committed Nov 5, 2024
1 parent de6c2a2 commit 3f12ff5
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions hooks/useEstimateGas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down

0 comments on commit 3f12ff5

Please sign in to comment.