I’m trying to fetch the prices from coingecko API it’s returning object json response how can I get that response value and assign it to const rate directly to my calculation here the below code I’m try to achieve
fetch(`https://api.coingecko.com/api/v3/simple/price?ids=${give}&vs_currencies=${get}`)
.then(res => res.json())
.then((data) => {
console.log(data.responseText)
const rate = data.responseText;
rateE1.innerText = `1 ${give} = ${rate} ${get}`
get_qty_enter.value = (give_qty_enter.value * rate).toFixed(5);
})
.catch(err => console.error(err));
2
Answers
What error are you getting?
You can process the data according to the field names in the incoming reply;
You should cultivate reading the documentation while you are exploring the new tech.
here i wrote an example for doge to usd.
HTML
JS
Read these two sections carefully on this link.
https://www.coingecko.com/en/api/documentation
/simple/price
/simple/supported_vs_currencies
/coins/list