Last active
May 22, 2022 15:33
-
-
Save KBPsystem777/bc68359dd1012e072ed23a334f514a22 to your computer and use it in GitHub Desktop.
This contract implement ERC721 for KBPsystem's NFT collection. This includes several functions like setting the URI, withdrawal of contract funds and checking if available contract funds
This file contains hidden or 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: MIT | |
pragma solidity ^0.8.2; | |
import "@openzeppelin/contracts/token/ERC721/ERC721.sol"; | |
import "@openzeppelin/contracts/token/ERC721/extensions/ERC721Enumerable.sol"; | |
import "@openzeppelin/contracts/access/Ownable.sol"; | |
import "@openzeppelin/contracts/utils/Counters.sol"; | |
import "@openzeppelin/contracts/token/ERC721/extensions/ERC721URIStorage.sol"; | |
/*** | |
* @title KBPsystem NFT contract | |
* @author Koleen BP | |
* @notice This contracts handles the NFT implementation for KBPsystem NFT collections | |
*/ | |
contract KBPPunk is ERC721, ERC721Enumerable, ERC721URIStorage, Ownable { | |
using Counters for Counters.Counter; | |
Counters.Counter private _tokenIdCounter; | |
uint256 public mintRate = 0.01 ether; | |
uint public MAX_SUPPLY = 10000; | |
constructor() ERC721("KBP-Punk", "KBPNFT") {} | |
function _baseURI() internal pure override returns (string memory) { | |
return "https://gateway.pinata.cloud/ipfs/QmYpwYV3V9nFQLt524A5JuL7NgHCzvLHCA5sqjgVd1xSdz/"; | |
} | |
function _burn(uint256 tokenId) internal override(ERC721, ERC721URIStorage) { | |
super._burn(tokenId); | |
} | |
function tokenURI(uint256 tokenId) | |
public | |
view | |
override(ERC721, ERC721URIStorage) | |
returns (string memory) | |
{ | |
return super.tokenURI(tokenId); | |
} | |
function safeMint(address to, string memory uri) public payable returns (uint256){ | |
require(totalSupply() <= MAX_SUPPLY, "Allowable number of NFTs has been met."); | |
require(msg.value > mintRate, "Ether sent is not enough to mint NFT"); | |
_tokenIdCounter.increment(); | |
uint256 tokenId = _tokenIdCounter.current(); | |
_safeMint(to, tokenId); | |
_setTokenURI(tokenId, uri); | |
return tokenId; | |
} | |
// @notice Withdraw function. This will withdraw all the funds from the contract from the minting | |
function withdraw() public onlyOwner { | |
require(address(this).balance > 0, "Contract Balance: 0; Nothing to withdraw here!"); | |
payable(owner()).transfer(address(this).balance); | |
} | |
// @notice Fetched the current contract balance or total ethers sent to this contract | |
function getContractBalance() public view returns(uint256) { | |
return address(this).balance; | |
} | |
// The following functions are overrides required by Solidity. | |
function _beforeTokenTransfer(address from, address to, uint256 tokenId) | |
internal | |
override(ERC721, ERC721Enumerable) | |
{ | |
super._beforeTokenTransfer(from, to, tokenId); | |
} | |
function supportsInterface(bytes4 interfaceId) | |
public | |
view | |
override(ERC721, ERC721Enumerable) | |
returns (bool) | |
{ | |
return super.supportsInterface(interfaceId); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment