@solana/web3.js ERC721元数据有接口吗? [英] @solana/web3.js Is there an API for ERC721 Metadata?
本文介绍了@solana/web3.js ERC721元数据有接口吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
推荐答案
Solana将令牌元数据存储在从原始令牌的地址派生的地址(按照 https://docs.solana.com/developing/programming-model/calling-between-programs#hash-based-generated-program-addresses
参考代码已锈迹斑斑,这里是@solana/web3.js
的实现。
(source)
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`);
}
请注意,元数据按照https://docs.metaplex.com/nft-standard#token-metadata-program使用borsh library以base64编码。
以下是仅使用borsh和@solana/web3.js检索和解析元数据的简明实现 https://gist.github.com/dvcrn/c099c9b5a095ffe4ddb6481c22cde5f4 最后,MagicDen有一个返回元数据的端点: https://api-mainnet.magiceden.io/rpc/getNFTByMintAddress/DugthRKbQZRMcDQQfjnj2HeSjz2VARPC8H9abxdNK2SS这篇关于@solana/web3.js ERC721元数据有接口吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文