// SPDX-License-Identifier: MIT pragma solidity ^0.8.0; import "@openzeppelin/contracts/token/ERC721/ERC721.sol"; import "@openzeppelin/contracts/access/Ownable.sol"; import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; contract NFTPresale is ERC721, Ownable { IERC20 public erc20Token; uint256 public _nextTokenId; uint256 public price; uint256 public priceInNative; constructor(address initialOwner, address _erc20Token, uint256 _price) ERC721("NAME_OF_TOKEN", "NOT") Ownable(initialOwner) { erc20Token = IERC20(_erc20Token); price = _price; } function _safeMint(address to) internal { uint256 tokenId = _nextTokenId++; _safeMint(to, tokenId); } function preSaleMintWithERC20Token() public onlyOwner { // transfer erc20 require(erc20Token.transferFrom(msg.sender, address(this), price), "ERC20: transfer failed"); // mint nft _safeMint(msg.sender); } function preSaleMintWithNativeToken() public payable onlyOwner { // transfer native require(msg.value >= priceInNative, "Insufficient native token amount"); // mint nft _safeMint(msg.sender); } function withdrawFunds(address payable to, uint256 amount, IERC20 token) public onlyOwner { require(token.transfer(to, amount), "ERC20 transfer failed"); } function withdrawNativeFunds(address payable to, uint256 amount) public onlyOwner { require(amount <= address(this).balance, "Insufficient balance"); to.transfer(amount); } }
0.7.0