[英]Getting ERC20 token prices using Moralis
After calling:调用后:
async function getPrice() {
fetch(
"https://deep-index.moralis.io/api/token/ERC20/0xe53ec727dbdeb9e2d5456c3be40cff031ab40a55/price?chain=eth&chain_name=mainnet",
{
method: "GET",
headers: {
"X-API-KEY":
"apiKey",
},
}
)
.then((res) => res)
.then((data) => console.log(data));
}
getPrice();
I'm getting a success Response object like this我得到了一个像这样的成功响应对象
Response {type: "cors", url: "https://deep-index.moralis.io/api/token/ERC20/0xe5…0cff031ab40a55/price?chain=eth&chain_name=mainnet", redirected: false, status: 200, ok: true, …}
how can i now retrieve the token price then?那么我现在如何检索代币价格?
I have modified your code a bit.我稍微修改了你的代码。
async function getPrice() {
return fetch(
"https://deep-index.moralis.io/api/token/ERC20/0xe53ec727dbdeb9e2d5456c3be40cff031ab40a55/price?chain=eth&chain_name=mainnet",
{
method: "GET",
headers: {
accept: "*/*",
"X-API-KEY":
"xxxxxxxxxxxxxxxxxxxxx"
}
}
).then((response) => {
return response.json();
});
}
Then you can call this function: const tokenPriceInfo = getPrice();
然后你可以调用这个函数: const tokenPriceInfo = getPrice();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.