Skip to content

Instantly share code, notes, and snippets.

@xtremetom
Created September 6, 2021 10:43
Show Gist options
  • Save xtremetom/b49e79d856e5082199e6e6f417639173 to your computer and use it in GitHub Desktop.
Save xtremetom/b49e79d856e5082199e6e6f417639173 to your computer and use it in GitHub Desktop.
claim and reserve test
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import '@openzeppelin/contracts/token/ERC721/extensions/ERC721Enumerable.sol';
import '@openzeppelin/contracts/access/Ownable.sol';
contract Reserve is ERC721Enumerable, Ownable {
string _baseTokenURI;
uint256 private _price = 0.04 ether;
mapping(address => uint256) public claimMap;
constructor(string memory baseURI) ERC721("Reserve", "R") {
setBaseURI(baseURI);
}
// pay at the point of reserving
// should stop ppl reserving and never claiming
function reserve(uint256 num) public payable {
require(num < 21, "You can adopt a maximum of 20");
require(msg.value >= _price * num, "Ether sent is not correct");
claimMap[msg.sender] += num;
}
// limit claim to help prevent gassing out
function claim(uint256 num) public {
uint256 supply = totalSupply();
uint256 claimCount = claimMap[msg.sender];
require(num >= claimCount, "Cant claim more than you own");
require(num < 21, "You can claim a maximum of 20");
for (uint256 i; i < claimCount; i++) {
_safeMint(msg.sender, supply + i);
}
// account for the claim
claimMap[msg.sender] -= num;
}
// standard minting
function adopt(uint256 num) public payable {
uint256 supply = totalSupply();
require(num < 21, "You can adopt a maximum of 20");
require(msg.value >= _price * num, "Ether sent is not correct");
for (uint256 i; i < num; i++) {
_safeMint(msg.sender, supply + i);
}
}
function _baseURI() internal view virtual override returns (string memory) {
return _baseTokenURI;
}
function setBaseURI(string memory baseURI) public onlyOwner {
_baseTokenURI = baseURI;
}
function getReservedCount() public view returns (uint256){
return claimMap[msg.sender];
}
}
@xtremetom
Copy link
Author

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment