Mint NFT

Mint Single NFT

The mintNFT function, imported from streamnft-evm, facilitates minting various types of tokens (ERC721, ERC1155, Certificate) on the Ethereum Virtual Machine (EVM). It supports both public and private minting methods for different token standards.


🔧 Function Signature

await mintNFT(
  tokenType,
  price,  // Price in Wei
  amount,  // Amount (irrelevant for ERC721)
  signature,  // Signature
  tokenUri,  // Token URI
  tokenId,  // Token ID
  chainId,  // Chain ID
  signer,
  contractAddress
);

📄 Parameters
  • tokenType (number, required): The type of token to be minted, specified in the TokenType enumeration.

  • price (BigInt | number, optional): The price per token in Wei for public minting. For private tokens, this is not required.

  • amount (number, optional): The quantity of tokens to mint (mainly for ERC1155).

  • signature (string, optional): A pre-approved signature required for ERC721Public minting.

  • tokenUri (string, optional): The metadata URI for the NFT.

  • tokenId (number, optional): The ID of the token to mint.

  • chainId (number, required): The chain ID where the contract is deployed.

  • signer (Signer, required): The wallet or account object initiating the transaction.

  • contractAddress (string, required): The address of the deployed NFT contract.


✅ Example Usage

1. ERC721Public (Public Minting)

  • Required: price, signature, tokenUri, tokenId

  • Example:

2. ERC721Private (Private Minting)

  • Required: tokenUri

  • Example:

3. ERC1155Public (Public Minting)

  • Required: price, amount, tokenId

  • Example:

4. ERC1155Private (Private Minting)

  • Required: amount, tokenId

  • Example:

5. Certificate (Owner-Only Minting)

  • No price, amount, or tokenUri required.

  • Example:


Return Value

An object containing:

  • success (boolean): Indicates if minting was successful.

  • tokenType (number): The type of token minted.

  • transactionHash (string): The hash of the transaction.

  • error (string): Error message, if applicable.


Error Handling

  • Throws Invalid token type if tokenType does not match a supported type.

  • Throws Unsupported token type for SoulBound and ERC7066 tokens (not yet implemented).

  • Catches and logs errors if the transaction fails.

Last updated