Skip to main content

Fetch Ethereum price

fetches current Ethereum price.

Import fetchEthPrice with const { fetchEthPrice } = MetastaqInstance and call it as follows to get the required data.

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

export const ShowEthPrice = () => {
const { fetchEthPrice } = MetastaqInstance;

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

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

The method fetchEthPrice 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 gives 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.