> For the complete documentation index, see [llms.txt](https://docs.cometh.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.cometh.io/integrations/react-hooks/usegetgasprice.md).

# useGetGasPrice

## Description

This hook fetches the current gas price for transactions on the connected blockchain. It leverages a public client to estimate the gas fees and provides both `maxFeePerGas` and `maxPriorityFeePerGas` values.&#x20;

The `maxFeePerGas` is calculated with a buffer, doubling the estimated fee to accommodate potential fluctuations in gas prices.&#x20;

This hook is useful for determining the cost of transactions in real-time.

## Parameters

* **rpcUrl?** (`string`) : An optional RPC URL to use for the public client. If not provided, the default RPC URL associated with the smart account will be used.

## Returns

* **data** (`GasPriceResult | undefined`): The fetched gas price data, containing `maxFeePerGas` and `maxPriorityFeePerGas`.
* **isLoading** (`boolean`): A boolean indicating whether the data is currently being fetched.
* **error** (`Error | null`): An error object if an error occurred during the fetching process, otherwise `null`.

## Example

```tsx
import { useGetGasPrice } from "@cometh/connect-react-hooks";
import { formatEther } from "viem";
 
export const GasPriceDisplay = () => {
 const { data: gasPrice, isLoading, error } = useGetGasPrice();
 
 if (isLoading) return <p>Loading gas prices...</p>;
 if (error) return <p>Error fetching gas prices: {error.message}</p>;
 
 return (
   <div>
     <h2>Current Gas Prices</h2>
     <p>Max Fee Per Gas: {formatEther(gasPrice.maxFeePerGas)} ETH</p>
     <p>Max Priority Fee Per Gas: {formatEther(gasPrice.maxPriorityFeePerGas)} ETH</p>
   </div>
  );
};
```

## Usage context

The `useGetGasPrice` hook must be used within a context that provides access to `useSmartAccount`. This ensures that the `smartAccountClient` and `queryClient` are available, and it avoids errors related to missing context or data.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.cometh.io/integrations/react-hooks/usegetgasprice.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
