// SPDX-License-Identifier: MITpragmasolidity 0.6.6;// using Open Zepplin 3.x import"@openzeppelin/contracts/token/ERC721/ERC721.sol";contractSimpleCollectibleisERC721 {uint256public tokenCounter; //token ids will start frm 0// ERC20 constructor requires:// Name of NFT, symbolconstructor() publicERC721("Doggie", "DOG") { tokenCounter =0; // just being explciit }functioncreateCollectible(stringmemory_tokenURI) publicreturns(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
from brownie import SimpleCollectiblefrom scripts.helpful_scripts import get_accountsample_token_uri ="https://ipfs.io/ipfs/Qmd9MCGtdVz2miNumBHDbvj8bigSgTwnr4SbyH6DNnpWdt?filename=0-PUG.json"OpenSeaURL ="https://testnets.opensea.io/assets/{}/{}"defdeploy(): account =get_account() simple_collectible = SimpleCollectible.deploy({"from": account})# create/mint txt = simple_collectible.createCollectible(sample_token_uri) txt.wait(1)print(f"You can view the NFT at {OpenSeaURL.format(simple_collectible.address, simple_collectible.tokenCounter()-1)}")return simple_collectibledefmain():deploy()
sample json used as URI
When deploying to rinkeby, the opensea link is accessible