On-Demand Minting
In some cases, owners of NFT collections want to allow for just in time, on-demand minting. Examples include:
- Allowing users to curate their own artwork to be minted
- Marking NFT metadata with user specific or off-chain information
- Deciding on a case by case basis whether a user can claim and what their claim conditions are
thirdweb provides a signature based minting mechanic which allows the publisher of the smart contract to issues signature vouchers that is sent back to the connected user giving them permission to mint (design document).
Signature based minting allows for a very secure means of minting that prevents users from minting directly from the smart contract as only wallets designated with the MINTER role are allowed to issue signatures.
// CLIENT: application sets nft metadata at run-time
const nftMetadata = {
name: "Cool NFT #1",
description: "This is a cool NFT",
image: fs.readFileSync("path/to/image.png"), // This can be an image url or file
};
////////////////////////////////////////////////////////////////////////
// SERVER: on back end signature is generated based on application rules
const startTime = new Date();
const endTime = new Date(Date.now() + 60 * 60 * 24 * 1000);
const payload = {
metadata: nftMetadata, // The NFT to mint
to: {{wallet_address}}, // Who will receive the NFT
quantity: 2, // the quantity of NFTs to mint
price: 0.5, // the price per NFT
currencyAddress: NATIVE_TOKEN_ADDRESS, // the currency to pay with
mintStartTime: startTime, // can mint anytime from now
mintEndTime: endTime, // to 24h from now
royaltyRecipient: "0x...", // custom royalty recipient for this NFT
royaltyBps: 100, // custom royalty fees for this NFT (in bps)
primarySaleRecipient: "0x...", // custom sale recipient for this NFT
};
const signedPayload = await contract.erc721.signature.generate(payload);
/////////////////////////////////////////////////////////////////////////
// CLIENT: mint using the signature
const tx = contract.erc721.signature.mint(signedPayload);