Discover more of Apescan's tools and services in one place.
Contract Source Code:
File 1 of 1 : TransferToNull.sol
// SPDX-License-Identifier: MIT pragma solidity ^0.8.0; interface IERC721A { function ownerOf(uint256 tokenId) external view returns (address); function approve(address to, uint256 tokenId) external; function transferFrom(address from, address to, uint256 tokenId) external; } contract TransferToNull { address public nftContractAddress; // Track the number of NFTs burned by each address mapping(address => uint256) public burnedNFTs; // Enum for tier levels enum Tier { None, Tier1, Tier2, Tier3 } // Mapping to store user's tier level mapping(address => Tier) public userTier; // Arrays to store addresses by tier address[] public tier1Addresses; address[] public tier2Addresses; address[] public tier3Addresses; // Constructor to set the NFT contract address constructor(address _nftContractAddress) { nftContractAddress = _nftContractAddress; } // Function to get the current tier of an address function getTier(address user) public view returns (Tier) { return userTier[user]; } // Function to transfer multiple NFTs to the null address (0x0) function transferToNull(uint256[] calldata tokenIds) external { IERC721A nft = IERC721A(nftContractAddress); for (uint256 i = 0; i < tokenIds.length; i++) { uint256 tokenId = tokenIds[i]; // Ensure the caller owns the token address owner = nft.ownerOf(tokenId); require(owner == msg.sender, "You must own the token to transfer it"); // Approve the transfer to this contract nft.approve(address(this), tokenId); // Transfer the token to the null address (0x0) nft.transferFrom(owner, address(0), tokenId); // Track the number of NFTs burned by the caller burnedNFTs[msg.sender]++; // Update the user's tier based on the number of NFTs burned updateTier(msg.sender); } } // Function to update the tier of the user based on the number of NFTs burned function updateTier(address user) internal { uint256 burnedCount = burnedNFTs[user]; // Check if the user needs to be moved to a higher or lower tier if (burnedCount >= 25) { if (userTier[user] != Tier.Tier1) { removeFromTier(userTier[user], user); tier1Addresses.push(user); userTier[user] = Tier.Tier1; } } else if (burnedCount >= 15) { if (userTier[user] != Tier.Tier2) { removeFromTier(userTier[user], user); tier2Addresses.push(user); userTier[user] = Tier.Tier2; } } else if (burnedCount >= 5) { if (userTier[user] != Tier.Tier3) { removeFromTier(userTier[user], user); tier3Addresses.push(user); userTier[user] = Tier.Tier3; } } else { if (userTier[user] != Tier.None) { removeFromTier(userTier[user], user); userTier[user] = Tier.None; } } } // Helper function to remove an address from the previous tier array function removeFromTier(Tier oldTier, address user) internal { if (oldTier == Tier.Tier1) { removeAddressFromArray(tier1Addresses, user); } else if (oldTier == Tier.Tier2) { removeAddressFromArray(tier2Addresses, user); } else if (oldTier == Tier.Tier3) { removeAddressFromArray(tier3Addresses, user); } } // Helper function to remove an address from an array function removeAddressFromArray(address[] storage tierArray, address user) internal { for (uint256 i = 0; i < tierArray.length; i++) { if (tierArray[i] == user) { tierArray[i] = tierArray[tierArray.length - 1]; tierArray.pop(); break; } } } // Function to get all addresses of users in Tier 1 function getTier1Addresses() public view returns (address[] memory) { return tier1Addresses; } // Function to get all addresses of users in Tier 2 function getTier2Addresses() public view returns (address[] memory) { return tier2Addresses; } // Function to get all addresses of users in Tier 3 function getTier3Addresses() public view returns (address[] memory) { return tier3Addresses; } }
Please enter a contract address above to load the contract details and source code.
Please DO NOT store any passwords or private keys here. A private note (up to 100 characters) can be saved and is useful for transaction tracking.
This website uses cookies to improve your experience. By continuing to use this website, you agree to its Terms and Privacy Policy.