createMetadataAccountV3 static method
This instruction creates and initializes a new Metadata account for a given Mint account. It is required that the Mint account has been created and initialized by the Token Program before executing this instruction.
Keys:
[w]
metadata
- Metadata key (pda of: 'metadata', program id, mint id).[]
mint
- Mint of token asset.[s]
mintAuthority
- Mint authority.[s, w]
payer
- Fee payer.[]
updateAuthority
- Update authority info.
Data:
-
dataV2
name
- The on-chain name of the token, limited to 32 bytes. For instance "Degen Ape #1 ".symbol
- The on-chain symbol of the token, limited to 10 bytes. For instance "DAPE".uri
- The URI of the token, limited to 200 bytes. This URI points to an off-chain JSON file that contains additional data following a certain standard. You can learn more about this JSON standard here. The JSON file can either be stored in a traditional server (e.g. using AWS) or using a permanent storage solution such as using Arweave.sellerFeeBasisPoints
- The royalties shared by the creators in basis points — i.e. 550 means 5.5%. Whilst this field is used by virtually all NFT marketplaces, it is not enforced by the Token Metadata program itself.creators
- An array of creators and their share of the royalties. This array is limited to 5 creators. Note that, because the Creators field is an array of variable length, we cannot guarantee the byte position of any field that follows.collection
- This field optionally links to the Mint address of another NFT that acts as a Collection NFT.uses
- This field can make NFTs usable. Meaning you can load it with a certain amount of "uses" and use it until it has run out. You can learn more about using NFTs here. -
isMutable
- A boolean indicating if the Metadata Account can be updated. Once flipped to false, it cannot ever be true again. -
collectionDetails
- Allows us to differentiate Collection NFTs from Regular NFTs whilst adding additional context such as the amount of NFTs that are linked to the Collection NFT.
Implementation
static TransactionInstruction createMetadataAccountV3({
// Keys
required final Pubkey metadata,
required final Pubkey mint,
required final Pubkey mintAuthority,
required final Pubkey payer,
required final Pubkey updateAuthority,
// Data
required final DataV2 dataV2,
final bool isMutable = true,
final MetadataCollectionDetails? collectionDetails,
}) {
final List<AccountMeta> keys = [
AccountMeta.writable(metadata),
AccountMeta(mint),
AccountMeta.signer(mintAuthority),
AccountMeta.signerAndWritable(payer),
AccountMeta(updateAuthority),
AccountMeta(SystemProgram.programId),
AccountMeta(sysvarRentPubkey),
];
final List<Iterable<u8>> data = [
metadataNameCodec.encode(dataV2.name),
metadataSymbolCodec.encode(dataV2.symbol),
metadataUriCodec.encode(dataV2.uri),
metadataSellerFeeBasisPointsCodec.encode(dataV2.sellerFeeBasisPoints),
metadataCreatorsCodec.encode(dataV2.creators?.toJson()),
metadataCollectionCodec.encode(dataV2.collection?.toJson()),
metadataUsesCodec.encode(dataV2.uses?.toJson()),
borsh.boolean.encode(isMutable),
metadataCollectionDetailsCodec.encode(collectionDetails),
];
return _instance.createTransactionIntruction(
MetaplexTokenMetadataInstruction.createMetadataAccountV3,
keys: keys,
data: data,
);
}