首页 > 解决方案 > Solana Web3.js:获取 Mint 帐户的“null”,尽管它应该返回一个“AccountInfo”对象

问题描述

当我运行时,connection.getAccountInfo(watermelonMint.key);我得到一个null对象,尽管它应该返回一个AccountInfoObject. 知道为什么会这样吗?当我在 solana explorer 上查找与此铸币厂相关的地址时,我得到了正常的统计数据(https://explorer.solana.com/address/7vLEZP5JHhKVg3HEGSWcFNaxAKg7L633uMT7ePqmn98V?cluster=devnet

console.log("Watermelon mint is: ");
console.log(watermelonMint);

返回

Mint {conn: Connection, key: PublicKey}
conn: Connection {_commitment: undefined, _confirmTransactionInitialTimeout: undefined, _rpcEndpoint: 'https://api.devnet.solana.com', _rpcWsEndpoint: 'wss://api.devnet.solana.com/', _rpcClient: ClientBrowser, …}
key: PublicKey
_bn: BN {negative: 0, words: Array(11), length: 10, red: null}
[[Prototype]]: Struct
[[Prototype]]: Object

知道是什么原因造成的吗?


更新1:

基本上,Token.getMintInfo();一直失败

const token = new Token(conn, mint, TOKEN_PROGRAM_ID, {} as any)
  console.log("Getting token: ", token);
  let out: Promise<MintInfo> = token.getMintInfo();
  console.log("Out is: ", out);

标签: web3web3jssolana

解决方案


最有可能的是,mint在“更新 1”中不正确,或者您的连接在某处未正确定义。您可以仔细检查mint是否等于PublicKey("7vLEZP5JHhKVg3HEGSWcFNaxAKg7L633uMT7ePqmn98V")

另外,你能确定await来自的回应token.getMintInfo()吗?


推荐阅读