Created
December 2, 2021 16:24
-
-
Save andreivcodes/1ad555357a5b4d53545bf8d372a7e95f to your computer and use it in GitHub Desktop.
Created using remix-ide: Realtime Ethereum Contract Compiler and Runtime. Load this file by pasting this gists URL or ID at https://remix.ethereum.org/#version=soljson-v0.8.7+commit.e28d00a7.js&optimize=false&runs=200&gist=
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
//Contract based on [https://docs.openzeppelin.com/contracts/3.x/erc721](https://docs.openzeppelin.com/contracts/3.x/erc721) | |
// SPDX-License-Identifier: MIT | |
pragma solidity ^0.8.0; | |
import "@openzeppelin/contracts/token/ERC721/ERC721.sol"; | |
import "@openzeppelin/contracts/utils/Counters.sol"; | |
import "@openzeppelin/contracts/access/Ownable.sol"; | |
import "@openzeppelin/contracts/utils/Address.sol"; | |
import "@openzeppelin/contracts/token/ERC721/extensions/ERC721URIStorage.sol"; | |
contract mintable is ERC721URIStorage, Ownable { | |
using Counters for Counters.Counter; | |
Counters.Counter private _tokenIdsCounter; | |
bool public saleIsActive = false; | |
uint256 public maxTokenSupply; | |
uint256 public mintPrice = 1000000000 gwei; // 1 ETH | |
address[2] private _shareholders; | |
uint[2] private _shares; | |
event PaymentReleased(address to, uint256 amount); | |
constructor() ERC721("Dacii Liberi", "DAC") { | |
_shareholders[0] = 0xdD870fA1b7C4700F2BD7f44238821C26f7392148; | |
_shareholders[1] = 0x583031D1113aD414F02576BD6afaBfb302140225; | |
_shares[0] = 3000; | |
_shares[1] = 7000; | |
maxTokenSupply = 10; | |
} | |
function withdraw(uint256 amount) public onlyOwner { | |
require(address(this).balance >= amount, "Insufficient balance"); | |
uint256 totalShares = 10000; | |
for (uint256 i = 0; i < 2; i++) { | |
uint256 payment = amount * _shares[i] / totalShares; | |
Address.sendValue(payable(_shareholders[i]), payment); | |
emit PaymentReleased(_shareholders[i], payment); | |
} | |
} | |
function mintNFT(address recipient, string memory tokenURI) | |
public payable | |
returns (uint256) | |
{ | |
require(saleIsActive, "Sale must be active."); | |
require(_tokenIdsCounter.current() < maxTokenSupply, "All tokens already minted."); | |
require(msg.value >= mintPrice, "Not enough ETH sent; check price!"); | |
_tokenIdsCounter.increment(); | |
uint256 newItemId = _tokenIdsCounter.current(); | |
_safeMint(recipient, newItemId); | |
_setTokenURI(newItemId, tokenURI); | |
return newItemId; | |
} | |
function setMintPrice(uint256 newPrice) public onlyOwner { | |
mintPrice = newPrice; | |
} | |
function setMaxTokenSupply(uint256 maxDragonSupply) public onlyOwner { | |
maxTokenSupply = maxDragonSupply; | |
} | |
function flipSaleState() public onlyOwner { | |
saleIsActive = !saleIsActive; | |
} | |
function getETHBalance() public view onlyOwner returns (uint256) | |
{ | |
return address(this).balance; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment