CodingYourLife

CodingYourLife

 

Referenzen

 
 

EUR<->ETH Exchange Rates von Coinbase via API

let getExchangeRates = async () => {
    const filename = 'exchangeRates.json'
    let result = null
    let exchangeRatesUrl = "https://api.coinbase.com/v1/currencies/exchange_rates"
    try {
        const response = await axios.get(exchangeRatesUrl)
        result = response.data
    } catch (error) {
        console.error(error);
        throw new Error(error)
    }

    return result
}

Use it like this:

const exchangeRates = await getExchangeRates()
const eth_to_eur = exchangeRates.eth_to_eur
const eur_to_eth = exchangeRates.eur_to_eth
console.log("eth_to_eur: " + eth_to_eur)
console.log("eur_to_eth: " + eur_to_eth)
console.log("example in wei:" (eth_to_eur * 1e18))

Kommentar schreiben

Kommentar