我想使用Metaplex SDK与react创建一个NFT。但是当我执行这个函数时,它会抛出以下错误:
AccountNotFoundError:
The account of type [MintAccount] was not found at the provided address
[7SYH47nGcK5fnMmf6zoW75BWpdxDAyq8DBRbagMdsPKJ].
这是我要执行的函数:
async function mint() {
const links = await uploadMetadata();
console.log("Cover: " + links.cover);
console.log("Text: " + links.text);
console.log("Metadata: " + links.metadata);
const { nft } = await metaplex.nfts().create({
uri: links.metadata,
name: title,
sellerFeeBasisPoints: 500, // Represents 5.00%.
});
console.log(nft);
}```
这是一个元plex SDK错误。
问题是metaplex sdk在写入solana后试图读取。这样做的问题显然是,这些更改尚未在整个供应链中传播。
要解决这个问题,请添加可选的承诺参数{ commitment: "finalized" }
你的代码现在看起来像这样
async function mint() {
const links = await uploadMetadata();
console.log("Cover: " + links.cover);
console.log("Text: " + links.text);
console.log("Metadata: " + links.metadata);
const { nft } = await metaplex.nfts().create(
{
uri: links.metadata,
name: title,
sellerFeeBasisPoints: 500, // Represents 5.00%.
},
{ commitment: "finalized" }
);
console.log(nft);
}
我解决问题的方法这是不直接使用nfts().create({})
这样的方法;相反,可以将它们与事务构建器模块一起使用。
所以这个例子看起来像这样:
const createNftBuilder = await metaplex.nfts().builders().create({
uri: links.metadata,
name: title,
sellerFeeBasisPoints: 500, // Represents 5.00%.
});
// Get the data that you don't know in advance from getContext()
const { mintAddress } = transactionBuilder.getContext();
// Submit the tx
await metaplex
.rpc()
.sendAndConfirmTransaction(createNftBuilder, { commitment: "confirmed" });
这样,SDK就不会过早地获取链上数据。问题是,你最终写了很多代码,你不能得到nft
对象在相同的方式与上面。
这对我有用:
const transactionBuilder = await metaplex.nfts().builders().create({ ... });
const { mintAddress } = transactionBuilder.getContext();
await metaplex.rpc().sendAndConfirmTransaction(transactionBuilder);
// Then, optionally fetch the NFT afterwards after sleeping for 2 seconds. 🤢
await new Promise(resolve => setTimeout(resolve, 2000))
const nft = await metaplex.nfts().findByMint({ mintAddress });
从https://github.com/metaplex-foundation/js/issues/344# issuecomment - 1325265657