For minting an NFT we will interact with the Token Metadata program, see the metaplex documentation for a comprehensive overview.
Firstly, we need to create a new mint account for the NFT we want to mint and an associated token account for owning it.
Copy
Ask AI
var mint = new Account();var associatedTokenAccount = AssociatedTokenAccountProgram .DeriveAssociatedTokenAccount(Web3.Account, mint.PublicKey);
Secondly, let’s define the metadata of the NFT.
Copy
Ask AI
var metadata = new Metadata(){ name = "Test", symbol = "TST", uri = "https://y5fi7acw5f5r4gu6ixcsnxs6bhceujz4ijihcebjly3zv3lcoqkq.arweave.net/x0qPgFbpex4ankXFJt5eCcRKJzxCUHEQKV43mu1idBU", sellerFeeBasisPoints = 0, creators = new List<Creator> { new(Web3.Account.PublicKey, 100, true)}};
We can now construct the transaction, whichi consists of 5 istructions:
var tx = Transaction.Deserialize(transaction.Build(new List<Account> {Web3.Account, mint}));var res = await Web3.Wallet.SignAndSendTransaction(tx);Debug.Log(res.Result);
The console will print the transaction signature, which you can investigate in the inspector and should looks similar to this transaction,You can lookup the mint address in the explorer, which should be similar to this NFT