Skip to main content

Fetch Gas price

fetches current Gas price.

Import fetchGasPrice with const { fetchGasPrice } = MetastaqInstance and call it as described below to get the required data.

fetchGasPrice
import React from "react";
import { MetastaqInstance } from "./MetastaqInstance";

export const ShowGasPrice = () => {
const { fetchGasPrice } = MetastaqInstance;

const { status, data, error, isFetching, isLoading, refetch } =
fetchGasPrice();

return (
<button
onClick={() => {
refetch();
}}
>
refetch Eth Price
</button>
);
};

The fetchGasPrice method returns status, data, error, isFetching, isLoading, refetch, where data is the required data, status tells you the success or failure status of the response, error tells you the error message, isFetching and isLoading are Boolean values that tell you the status, whether the request is still running or not, and the refetch method lets you retrieve the response again if you want to update the status when you click the button.