You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用Solscan API获取SPL代币元数据时代码报错排查

问题排查与修复

你的代码核心错误出在请求头的token字段写法上:

  • 代码里的"token": {apiKEY}是错误语法,若API密钥存在变量apiKEY中,需直接使用变量名;若直接写入密钥字符串,要用引号包裹。

修正后的代码示例

场景1:API密钥存于变量apiKEY

const data = await fetch(`https://pro-api.solscan.io/v1.0/nft/token/info/${tokenAddress}`, {
  headers: {
    "accept": "application/json",
    "token": apiKEY // 直接使用变量,无需大括号
  }
});

场景2:直接写入API密钥字符串

const data = await fetch(`https://pro-api.solscan.io/v1.0/nft/token/info/${tokenAddress}`, {
  headers: {
    "accept": "application/json",
    "token": "你的实际API密钥内容" // 用引号包裹密钥字符串
  }
});

额外验证项

  • 确认Solscan后台的API密钥已激活,无过期或权限限制
  • 检查tokenAddress是有效的Solana代币铸币地址,格式无误

内容的提问来源于stack exchange,提问作者Alchemist

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.27 12:13:10