Untitled

mail@pastecode.io avatar
unknown
javascript
2 months ago
1.1 kB
3
Indexable
Never
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;

import "@openzeppelin/contracts/token/ERC721/ERC721.sol";

contract MyToken is ERC721 {
    using Strings for uint256;
    uint256 public currentId;

    string private _uri;
    address private _owner;

    constructor() ERC721("Chimpers", "CHIMP") {
        _owner = msg.sender;
    }

    function setBaseURI(string memory uri) public virtual {
        require(_owner == msg.sender, "invalid owner");

        require(bytes(uri).length > 0, "uri is invalid");

        _uri = uri;
    }

    function mint(address to) public virtual {
        require(_owner == msg.sender, "invalid owner");

        _mint(to, ++currentId);
    }

    function mintBatch(address to, uint256 num) public virtual {
        require(_owner == msg.sender, "invalid owner");
      
        for (uint256 i = 0; i < num; i++) {
            _mint(to, ++currentId);
        }
    }

    function _baseURI() internal view virtual override returns (string memory) {
        return _uri;
    }
}
Leave a Comment