繁体   English   中英

使用 Moralis 获取 ERC20 代币价格

[英]Getting ERC20 token prices using Moralis

调用后:


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();

我得到了一个像这样的成功响应对象

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, …} 

那么我现在如何检索代币价格?

我稍微修改了你的代码。

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();
            });
          }

然后你可以调用这个函数: const tokenPriceInfo = getPrice();

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM