// SPDX-License-Identifier: MIT pragma solidity >0.8.16; import "@openzeppelin/contracts/token/ERC721/extensions/ERC721Enumerable.sol"; import "@openzeppelin/contracts/token/ERC721/ERC721.sol"; import "@openzeppelin/contracts/utils/Base64.sol"; // import "this shouldn't be imorted"; /// @author Wagmi /// @author Tevm /// @title WagmiMintExample /// @notice An example token original from the wagmi template contract WagmiMintExample is ERC721 { uint256 public totalSupply; // import "@openzeppelin/contracts/utils/Base64.sol"; uint256 private nextTokenId = 0; constructor() ERC721("wagmi", "WAGMI") {} /// @notice Allows an address to mint function mint() external { uint256 tokenId = nextTokenId; while (_ownerOf(tokenId) != address(0)) { unchecked { tokenId++; } } _safeMint(msg.sender, tokenId); unchecked { totalSupply++; nextTokenId = tokenId + 1; } } /// @notice Returns the token URI for a given token by ID /// @param tokenId Token ID to mint. function mint(uint256 tokenId) external { require(_ownerOf(tokenId) == address(0), "Token ID is taken"); _safeMint(msg.sender, tokenId); unchecked { totalSupply++; } } /// @notice Returns the token URI for a given token by ID /// @param tokenId Token ID to query. /// @return uri_ Token URI for the given token by ID. function tokenURI( uint256 tokenId ) public pure override returns (string memory) { uint256 foregroundHue = uint256( keccak256(abi.encodePacked("foreground", tokenId)) ) % 360; uint256 backgroundHue = uint256( keccak256(abi.encodePacked("background", tokenId)) ) % 360; string memory json = Base64.encode( bytes( abi.encodePacked( '{"name": "wagmi #', toString(tokenId), '", "image": "data:image/svg+xml;base64,', Base64.encode( bytes( abi.encodePacked( '' ) ) ), '"}' ) ) ); string memory output = string( abi.encodePacked("data:application/json;base64,", json) ); return output; } function toString(uint256 value) internal pure returns (string memory) { // Inspired by OraclizeAPI's implementation - MIT licence // https://github.com/oraclize/ethereum-api/blob/b42146b063c7d6ee1358846c198246239e9360e8/oraclizeAPI_0.4.25.sol 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); } }