CRYPTO NEWS

How to convert USD to ETH?

I have created a simple CodeSandbox project to convert ETH to USD. however now I want to convert USD to ETH also. I think it seems to be there is an issue in my USD to ETH logic. It gives me the wrong output. Can anyone give me the correct logic it will help me to understand what happened in my code?

I’m using Coinbase Digital Currency API

Coinbase converter

api.js file

export const GetUSDExchangeRate = async () => {   var requestOptions = { method: "GET", redirect: "follow" };   return fetch("https://api.coinbase.com/v2/exchange-rates?currency=ETH", requestOptions)     .then((response) => response.json())     .then((result) => {return(result.data.rates.USD)})     .catch((error) => {return("error", error)}); }  export const GetETHExchangeRate = async () => {   var requestOptions = { method: "GET", redirect: "follow" };   return fetch("https://api.coinbase.com/v2/exchange-rates?currency=USD", requestOptions)     .then((response) => response.json())     .then((result) => {return(result.data.rates.ETH)})     .catch((error) => {return("error", error)}); } 

ETH to USD covert part

<Grid item xs={12} sm={12} md={12} lg={12}>   {(ethPrice * usdExRate).toFixed(2)} USD </Grid> 

USD to ETH part

<Grid item xs={12} sm={12} md={12} lg={12}>   {(usdPrice / ethExRate).toFixed(2)} ETH </Grid> 

Here is my full code part I had done.

Edit converter

How to convert USD to ETH?

Shopping cart
There are no products in the cart!
Continue shopping
0