Mint an NFT
Now that we have a deployed contract, we can mint an NFT.
info
This document assumes you have followed the deploy a contract instructions and have a contract address for minting NFTs.
Load the contract
Use the loadContract
method to assign the contract to a variable.
Add the deployed contract address.
const existing = await sdk.loadContract({
template: TEMPLATES.ERC721Mintable,
contractAddress: "<CONTRACT_ADDRESS>",
});
console.log(`Contract address is: ${existing.contractAddress}`);
Mint an NFT
Include the tokenURI
in the mint
method.
info
Like contractURI
, the tokenURI
must resolve to a public, hosted, well-formed json file.
Call the mint method.
const mint1 = await existing.mint({
publicAddress: process.env.WALLET_PUBLIC_ADDRESS,
tokenURI:
"https://bafybeiebu2p6locm37kt2yqybpk6cw5kih5dytnfm3mkh7h7auuksbtx5i.ipfs.infura-ipfs.io/",
});
const minted = await mint1.wait();
console.log(
`Status: ${minted.status}\n NFT minted on ${minted.blockHash} with ${minted.confirmations} confirmation!`,
);
Example output:
Contract address is: 0x0300F3F929B558e84107B67e3FbBe9e897daDB5a
Status: 1
NFT minted on 0x3df8bf019a2d38f71173a1c7d94ab1f70ffa13a411b311e9054c55fd3e35c00a with 1 confirmation!