Skip to content
Verified contractPartialMIT

InariaFoxes

Address0xd1725bdec3c2cec004c178d17dea4634cd63fcfd
Balance

0 ETH

 

Transactions

1,634

 

Compiler

solc 0.8.26

 

Same code

Only this contract

 

Details

Compiler
solc 0.8.26+commit.8a97fa7a
Language
solidity
Optimization
Yes, 200 runs
License
MIT
Match
Partialcreation code: yes, runtime code: yes
Verified on Sourcify
Created in block
25,371,675
Creation transaction
0x78e0257d53…27bbe8d614

InariaFoxes.sol

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

/*
      ___________________________________________
     |___________________________________________|
         ||                               ||
    =====||===============================||=====
         ||         I N A R I A           ||
         ||           F O X E S           ||
        _||_                             _||_
       |____|                           |____|

  INARIA FOXES (KITSUNE) - a fully on-chain ERC-721.

  The kitsune are Inari's messengers. Each fox here is drawn by the contract
  itself: the image is an SVG generated on-chain from the token id, so it needs
  no server, no IPFS, and no metadata host. Mint is open and free (you pay only
  gas). There is no owner, no admin, and no constructor arguments - just deploy.

  inaria.xyz  .  x.com/inariaGame  .  seal 稲荷
*/

interface ERC721TokenReceiver {
    function onERC721Received(address, address, uint256, bytes calldata) external returns (bytes4);
}

library LibString {
    function toString(uint256 v) internal pure returns (string memory) {
        if (v == 0) return "0";
        uint256 t = v;
        uint256 d;
        while (t != 0) {
            d++;
            t /= 10;
        }
        bytes memory b = new bytes(d);
        while (v != 0) {
            d -= 1;
            b[d] = bytes1(uint8(48 + (v % 10)));
            v /= 10;
        }
        return string(b);
    }
}

library Base64 {
    string internal constant TABLE = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";

    function encode(bytes memory data) internal pure returns (string memory) {
        if (data.length == 0) return "";
        string memory table = TABLE;
        string memory result = new string(4 * ((data.length + 2) / 3));
        assembly {
            let tablePtr := add(table, 1)
            let resultPtr := add(result, 32)
            for {
                let dataPtr := data
                let endPtr := add(data, mload(data))
            } lt(dataPtr, endPtr) {} {
                dataPtr := add(dataPtr, 3)
                let input := mload(dataPtr)
                mstore8(resultPtr, mload(add(tablePtr, and(shr(18, input), 0x3F))))
                resultPtr := add(resultPtr, 1)
                mstore8(resultPtr, mload(add(tablePtr, and(shr(12, input), 0x3F))))
                resultPtr := add(resultPtr, 1)
                mstore8(resultPtr, mload(add(tablePtr, and(shr(6, input), 0x3F))))
                resultPtr := add(resultPtr, 1)
                mstore8(resultPtr, mload(add(tablePtr, and(input, 0x3F))))
                resultPtr := add(resultPtr, 1)
            }
            switch mod(mload(data), 3)
            case 1 {
                mstore8(sub(resultPtr, 1), 0x3d)
                mstore8(sub(resultPtr, 2), 0x3d)
            }
            case 2 {
                mstore8(sub(resultPtr, 1), 0x3d)
            }
        }
        return result;
    }
}

/// @title  Inaria Foxes ($KITSUNE)
/// @notice Fully on-chain ERC-721. Open, free, ownerless mint. No constructor args.
contract InariaFoxes {
    using LibString for uint256;

    string public constant name = "Inaria Foxes";
    string public constant symbol = "KITSUNE";

    string public constant website = "https://inaria.xyz";
    string public constant twitter = "https://x.com/inariaGame";

    uint256 public constant MAX_SUPPLY = 8888;
    uint256 public constant MAX_PER_WALLET = 10;

    uint256 public totalSupply;
    mapping(address => uint256) public minted;

    mapping(uint256 => address) internal _ownerOf;
    mapping(address => uint256) internal _balanceOf;
    mapping(uint256 => address) public getApproved;
    mapping(address => mapping(address => bool)) public isApprovedForAll;

    event Transfer(address indexed from, address indexed to, uint256 indexed id);
    event Approval(address indexed owner, address indexed spender, uint256 indexed id);
    event ApprovalForAll(address indexed owner, address indexed operator, bool approved);

    /*//////////////////////////////////////////////////////////////
                                  MINT
    //////////////////////////////////////////////////////////////*/

    /// @notice Mint one fox to yourself. Free (pay gas only).
    function mint() public {
        _mintOne();
    }

    /// @notice Mint several foxes in one call, up to the per-wallet cap.
    function mintMany(uint256 qty) public {
        for (uint256 i; i < qty; ++i) _mintOne();
    }

    function _mintOne() internal {
        require(totalSupply < MAX_SUPPLY, "SOLD_OUT");
        require(minted[msg.sender] < MAX_PER_WALLET, "WALLET_LIMIT");
        uint256 id = totalSupply;
        unchecked {
            totalSupply++;
            minted[msg.sender]++;
            _balanceOf[msg.sender]++;
        }
        _ownerOf[id] = msg.sender;
        emit Transfer(address(0), msg.sender, id);
    }

    /*//////////////////////////////////////////////////////////////
                                ERC-721
    //////////////////////////////////////////////////////////////*/

    function ownerOf(uint256 id) public view returns (address owner) {
        require((owner = _ownerOf[id]) != address(0), "NOT_MINTED");
    }

    function balanceOf(address owner) public view returns (uint256) {
        require(owner != address(0), "ZERO_ADDRESS");
        return _balanceOf[owner];
    }

    function approve(address spender, uint256 id) public {
        address owner = _ownerOf[id];
        require(msg.sender == owner || isApprovedForAll[owner][msg.sender], "NOT_AUTHORIZED");
        getApproved[id] = spender;
        emit Approval(owner, spender, id);
    }

    function setApprovalForAll(address operator, bool approved) public {
        isApprovedForAll[msg.sender][operator] = approved;
        emit ApprovalForAll(msg.sender, operator, approved);
    }

    function transferFrom(address from, address to, uint256 id) public {
        require(from == _ownerOf[id], "WRONG_FROM");
        require(to != address(0), "INVALID_RECIPIENT");
        require(
            msg.sender == from || isApprovedForAll[from][msg.sender] || msg.sender == getApproved[id],
            "NOT_AUTHORIZED"
        );
        unchecked {
            _balanceOf[from]--;
            _balanceOf[to]++;
        }
        _ownerOf[id] = to;
        delete getApproved[id];
        emit Transfer(from, to, id);
    }

    function safeTransferFrom(address from, address to, uint256 id) public {
        transferFrom(from, to, id);
        require(
            to.code.length == 0 ||
                ERC721TokenReceiver(to).onERC721Received(msg.sender, from, id, "") ==
                ERC721TokenReceiver.onERC721Received.selector,
            "UNSAFE_RECIPIENT"
        );
    }

    function safeTransferFrom(address from, address to, uint256 id, bytes calldata data) public {
        transferFrom(from, to, id);
        require(
            to.code.length == 0 ||
                ERC721TokenReceiver(to).onERC721Received(msg.sender, from, id, data) ==
                ERC721TokenReceiver.onERC721Received.selector,
            "UNSAFE_RECIPIENT"
        );
    }

    function supportsInterface(bytes4 id) public pure returns (bool) {
        return id == 0x01ffc9a7 || id == 0x80ac58cd || id == 0x5b5e139f; // ERC165, ERC721, ERC721Metadata
    }

    /*//////////////////////////////////////////////////////////////
                          ON-CHAIN ART / METADATA
    //////////////////////////////////////////////////////////////*/

    function tokenURI(uint256 id) public view returns (string memory) {
        require(_ownerOf[id] != address(0), "NOT_MINTED");
        return string(abi.encodePacked("data:application/json;base64,", Base64.encode(bytes(_json(id)))));
    }

    function _json(uint256 id) internal pure returns (string memory) {
        return
            string(
                abi.encodePacked(
                    '{"name":"Inaria Fox #',
                    id.toString(),
                    '","description":"A kitsune of Inaria, drawn fully on-chain. inaria.xyz",',
                    '"image":"data:image/svg+xml;base64,',
                    Base64.encode(bytes(_svg(id))),
                    '"}'
                )
            );
    }

    function contractURI() public pure returns (string memory) {
        string memory json =
            '{"name":"Inaria Foxes","description":"The kitsune of Inaria. Fully on-chain ERC-721. inaria.xyz","external_link":"https://inaria.xyz"}';
        return string(abi.encodePacked("data:application/json;base64,", Base64.encode(bytes(json))));
    }

    function _fur(uint256 i) internal pure returns (string memory) {
        if (i == 0) return "#e0533a";
        if (i == 1) return "#c23f29";
        if (i == 2) return "#e8843a";
        if (i == 3) return "#9a3320";
        return "#d96a4a";
    }

    function _bg(uint256 i) internal pure returns (string memory) {
        if (i == 0) return "#1b0a06";
        if (i == 1) return "#10131a";
        if (i == 2) return "#241010";
        if (i == 3) return "#0d0605";
        return "#2a1209";
    }

    function _svg(uint256 id) internal pure returns (string memory) {
        uint256 h = uint256(keccak256(abi.encodePacked("inaria-fox", id)));
        return string(abi.encodePacked(_svgA(h), _svgB(h)));
    }

    function _svgA(uint256 h) internal pure returns (string memory) {
        string memory fur = _fur(h % 5);
        return
            string(
                abi.encodePacked(
                    '<svg xmlns="http://www.w3.org/2000/svg" width="500" height="500" viewBox="0 0 400 420">',
                    '<rect width="400" height="420" fill="', _bg((h >> 8) % 5), '"/>',
                    '<polygon points="120,40 95,185 205,150" fill="', fur,
                    '"/><polygon points="280,40 305,185 195,150" fill="', fur, '"/>',
                    '<polygon points="124,78 114,165 182,150" fill="#f4e8cc"/><polygon points="276,78 286,165 218,150" fill="#f4e8cc"/>',
                    '<polygon points="130,150 270,150 320,250 250,332 200,384 150,332 80,250" fill="', fur, '"/>'
                )
            );
    }

    function _svgB(uint256 h) internal pure returns (string memory) {
        string memory eye = ((h >> 16) % 2 == 0) ? "#f7d06b" : "#f4e8cc";
        return
            string(
                abi.encodePacked(
                    '<polygon points="160,300 240,300 200,386" fill="#f4e8cc"/>',
                    '<polygon points="150,236 196,224 190,256 150,260" fill="', eye,
                    '"/><polygon points="250,236 204,224 210,256 250,260" fill="', eye, '"/>',
                    '<polygon points="168,240 188,236 184,254 168,255" fill="#2a1209"/><polygon points="232,240 212,236 216,254 232,255" fill="#2a1209"/>',
                    '<polygon points="190,360 210,360 200,380" fill="#2a1209"/></svg>'
                )
            );
    }
}
Compiler settingsShow
{
  "libraries": {},
  "optimizer": {
    "runs": 200,
    "enabled": true
  }
}

Source code and metadata: Sourcify.

The source code belongs to the authors of the contract.