> ## Documentation Index
> Fetch the complete documentation index at: https://docs.dynamic.xyz/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Estimate Gas

> [card] Recommended: JavaScript SDK for React Native
>
> While this SDK is still supported, we recommend using newer [JavaScript SDK](https://docs.dynamic.xyz/docs/javascript/reference/react-native-quickstart.md), which is optimized for React Native, but also comes with a host of other benefits.

Before sending a transaction, you can use the public client to estimate the gas
fees. Some chains also support custom gas estimation methods.

Here are examples of how to get a gas estimate using viem:

## Estimate Gas Function

> [tab] General
>
> ```tsx theme={"system"}
> import { mainnet } from 'viem/chains';
> import { toHex, parseEther } from 'viem';
> import { dynamicClient } from './dynamicClient';
>
> const estimateGas = async () => {
>   const publicClient = await dynamicClient.viem.createPublicClient({
>     chain: mainnet,
>   });
>
>   const estimate = await publicClient.estimateGas({
>     from: dynamicClient.wallets.primary.address as `0x${string}`,
>     to: '0x123' as `0x${string}`,
>     value: toHex(parseEther('0.001')),
>   })
>
>   console.log(estimate);
> }
> ```

> [tab] Linea
>
> ```tsx theme={"system"}
> import { linea } from 'viem/chains';
> import { toHex, parseEther } from 'viem';
> import { dynamicClient } from './dynamicClient';
>
> const estimateGas = async () => {
>   const publicClient = await dynamicClient.viem.createPublicClient({
>     chain: linea,
>   });
>
>   const estimate = await publicClient.estimateGas({
>     from: dynamicClient.wallets.primary.address as `0x${string}`,
>     to: '0x123' as `0x${string}`,
>     value: toHex(parseEther('0.001')),
>   })
>
>   console.log(estimate);
> }
> ```


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.