Created
November 24, 2022 01:22
-
-
Save apogiatzis/df572fd12ead96266f1822a2e60ed71a to your computer and use it in GitHub Desktop.
ERC721 Contract for Comp1830
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// SPDX-License-Identifier: Unlicensed | |
pragma solidity >=0.7.0 <0.9.0; | |
import "@openzeppelin/contracts/token/ERC721/extensions/ERC721Enumerable.sol"; | |
import "@openzeppelin/contracts/access/Ownable.sol"; | |
contract Comp1830NFT is ERC721Enumerable, Ownable { | |
using Strings for uint256; | |
string public baseURI; | |
uint256 public maxSupply = 10; // max total nft | |
constructor( | |
string memory _name, // token name | |
string memory _symbol, // token symbol | |
string memory _initBaseURI // token metdata | |
) ERC721(_name, _symbol) { | |
setBaseURI(_initBaseURI); | |
mint(msg.sender, 5); // mint at the initial run | |
} | |
function _baseURI() internal view virtual override returns (string memory) { | |
return baseURI; | |
} | |
function mint(address _to, uint256 _mintAmount) public payable { | |
uint256 supply = totalSupply(); | |
require(_mintAmount > 0); | |
require(supply + _mintAmount <= maxSupply); | |
for (uint256 i = 1; i <= _mintAmount; i++) { | |
_safeMint(_to, supply + i); | |
} | |
} | |
function setBaseURI(string memory _newBaseURI) public onlyOwner { | |
baseURI = _newBaseURI; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment