現象
AnchorのテストコードにMetaplexを使ってdevnetでNFTをMintすると以下のエラー。
myanc
1) Is initialized!
0 passing (12s)
1 failing
1) myanc
Is initialized!:
FailedToSendTransactionError: The transaction could not be sent successfully to the network. Please check the underlying error below for more details.
Source: RPC
Caused By: Error: failed to send transaction: Transaction simulation failed: Attempt to debit an account but found no record of a prior credit.
at RpcClient.parseProgramError (node_modules/@metaplex-foundation/js/src/plugins/rpcModule/RpcClient.ts:336:14)
at RpcClient.sendTransaction (node_modules/@metaplex-foundation/js/src/plugins/rpcModule/RpcClient.ts:128:18)
at processTicksAndRejections (node:internal/process/task_queues:96:5)
at RpcClient.sendAndConfirmTransaction (node_modules/@metaplex-foundation/js/src/plugins/rpcModule/RpcClient.ts:164:23)
at TransactionBuilder.sendAndConfirm (node_modules/@metaplex-foundation/js/src/utils/TransactionBuilder.ts:197:22)
at Object.handle (node_modules/@metaplex-foundation/js/src/plugins/nftModule/operations/createNft.ts:296:20)
at Disposable.run (node_modules/@metaplex-foundation/js/src/utils/Disposable.ts:33:14)
tests/myanc.ts
const metaplex = Metaplex.make(connection)
.use(keypairIdentity(wallet))
.use(bundlrStorage({
address: 'https://devnet.bundlr.network',
providerUrl: 'https://api.devnet.solana.com',
timeout: 60000,
}));
const { uri } = await metaplex
.nfts()
.uploadMetadata({
name: "My NFT Metadata",
description: "My description",
image: "https://placekitten.com/200/300",
});
const { nft } = await metaplex
.nfts()
.create({
uri: uri,
name: "My NFT",
sellerFeeBasisPoints: 500, // Represents 5.00%.
maxSupply: toBigNumber(1),
});
原因
Mintに必要なSOL代が足りていないため。
1SOLをエアドロップしていたが、足りなかったらしい。
対応
画像サイズを小さくする(SOL代を少なくする)。
今回は、200x300の画像を20x30にサイズ縮小した。
tests/myanc.ts
const { uri } = await metaplex
.nfts()
.uploadMetadata({
name: "My NFT Metadata",
description: "My description",
image: "https://placekitten.com/20/30", // ← 20x30に変更
});