Created
June 8, 2020 03:01
-
-
Save dekanbro/1172e0d296e61641ead72e2538af7d88 to your computer and use it in GitHub Desktop.
Simple nft sale contract
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
pragma solidity ^0.6.0; | |
// OZ release-v3.0.0 | |
import "github/OpenZeppelin/openzeppelin-contracts/contracts/token/ERC721/ERC721.sol"; | |
import "github/OpenZeppelin/openzeppelin-contracts/contracts/utils/Counters.sol"; | |
import "github/OpenZeppelin/openzeppelin-contracts/contracts/access/Ownable.sol"; | |
contract NFTSale is ERC721, Ownable { | |
using Counters for Counters.Counter; | |
Counters.Counter private _tokenIds; | |
uint256 public salePrice = 100000000000000000; | |
constructor() ERC721("Dao Donations NFT", "DDN") public { | |
} | |
function mintNFT(string memory tokenURI) public payable returns (bool) { | |
require(msg.value >= salePrice, 'value sent needs to be atleast sale price'); | |
_tokenIds.increment(); | |
uint256 newItemId = _tokenIds.current(); | |
_mint(address(msg.sender), newItemId); | |
_setTokenURI(newItemId, tokenURI); | |
return true; | |
} | |
function withdraw(address payable owner) public onlyOwner returns(bool) { | |
owner.transfer(address(this).balance); | |
return true; | |
} | |
function setPrice(uint256 price) public onlyOwner returns (bool) { | |
salePrice = price; | |
return true; | |
} | |
function getBalanceContract() public view returns(uint){ | |
return address(this).balance; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment