0xsequence / erc-1155

Ethereum Semi Fungible Standard (ERC-1155)
https://sequence.build
Other
321 stars 118 forks source link

How do you check if the token is unique? #20

Closed mjtpena closed 4 years ago

mjtpena commented 4 years ago

I was trying to implement the mint and mintBatch functions, but I don't know how to ensure that tokens are unique (NFT). Is it based from the balance of the owners?

PhABC commented 4 years ago

_mintBatch() function should be inherited and called by a parent contract, where you would need to add a logic enforcing that each token id can only be minted once.

e.g. something like

contract ERC1155NFT is ERC1155MintBurn {

  mapping (uint256 => bool) internal minted;

  function batchMintNFT(address _to, uint256[] calldata _ids) external onlyOwners() {
      // Number of NFTs to mint
      uint256 n_ids = _ids.length;

      // Array of 1s for batchmint
      uint256[] memory ones = new uint256[](n_ids);

      // Enforces that each ID is only minted once
      for (uint256 i = 0; i < n_ids; i++) {
        require(!minted[_ids[i]], "NFT Already Minted");
        minted[_ids[i]] = true;
      }

      // Mint NFTs
     super._batchMint(_to, _ids, ones);
  }
}
mjtpena commented 4 years ago

That's actually very clever. I implemented something similar yesterday

    struct TokenSchema {
        string tokenType;
        string metadataUri;
        bool exists;
    }

  mapping(uint256 => TokenSchema) public tokenIds;

Thank you for the effort of implementing ERC1155.