// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
contract Zuiko {
string public name = "ZK";
string public symbol = "ZKO";
string private baseTokenURI;
address public owner;
uint256 public totalSupply;
mapping(uint256 => address) public ownerOf;
mapping(address => uint256) public balanceOf;
mapping(uint256 => string) public tokenURI;
event Transfer(address indexed from, address indexed to, uint256 indexed tokenId);
event Mint(address indexed to, uint256 indexed tokenId, string uri);
event BaseURIChanged(string newBaseURI);
modifier onlyOwner() {
require(msg.sender == owner, "You are not the owner");
_;
}
constructor(string memory _baseTokenURI) {
owner = msg.sender;
baseTokenURI = _baseTokenURI;
}
function mint() public {
uint256 tokenId = totalSupply + 1;
totalSupply = tokenId;
ownerOf[tokenId] = msg.sender;
balanceOf[msg.sender] += 1;
tokenURI[tokenId] = string(abi.encodePacked(baseTokenURI, uint2str(tokenId), ".json"));
emit Transfer(address(0), msg.sender, tokenId);
emit Mint(msg.sender, tokenId, tokenURI[tokenId]);
}
function transfer(address to, uint256 tokenId) public {
require(ownerOf[tokenId] == msg.sender, "You are not the owner of this token");
ownerOf[tokenId] = to;
balanceOf[msg.sender] -= 1;
balanceOf[to] += 1;
emit Transfer(msg.sender, to, tokenId);
}
function getTokenURI(uint256 tokenId) public view returns (string memory) {
require(ownerOf[tokenId] != address(0), "Token does not exist");
return tokenURI[tokenId];
}
function setBaseURI(string memory _newBaseURI) public onlyOwner {
baseTokenURI = _newBaseURI;
emit BaseURIChanged(_newBaseURI);
}
function uint2str(uint256 _i) internal pure returns (string memory) {
if (_i == 0) {
return "0";
}
uint256 j = _i;
uint256 len;
while (j != 0) {
len++;
j /= 10;
}
bytes memory bstr = new bytes(len);
uint256 k = len;
while (_i != 0) {
k = k - 1;
uint8 temp = (48 + uint8(_i - _i / 10 * 10));
bytes1 b1 = bytes1(temp);
bstr[k] = b1;
_i /= 10;
}
return string(bstr);
}
}
{
"compilationTarget": {
"Zuiko.sol": "Zuiko"
},
"evmVersion": "london",
"libraries": {},
"metadata": {
"bytecodeHash": "ipfs"
},
"optimizer": {
"enabled": false,
"runs": 200
},
"remappings": []
}
[{"inputs":[{"internalType":"string","name":"_baseTokenURI","type":"string"}],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"string","name":"newBaseURI","type":"string"}],"name":"BaseURIChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"to","type":"address"},{"indexed":true,"internalType":"uint256","name":"tokenId","type":"uint256"},{"indexed":false,"internalType":"string","name":"uri","type":"string"}],"name":"Mint","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"from","type":"address"},{"indexed":true,"internalType":"address","name":"to","type":"address"},{"indexed":true,"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"Transfer","type":"event"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"balanceOf","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"getTokenURI","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"mint","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"name","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"ownerOf","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"string","name":"_newBaseURI","type":"string"}],"name":"setBaseURI","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"symbol","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"tokenURI","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"totalSupply","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"transfer","outputs":[],"stateMutability":"nonpayable","type":"function"}]