NFT
SimpleCollectible
AdvancedCollectible
SimpleCollectible
// SPDX-License-Identifier: MIT
pragma solidity 0.6.6;
// using Open Zepplin 3.x
import "@openzeppelin/contracts/token/ERC721/ERC721.sol";
contract SimpleCollectible is ERC721 {
uint256 public tokenCounter; //token ids will start frm 0
// ERC20 constructor requires:
// Name of NFT, symbol
constructor() public ERC721("Doggie", "DOG") {
tokenCounter = 0; // just being explciit
}
function createCollectible(string memory _tokenURI) public returns(uint256) {
uint newTokenId = tokenCounter;
_safeMint(msg.sender, newTokenId);
_setTokenURI(newTokenId, _tokenURI); //sets tokenURI for this tokenID - for images.
tokenCounter = ++ tokenCounter;
return newTokenId; //return tokenID of the minted
}
}
We inherit ERC721 (and its constructor):
need to pass name and symbol as parameters
createCollectible() will be used to mint new NFTs by calling:
_safeMint() from ERC721
_setTokenURI() to pass the URI webstring
tokenCounter to track and increment NFTs minted
Last updated