There is a JavaScript code sample on the getTokenPrice page you can use with axios
(or just use fetch
like in the example below).
After you get the response back from the API, you can set some element to use the value from this response.
// some element in your HTML where you want to display something
<input id="tokenprice" />
...
// in your JavaScript code, swap out address f
async function fetchPrice() {
fetch(
'https://deep-index.moralis.io/api/v2/erc20/0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2/price?chain=eth',
{
headers: { accept: 'application/json', 'X-API-Key': 'test' },
}
)
.then((response) => response.json())
.then((data) => {
console.log('data', data); // find out what data you can use
document.getElementById('tokenprice').value = data.usdPrice; // set value of this input, can use .innerHTML for other elements like <p>
});
}
fetchPrice(); // call somewhere
It would be a good idea to follow a course like this one to learn the fundamentals if you want to be able to fetch data or use APIs like Moralis.