Skip to content

Instantly share code, notes, and snippets.

@sagaratalatti
Last active October 16, 2024 10:36
Show Gist options
  • Save sagaratalatti/a5bc7e76f481957ae4cf793a5c9f19cf to your computer and use it in GitHub Desktop.
Save sagaratalatti/a5bc7e76f481957ae4cf793a5c9f19cf to your computer and use it in GitHub Desktop.
Generated ERC721 with Airdrop Contract by Bountys
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;
import "@openzeppelin/contracts/token/ERC721/ERC721.sol";
import "@openzeppelin/contracts/token/ERC721/extensions/ERC721Enumerable.sol";
import "@openzeppelin/contracts/token/ERC721/extensions/ERC721Pausable.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
import "@openzeppelin/contracts/token/ERC721/extensions/ERC721Burnable.sol";
contract AMEYA is ERC721, ERC721Enumerable, ERC721Pausable, Ownable, ERC721Burnable {
uint256 private _nextTokenId;
uint256 public constant AIRDROP_SUPPLY = 21;
uint256 public airdropStartTime;
uint256 public airdropEndTime;
uint256 public airdropMintedCount;
event MintSuccess(address indexed recipient, uint256 indexed tokenId);
event MintFailure(address indexed recipient, uint256 indexed tokenId, string reason);
constructor(address initialOwner)
ERC721("AMEYA", "AMY")
Ownable(initialOwner)
{
airdropStartTime = 1124123;
airdropEndTime = 34545;
}
function _baseURI() internal pure override returns (string memory) {
return "https://google.com/ameya/";
}
function pause() public onlyOwner {
_pause();
}
function unpause() public onlyOwner {
_unpause();
}
function safeMint(address to, uint256 tokenId) external onlyOwner {
_safeMint(to, tokenId);
}
function setAirdropTime(uint256 _time) public {
require(_time > block.timestamp, "Airdrop start time must be in the future");
airdropStartTime = _time;
airdropEndTime = _time;
}
function getAirdropTime() public view returns (uint256, uint256) {
return (airdropStartTime, airdropEndTime);
}
function airdrop() public {
require(block.timestamp >= airdropStartTime, "Airdrop hasn't started yet");
require(block.timestamp <= airdropEndTime, "Airdrop has ended");
require(airdropMintedCount < AIRDROP_SUPPLY, "All airdrop tokens have been minted");
require(balanceOf(msg.sender) == 0, "You have already claimed your airdrop");
uint256 tokenId = airdropMintedCount;
airdropMintedCount++;
_safeMint(msg.sender, tokenId);
emit MintSuccess(msg.sender, tokenId);
}
function batchMint(address[] memory recipients, uint256[] calldata tokenIds)
public
returns (uint256[] memory)
{
require(block.timestamp >= airdropStartTime, "Airdrop hasn't started yet");
require(recipients.length == tokenIds.length, "Mismatched array lengths");
require(airdropMintedCount + recipients.length <= AIRDROP_SUPPLY, "Exceeds airdrop supply");
uint256[] memory failedTokenIds = new uint256[](recipients.length);
uint256 failedCount = 0;
for (uint256 i = 0; i < recipients.length; i++) {
address recipient = recipients[i];
uint256 tokenId = tokenIds[i];
if (recipient == address(0)) {
emit MintFailure(recipient, tokenId, "Invalid recipient address");
failedTokenIds[failedCount++] = tokenId;
continue;
}
try safeMint(recipient, tokenId) {
emit MintSuccess(recipient, tokenId);
airdropMintedCount++;
} catch Error(string memory reason) {
emit MintFailure(recipient, tokenId, reason);
failedTokenIds[failedCount++] = tokenId;
} catch (bytes memory /*lowLevelData*/) {
emit MintFailure(recipient, tokenId, "Low-level error");
failedTokenIds[failedCount++] = tokenId;
}
}
uint256[] memory finalFailedTokenIds = new uint256[](failedCount);
for (uint256 j = 0; j < failedCount; j++) {
finalFailedTokenIds[j] = failedTokenIds[j];
}
return finalFailedTokenIds;
}
// The following functions are overrides required by Solidity.
function _update(address to, uint256 tokenId, address auth)
internal
override(ERC721, ERC721Enumerable, ERC721Pausable)
returns (address)
{
return super._update(to, tokenId, auth);
}
function _increaseBalance(address account, uint128 value)
internal
override(ERC721, ERC721Enumerable)
{
super._increaseBalance(account, value);
}
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