APE Price: $0.99 (-0.65%)

Contract Diff Checker

Contract Name:
GobPepe

Contract Source Code:

File 1 of 1 : GobPepe

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;

contract GobPepe {
    // Token data
    string private _name = "Gob Pepe";
    string private _symbol = "GOBPEPE";
    string private _baseTokenURI;
    uint256 public totalSupply = 0;
    uint256 public maxSupply = 2222;
    uint256 public maxMintAmountPerTx = 50;
    uint256 public cost = 1 ether; // Mint cost in native currency
    bool public paused = false;

    // Owner of the contract
    address public owner;

    // Mappings
    mapping(uint256 => address) private _owners;
    mapping(address => uint256) private _balances;
    mapping(uint256 => address) private _tokenApprovals;
    mapping(address => mapping(address => bool)) private _operatorApprovals;

    // Events
    event Transfer(address indexed from, address indexed to, uint256 indexed tokenId);
    event Approval(address indexed owner, address indexed approved, uint256 indexed tokenId);
    event ApprovalForAll(address indexed owner, address indexed operator, bool approved);
    event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);

    modifier onlyOwner() {
        require(msg.sender == owner, "Caller is not the owner");
        _;
    }

    modifier whenNotPaused() {
        require(!paused, "Contract is paused");
        _;
    }

    constructor(string memory baseURI) {
        owner = msg.sender; // Set the contract deployer as the owner
        _baseTokenURI = baseURI; // Initialize base token URI
    }

    // Public mint function
    function mint(uint256 _mintAmount) public payable whenNotPaused {
        require(_mintAmount > 0, "Invalid mint amount");
        require(_mintAmount <= maxMintAmountPerTx, "Exceeds max mint amount per transaction");
        require(totalSupply + _mintAmount <= maxSupply, "Max supply exceeded");
        require(msg.value >= cost * _mintAmount, "Insufficient funds");

        for (uint256 i = 0; i < _mintAmount; i++) {
            _mint(msg.sender, totalSupply + 1);
        }
    }

    // Admin mint for specific address
    function mintForAddress(uint256 _mintAmount, address _receiver) public onlyOwner {
        require(totalSupply + _mintAmount <= maxSupply, "Max supply exceeded");

        for (uint256 i = 0; i < _mintAmount; i++) {
            _mint(_receiver, totalSupply + 1);
        }
    }

    // Internal mint function
    function _mint(address to, uint256 tokenId) internal {
        require(to != address(0), "Mint to the zero address");
        require(_owners[tokenId] == address(0), "Token already minted");

        _balances[to] += 1;
        _owners[tokenId] = to;
        totalSupply += 1;

        emit Transfer(address(0), to, tokenId);
    }

    // Token URI logic
    function tokenURI(uint256 tokenId) public view returns (string memory) {
        require(_owners[tokenId] != address(0), "Token does not exist");
        return string(abi.encodePacked(_baseTokenURI, uint256ToString(tokenId), ".json"));
    }

    // Helper function to set the base URI
    function setBaseURI(string memory baseURI) public onlyOwner {
        _baseTokenURI = baseURI;
    }

    // Approve a token for transfer
    function approve(address to, uint256 tokenId) public {
        address tokenOwner = _owners[tokenId];
        require(msg.sender == tokenOwner || isApprovedForAll(tokenOwner, msg.sender), "Not authorized");
        _tokenApprovals[tokenId] = to;

        emit Approval(tokenOwner, to, tokenId);
    }

    // Get approved address for a token
    function getApproved(uint256 tokenId) public view returns (address) {
        return _tokenApprovals[tokenId];
    }

    // Set operator approval for all tokens
    function setApprovalForAll(address operator, bool approved) public {
        _operatorApprovals[msg.sender][operator] = approved;

        emit ApprovalForAll(msg.sender, operator, approved);
    }

    // Check if operator is approved for all tokens
    function isApprovedForAll(address tokenOwner, address operator) public view returns (bool) {
        return _operatorApprovals[tokenOwner][operator];
    }

    // Transfer token from one address to another
    function transferFrom(address from, address to, uint256 tokenId) public whenNotPaused {
        require(_isApprovedOrOwner(msg.sender, tokenId), "Not authorized");
        require(to != address(0), "Transfer to the zero address");

        _balances[from] -= 1;
        _balances[to] += 1;
        _owners[tokenId] = to;

        emit Transfer(from, to, tokenId);
    }

    // Pause or unpause the contract
    function setPaused(bool _state) public onlyOwner {
        paused = _state;
    }

    // Withdraw funds to the owner
    function withdraw() public onlyOwner {
        (bool success, ) = owner.call{value: address(this).balance}("");
        require(success, "Withdraw failed");
    }

    // Transfer ownership to a new address
    function transferOwnership(address newOwner) public onlyOwner {
        require(newOwner != address(0), "New owner is the zero address");
        emit OwnershipTransferred(owner, newOwner);
        owner = newOwner;
    }

    // Internal function to check if caller is approved or owner
    function _isApprovedOrOwner(address spender, uint256 tokenId) internal view returns (bool) {
        address tokenOwner = _owners[tokenId];
        return (spender == tokenOwner || getApproved(tokenId) == spender || isApprovedForAll(tokenOwner, spender));
    }

    // Utility function to convert uint256 to string
    function uint256ToString(uint256 value) internal pure returns (string memory) {
        if (value == 0) {
            return "0";
        }
        uint256 temp = value;
        uint256 digits;
        while (temp != 0) {
            digits++;
            temp /= 10;
        }
        bytes memory buffer = new bytes(digits);
        while (value != 0) {
            digits -= 1;
            buffer[digits] = bytes1(uint8(48 + uint256(value % 10)));
            value /= 10;
        }
        return string(buffer);
    }
}

Please enter a contract address above to load the contract details and source code.

Context size (optional):