给定一个令牌铸币厂地址,我正在寻找一种方法来访问 ERC721 令牌的元数据。@solana/web3.js 中有 API 吗?
3 回答
Solana 根据https://docs.solana.com/developing/programming-model/calling-between-programs#hash-based-generated-program-addresses将令牌元数据存储在从原始令牌地址派生的地址
参考代码已生锈,这是来自@solana/web3.js
.
(来源)
static async findProgramAddress(
seeds: Array<Buffer | Uint8Array>,
programId: PublicKey,
): Promise<[PublicKey, number]> {
let nonce = 255;
let address;
while (nonce != 0) {
try {
const seedsWithNonce = seeds.concat(Buffer.from([nonce]));
address = await this.createProgramAddress(seedsWithNonce, programId);
} catch (err) {
if (err instanceof TypeError) {
throw err;
}
nonce--;
continue;
}
return [address, nonce];
}
throw new Error(`Unable to find a viable program address nonce`);
}
请注意,元数据使用borsh library按照https://docs.metaplex.com/nft-standard#token-metadata-program以 base64 编码。
这是仅使用 borsh 和 @solana/web3.js https://gist.github.com/dvcrn/c099c9b5a095ffe4ddb6481c22cde5f4检索和解析元数据的简洁实现
最后,MagicDen 有一个返回元数据的端点: https ://api-mainnet.magiceden.io/rpc/getNFTByMintAddress/DugthRKbQZRMcDQQfjnj2HeSjz2VARPC8H9abxdNK2SS
不,但可以通过此处的区块链 API 获得一个:https ://docs.theblockchainapi.com/#tag/Solana-NFT/paths/~1v1~1solana~1nft/get
您只需提供 mint_address 并取回元数据。很简单!