WHITE PAPER
  • 🛢️Background
  • 🗃️Design Concepts and Design Principles
  • 📇Decentralized storage
    • For Verifiable Content
    • Content addressing
      • CID: globally unique regardless of location
      • WebMingle CIDs
  • 📼NFT storage example
    • Why choose WebMingle?
    • IPFS and WebMingle to the rescue
    • Storing and Minting NFTs in WebMingle
      • Upload your images, assets and metadata
      • Mint your NFT
      • Writing NFT smart contracts
  • 🌐Application Notes
    • WMI NFT Storage
    • WMI NFT Start
    • WMI NFT Share
  • 💾Token Economics
    • Introduction
    • Economic Model
  • 🎛️Participant
  • ⚙️Statement
Powered by GitBook
On this page
  1. NFT storage example
  2. Storing and Minting NFTs in WebMingle

Writing NFT smart contracts

Ethereum is the “birthplace” of NFTs and remains one of the most popular platforms for the NFT market and creators.

The most widely used and well supported standards are ERC-721 and ERC-1155. Adopting one of these interfaces will allow your NFTs to receive broad support "out of the box" from wallets and other NFT applications without any special coordination or effort on your part.

Both ERC standards define methods for retrieving the URI associated with a token. In ERC-721, the method is called tokenURI, while ERC-1155 uses uri.

In general, you will mint new tokens by calling a smart contract function that assigns a new token ID and sets the metadata URI. The exact name of this function may vary from contract to contract, if you are writing your own contract you can call it however you want.

Here's an example contract from the OpenZeppelin ERC-721 guide, using their excellent base contract:

// contracts/GameItem.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

import "@openzeppelin/contracts/token/ERC721/extensions/ERC721URIStorage.sol";
import "@openzeppelin/contracts/utils/Counters.sol";

contract GameItem is ERC721URIStorage {
    using Counters for Counters.Counter;
    Counters.Counter private _tokenIds;
    constructor() ERC721("GameItem", "ITM") {}
    function awardItem(address player, string memory tokenURI)
        public
        returns (uint256)
    {
        _tokenIds.increment();
        uint256 newItemId = _tokenIds.current();
        _mint(player, newItemId);
        _setTokenURI(newItemId, tokenURI);

        return newItemId;
    }
}

Here, the minting function is called awardItem, which creates a new token and assigns it to the player address.

The second parameter is tokenURI, which sets the value returned by the contract's tokenURI method. Here you can put the IPFS URI of the NFT metadata.

After a token is minted, anyone can call the tokenURI method (defined in the underlying contract) and find the URI of any token. Using URIs, callers can use a peer-to-peer IPFS network or HTTP gateway to get metadata, images, and other assets that define the NFT.

PreviousMint your NFTNextApplication Notes

Last updated 1 year ago

📼
Page cover image