Cryo Explorer Ethereum Mainnet

Address Contract Partially Verified

Address 0x5537d90A4A2DC9d9b37BAb49B490cF67D4C54E91
Balance 0 ETH
Nonce 1
Code Size 9173 bytes
Indexed Transactions 0
External Etherscan · Sourcify

Contract Bytecode

9173 bytes
0x608060405234801561001057600080fd5b50600436106101a35760003560e01c80638da5cb5b116100ee578063b88d4fde11610097578063e14ca35311610071578063e14ca3531461031e578063e8a3d48514610326578063e985e9c51461032e578063f2fde38b14610341576101a3565b8063b88d4fde146102e5578063c87b56dd146102f8578063ddeae0331461030b576101a3565b80639f181b5e116100c85780639f181b5e146102c2578063a22cb465146102ca578063aa3ec0a9146102dd576101a3565b80638da5cb5b1461029f578063938e3d7b146102a757806395d89b41146102ba576101a3565b806342842e0e116101505780636352211e1161012a5780636352211e1461027157806370a0823114610284578063715018a614610297576101a3565b806342842e0e1461024357806342ec38e2146102565780634e71d92d14610269576101a3565b8063095ea7b311610181578063095ea7b31461020657806318160ddd1461021b57806323b872dd14610230576101a3565b806301ffc9a7146101a857806306fdde03146101d1578063081812fc146101e6575b600080fd5b6101bb6101b6366004611942565b610354565b6040516101c89190611bf3565b60405180910390f35b6101d96103ce565b6040516101c89190611bfe565b6101f96101f43660046119c0565b610460565b6040516101c89190611ba3565b6102196102143660046118fd565b6104ac565b005b610223610544565b6040516101c8919061224b565b61021961023e366004611813565b61054a565b610219610251366004611813565b610582565b6102236102643660046117c0565b61059d565b6102196105f7565b6101f961027f3660046119c0565b610602565b6102236102923660046117c0565b610637565b61021961067b565b6101f96106c4565b6102196102b536600461197a565b6106d3565b6101d9610729565b610223610738565b6102196102d83660046118c7565b610749565b6101d9610817565b6102196102f336600461184e565b6108a5565b6101d96103063660046119c0565b6108e4565b6102196103193660046117c0565b6108ef565b6102236108fb565b6101d9610917565b6101bb61033c3660046117e1565b610926565b61021961034f3660046117c0565b610954565b60006001600160e01b031982167f80ac58cd0000000000000000000000000000000000000000000000000000000014806103b757506001600160e01b031982167f5b5e139f00000000000000000000000000000000000000000000000000000000145b806103c657506103c6826109c2565b90505b919050565b6060600080546103dd906122cf565b80601f0160208091040260200160405190810160405280929190818152602001828054610409906122cf565b80156104565780601f1061042b57610100808354040283529160200191610456565b820191906000526020600020905b81548152906001019060200180831161043957829003601f168201915b5050505050905090565b600061046b826109f4565b6104905760405162461bcd60e51b815260040161048790611ff9565b60405180910390fd5b506000908152600460205260409020546001600160a01b031690565b60006104b782610602565b9050806001600160a01b0316836001600160a01b031614156104eb5760405162461bcd60e51b815260040161048790612134565b806001600160a01b03166104fd610a11565b6001600160a01b0316148061051957506105198161033c610a11565b6105355760405162461bcd60e51b815260040161048790611ead565b61053f8383610a15565b505050565b60085490565b61055b610555610a11565b82610a90565b6105775760405162461bcd60e51b815260040161048790612191565b61053f838383610b15565b61053f838383604051806020016040528060008152506108a5565b6001600160a01b0381166000908152600660205260408120546105d25760405162461bcd60e51b815260040161048790611d02565b6001600160a01b0382166000908152600660205260409020546103c69060019061228c565b61060033610b20565b565b6000818152600260205260408120546001600160a01b0316806103c65760405162461bcd60e51b815260040161048790611f67565b60006001600160a01b03821661065f5760405162461bcd60e51b815260040161048790611f0a565b506001600160a01b031660009081526003602052604090205490565b610683610a11565b6001600160a01b03166106946106c4565b6001600160a01b0316146106ba5760405162461bcd60e51b815260040161048790612045565b6106006000610cd9565b600c546001600160a01b031690565b6106db610a11565b6001600160a01b03166106ec6106c4565b6001600160a01b0316146107125760405162461bcd60e51b815260040161048790612045565b805161072590600d9060208401906116a0565b5050565b6060600180546103dd906122cf565b60006107446007610d38565b905090565b610751610a11565b6001600160a01b0316826001600160a01b031614156107825760405162461bcd60e51b815260040161048790611d96565b806005600061078f610a11565b6001600160a01b03908116825260208083019390935260409182016000908120918716808252919093529120805460ff1916921515929092179091556107d3610a11565b6001600160a01b03167f17307eab39ab6107e8899845ad3d59bd9653f200f220920489ca2b5937696c318360405161080b9190611bf3565b60405180910390a35050565b600b8054610824906122cf565b80601f0160208091040260200160405190810160405280929190818152602001828054610850906122cf565b801561089d5780601f106108725761010080835404028352916020019161089d565b820191906000526020600020905b81548152906001019060200180831161088057829003601f168201915b505050505081565b6108b66108b0610a11565b83610a90565b6108d25760405162461bcd60e51b815260040161048790612191565b6108de84848484610d3c565b50505050565b60606103c682610d6f565b6108f881610b20565b50565b6000610905610738565b61090d610544565b610744919061228c565b6060600d80546103dd906122cf565b6001600160a01b03918216600090815260056020908152604080832093909416825291909152205460ff1690565b61095c610a11565b6001600160a01b031661096d6106c4565b6001600160a01b0316146109935760405162461bcd60e51b815260040161048790612045565b6001600160a01b0381166109b95760405162461bcd60e51b815260040161048790611c6e565b6108f881610cd9565b6001600160e01b031981167f01ffc9a70000000000000000000000000000000000000000000000000000000014919050565b6000908152600260205260409020546001600160a01b0316151590565b3390565b6000818152600460205260409020805473ffffffffffffffffffffffffffffffffffffffff19166001600160a01b0384169081179091558190610a5782610602565b6001600160a01b03167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b92560405160405180910390a45050565b6000610a9b826109f4565b610ab75760405162461bcd60e51b815260040161048790611e61565b6000610ac283610602565b9050806001600160a01b0316846001600160a01b03161480610afd5750836001600160a01b0316610af284610460565b6001600160a01b0316145b80610b0d5750610b0d8185610926565b949350505050565b61053f838383610dce565b6000610b2a6108fb565b11610b475760405162461bcd60e51b815260040161048790611dcd565b604051632369730560e21b815281907332336a625aacfa08fe9723d901fff92a7e3465c190638da5cc1490610b80908490600401611ba3565b60206040518083038186803b158015610b9857600080fd5b505af4158015610bac573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610bd09190611926565b15610c0b576001600160a01b03811660009081526006602052604090205415610c0b5760405162461bcd60e51b815260040161048790611e04565b600e546040517f70a082310000000000000000000000000000000000000000000000000000000081526001600160a01b039091169081906370a0823190610c56908690600401611ba3565b60206040518083038186803b158015610c6e57600080fd5b505afa158015610c82573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610ca691906119d8565b15610cc35760405162461bcd60e51b8152600401610487906121ee565b6000610ccd610ee3565b90506108de848261102a565b600c80546001600160a01b0383811673ffffffffffffffffffffffffffffffffffffffff19831681179093556040519116919082907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e090600090a35050565b5490565b610d47848484610b15565b610d5384848484611044565b6108de5760405162461bcd60e51b815260040161048790611c11565b6060610d7a826109f4565b610d965760405162461bcd60e51b8152600401610487906120d7565b610d9e611178565b610da783611182565b604051602001610db8929190611a57565b6040516020818303038152906040529050919050565b604051632369730560e21b815282907332336a625aacfa08fe9723d901fff92a7e3465c190638da5cc1490610e07908490600401611ba3565b60206040518083038186803b158015610e1f57600080fd5b505af4158015610e33573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610e579190611926565b15610e92576001600160a01b03811660009081526006602052604090205415610e925760405162461bcd60e51b815260040161048790611e04565b610e9d8484846112d1565b6001600160a01b038416600090815260066020526040812055610ec1826001612260565b6001600160a01b03909316600090815260066020526040902092909255505050565b600080610eee6108fb565b11610f0b5760405162461bcd60e51b815260040161048790611dcd565b6000610f15610738565b610f1d610544565b610f27919061228c565b90506000813341444542604051602001610f45959493929190611a1c565b6040516020818303038152906040528051906020012060001c610f689190612325565b60008181526009602052604081205491925090610f86575080610f97565b506000818152600960205260409020545b60096000610fa660018661228c565b81526020019081526020016000205460001415610fdc57610fc860018461228c565b60008381526009602052604090205561100c565b60096000610feb60018661228c565b81526020808201929092526040908101600090812054858252600990935220555b61101461140b565b50600a546110229082612260565b935050505090565b61072582826040518060200160405280600081525061144b565b6000611058846001600160a01b031661147e565b1561116d57836001600160a01b031663150b7a02611074610a11565b8786866040518563ffffffff1660e01b81526004016110969493929190611bb7565b602060405180830381600087803b1580156110b057600080fd5b505af19250505080156110e0575060408051601f3d908101601f191682019092526110dd9181019061195e565b60015b61113a573d80801561110e576040519150601f19603f3d011682016040523d82523d6000602084013e611113565b606091505b5080516111325760405162461bcd60e51b815260040161048790611c11565b805181602001fd5b6001600160e01b0319167f150b7a0200000000000000000000000000000000000000000000000000000000149050610b0d565b506001949350505050565b6060610744611484565b6060816111c3575060408051808201909152600181527f300000000000000000000000000000000000000000000000000000000000000060208201526103c9565b8160005b81156111ed57806111d78161230a565b91506111e69050600a83612278565b91506111c7565b60008167ffffffffffffffff81111561121657634e487b7160e01b600052604160045260246000fd5b6040519080825280601f01601f191660200182016040528015611240576020820181803683370190505b5090505b8415610b0d5761125560018361228c565b9150611262600a86612325565b61126d906030612260565b60f81b81838151811061129057634e487b7160e01b600052603260045260246000fd5b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916908160001a9053506112ca600a86612278565b9450611244565b826001600160a01b03166112e482610602565b6001600160a01b03161461130a5760405162461bcd60e51b81526004016104879061207a565b6001600160a01b0382166113305760405162461bcd60e51b815260040161048790611d39565b61133b83838361053f565b611346600082610a15565b6001600160a01b038316600090815260036020526040812080546001929061136f90849061228c565b90915550506001600160a01b038216600090815260036020526040812080546001929061139d908490612260565b9091555050600081815260026020526040808220805473ffffffffffffffffffffffffffffffffffffffff19166001600160a01b0386811691821790925591518493918716917fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef91a4505050565b6000806114166108fb565b116114335760405162461bcd60e51b815260040161048790611dcd565b600061143f6007610d38565b905061074460076114ac565b61145583836114b5565b6114626000848484611044565b61053f5760405162461bcd60e51b815260040161048790611c11565b3b151590565b6060600b6040516020016114989190611ad9565b604051602081830303815290604052905090565b80546001019055565b6107258282604051632369730560e21b815282907332336a625aacfa08fe9723d901fff92a7e3465c190638da5cc14906114f3908490600401611ba3565b60206040518083038186803b15801561150b57600080fd5b505af415801561151f573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906115439190611926565b1561157e576001600160a01b0381166000908152600660205260409020541561157e5760405162461bcd60e51b815260040161048790611e04565b61158883836115b4565b611593826001612260565b6001600160a01b039093166000908152600660205260409020929092555050565b6001600160a01b0382166115da5760405162461bcd60e51b815260040161048790611fc4565b6115e3816109f4565b156116005760405162461bcd60e51b815260040161048790611ccb565b61160c6000838361053f565b6001600160a01b0382166000908152600360205260408120805460019290611635908490612260565b9091555050600081815260026020526040808220805473ffffffffffffffffffffffffffffffffffffffff19166001600160a01b03861690811790915590518392907fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef908290a45050565b8280546116ac906122cf565b90600052602060002090601f0160209004810192826116ce5760008555611714565b82601f106116e757805160ff1916838001178555611714565b82800160010185558215611714579182015b828111156117145782518255916020019190600101906116f9565b50611720929150611724565b5090565b5b808211156117205760008155600101611725565b600067ffffffffffffffff8084111561175457611754612365565b604051601f8501601f19168101602001828111828210171561177857611778612365565b60405284815291508183850186101561179057600080fd5b8484602083013760006020868301015250509392505050565b80356001600160a01b03811681146103c957600080fd5b6000602082840312156117d1578081fd5b6117da826117a9565b9392505050565b600080604083850312156117f3578081fd5b6117fc836117a9565b915061180a602084016117a9565b90509250929050565b600080600060608486031215611827578081fd5b611830846117a9565b925061183e602085016117a9565b9150604084013590509250925092565b60008060008060808587031215611863578081fd5b61186c856117a9565b935061187a602086016117a9565b925060408501359150606085013567ffffffffffffffff81111561189c578182fd5b8501601f810187136118ac578182fd5b6118bb87823560208401611739565b91505092959194509250565b600080604083850312156118d9578182fd5b6118e2836117a9565b915060208301356118f28161237b565b809150509250929050565b6000806040838503121561190f578182fd5b611918836117a9565b946020939093013593505050565b600060208284031215611937578081fd5b81516117da8161237b565b600060208284031215611953578081fd5b81356117da81612389565b60006020828403121561196f578081fd5b81516117da81612389565b60006020828403121561198b578081fd5b813567ffffffffffffffff8111156119a1578182fd5b8201601f810184136119b1578182fd5b610b0d84823560208401611739565b6000602082840312156119d1578081fd5b5035919050565b6000602082840312156119e9578081fd5b5051919050565b60008151808452611a088160208601602086016122a3565b601f01601f19169290920160200192915050565b6bffffffffffffffffffffffff19606096871b811682529490951b909316601485015260288401919091526048830152606882015260880190565b60008351611a698184602088016122a3565b7f2f000000000000000000000000000000000000000000000000000000000000009083019081528351611aa38160018401602088016122a3565b7f2f6d657461646174612e6a736f6e00000000000000000000000000000000000060019290910191820152600f01949350505050565b60007f697066733a2f2f000000000000000000000000000000000000000000000000008252600781845483600282049050600180831680611b1b57607f831692505b6020808410821415611b3b57634e487b7160e01b88526022600452602488fd5b818015611b4f5760018114611b6457611b94565b60ff1986168a890152848a0188019650611b94565b611b6d8b612254565b895b86811015611b8a5781548c82018b0152908501908301611b6f565b505087858b010196505b50949998505050505050505050565b6001600160a01b0391909116815260200190565b60006001600160a01b03808716835280861660208401525083604083015260806060830152611be960808301846119f0565b9695505050505050565b901515815260200190565b6000602082526117da60208301846119f0565b60208082526032908201527f4552433732313a207472616e7366657220746f206e6f6e20455243373231526560408201527f63656976657220696d706c656d656e7465720000000000000000000000000000606082015260800190565b60208082526026908201527f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160408201527f6464726573730000000000000000000000000000000000000000000000000000606082015260800190565b6020808252601c908201527f4552433732313a20746f6b656e20616c7265616479206d696e74656400000000604082015260600190565b6020808252601a908201527f4e6f20746f6b656e20666f722074686973206163636f756e742e000000000000604082015260600190565b60208082526024908201527f4552433732313a207472616e7366657220746f20746865207a65726f2061646460408201527f7265737300000000000000000000000000000000000000000000000000000000606082015260800190565b60208082526019908201527f4552433732313a20617070726f766520746f2063616c6c657200000000000000604082015260600190565b60208082526018908201527f4e6f206d6f726520746f6b656e7320617661696c61626c650000000000000000604082015260600190565b60208082526022908201527f43616e206f6e6c7920686f6c64206f6e6520746f6b656e207065722077616c6c60408201527f6574000000000000000000000000000000000000000000000000000000000000606082015260800190565b6020808252602c908201527f4552433732313a206f70657261746f7220717565727920666f72206e6f6e657860408201526b34b9ba32b73a103a37b5b2b760a11b606082015260800190565b60208082526038908201527f4552433732313a20617070726f76652063616c6c6572206973206e6f74206f7760408201527f6e6572206e6f7220617070726f76656420666f7220616c6c0000000000000000606082015260800190565b6020808252602a908201527f4552433732313a2062616c616e636520717565727920666f7220746865207a6560408201527f726f206164647265737300000000000000000000000000000000000000000000606082015260800190565b60208082526029908201527f4552433732313a206f776e657220717565727920666f72206e6f6e657869737460408201527f656e7420746f6b656e0000000000000000000000000000000000000000000000606082015260800190565b6020808252818101527f4552433732313a206d696e7420746f20746865207a65726f2061646472657373604082015260600190565b6020808252602c908201527f4552433732313a20617070726f76656420717565727920666f72206e6f6e657860408201526b34b9ba32b73a103a37b5b2b760a11b606082015260800190565b6020808252818101527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604082015260600190565b60208082526029908201527f4552433732313a207472616e73666572206f6620746f6b656e2074686174206960408201527f73206e6f74206f776e0000000000000000000000000000000000000000000000606082015260800190565b6020808252602f908201527f4552433732314d657461646174613a2055524920717565727920666f72206e6f60408201527f6e6578697374656e7420746f6b656e0000000000000000000000000000000000606082015260800190565b60208082526021908201527f4552433732313a20617070726f76616c20746f2063757272656e74206f776e6560408201527f7200000000000000000000000000000000000000000000000000000000000000606082015260800190565b60208082526031908201527f4552433732313a207472616e736665722063616c6c6572206973206e6f74206f60408201527f776e6572206e6f7220617070726f766564000000000000000000000000000000606082015260800190565b60208082526028908201527f596f75206c75636b79206f6e6520616c7265616479206861766520612043727960408201527f70746f50756e6b2e000000000000000000000000000000000000000000000000606082015260800190565b90815260200190565b60009081526020902090565b6000821982111561227357612273612339565b500190565b6000826122875761228761234f565b500490565b60008282101561229e5761229e612339565b500390565b60005b838110156122be5781810151838201526020016122a6565b838111156108de5750506000910152565b6002810460018216806122e357607f821691505b6020821081141561230457634e487b7160e01b600052602260045260246000fd5b50919050565b600060001982141561231e5761231e612339565b5060010190565b6000826123345761233461234f565b500690565b634e487b7160e01b600052601160045260246000fd5b634e487b7160e01b600052601260045260246000fd5b634e487b7160e01b600052604160045260246000fd5b80151581146108f857600080fd5b6001600160e01b0319811681146108f857600080fdfea2646970667358221220a1dbf969170fc3f83d7f4980699e76878da583fd98a61a69b9cbe2f5c5010fe364736f6c63430008000033

Verified Source Code Partial Match

Compiler: v0.8.0+commit.c7dfd78e EVM: istanbul Optimization: Yes (1000 runs)
OneDayPunk.sol 95 lines
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

import "@1001-digital/erc721-extensions/contracts/RandomlyAssigned.sol";
import "@1001-digital/erc721-extensions/contracts/WithContractMetaData.sol";
import "@1001-digital/erc721-extensions/contracts/WithIPFSMetaData.sol";
import "@1001-digital/erc721-extensions/contracts/OnePerWallet.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
import "@openzeppelin/contracts/token/ERC721/ERC721.sol";
import "@openzeppelin/contracts/token/ERC721/IERC721.sol";

import "./CryptoPunkInterface.sol";

// ====================================================================================================================== //
//    ______     __   __     ______        _____     ______     __  __        ______   __  __     __   __     __  __      //
//   /\  __ \   /\ "-.\ \   /\  ___\      /\  __-.  /\  __ \   /\ \_\ \      /\  == \ /\ \/\ \   /\ "-.\ \   /\ \/ /      //
//   \ \ \/\ \  \ \ \-.  \  \ \  __\      \ \ \/\ \ \ \  __ \  \ \____ \     \ \  _-/ \ \ \_\ \  \ \ \-.  \  \ \  _"-.    //
//    \ \_____\  \ \_\\"\_\  \ \_____\     \ \____-  \ \_\ \_\  \/\_____\     \ \_\    \ \_____\  \ \_\\"\_\  \ \_\ \_\   //
//     \/_____/   \/_/ \/_/   \/_____/      \/____/   \/_/\/_/   \/_____/      \/_/     \/_____/   \/_/ \/_/   \/_/\/_/   //
//                                                                                                                        //
// ====================================================================================================================== //
//                                           10k "ONE DAY I'LL BE A PUNK"-punks                                           //
//                                              limited to one per address                                                //
//                                                    aim high, fren!                                                     //
// ====================================================================================================================== //
contract OneDayPunk is
    ERC721,
    OnePerWallet,
    RandomlyAssigned,
    WithIPFSMetaData,
    WithContractMetaData
{
    address private cryptoPunksAddress;

    // Instantiate the PunkScape Contract
    constructor(
        string memory _cid,
        string memory _contractMetaDataURI,
        address _cryptopunksAddress
    )
        ERC721("OneDayPunk", "ODP")
        RandomlyAssigned(10000, 0)
        WithIPFSMetaData(_cid)
        WithContractMetaData(_contractMetaDataURI)
    {
        cryptoPunksAddress = _cryptopunksAddress;
    }

    // Claim a "One Day I'll Be A Punk"-Punk
    function claim() external {
        _claim(msg.sender);
    }

    // Claim a "One Day I'll Be A Punk"-Punk to a specific address
    function claimFor(address to) external {
        _claim(to);
    }

    // Claims a token for a specific address.
    function _claim (address to) internal ensureAvailability onePerWallet(to) {
        CryptoPunks cryptopunks = CryptoPunks(cryptoPunksAddress);
        require(cryptopunks.balanceOf(to) == 0, "You lucky one already have a CryptoPunk.");

        uint256 next = nextToken();

        _safeMint(to, next);
    }

    // Get the tokenURI for a specific token
    function tokenURI(uint256 tokenId)
        public view override(WithIPFSMetaData, ERC721)
        returns (string memory)
    {
        return WithIPFSMetaData.tokenURI(tokenId);
    }

    // Configure the baseURI for the tokenURI method.
    function _baseURI()
        internal view override(WithIPFSMetaData, ERC721)
        returns (string memory)
    {
        return WithIPFSMetaData._baseURI();
    }

    // Mark OnePerWallet implementation as override for ERC721, OnePerWallet
    function _mint(address to, uint256 tokenId) internal override(ERC721, OnePerWallet) {
        OnePerWallet._mint(to, tokenId);
    }

    // Mark OnePerWallet implementation as override for ERC721, OnePerWallet
    function _transfer(address from, address to, uint256 tokenId) internal override(ERC721, OnePerWallet) {
        OnePerWallet._transfer(from, to, tokenId);
    }

}
CryptoPunkInterface.sol 7 lines
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

interface CryptoPunks {
    function balanceOf(address owner) external view returns(uint256);
    function punkIndexToAddress(uint index) external view returns(address);
}
Address.sol 216 lines
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

/**
 * @dev Collection of functions related to the address type
 */
library Address {
    /**
     * @dev Returns true if `account` is a contract.
     *
     * [IMPORTANT]
     * ====
     * It is unsafe to assume that an address for which this function returns
     * false is an externally-owned account (EOA) and not a contract.
     *
     * Among others, `isContract` will return false for the following
     * types of addresses:
     *
     *  - an externally-owned account
     *  - a contract in construction
     *  - an address where a contract will be created
     *  - an address where a contract lived, but was destroyed
     * ====
     */
    function isContract(address account) internal view returns (bool) {
        // This method relies on extcodesize, which returns 0 for contracts in
        // construction, since the code is only stored at the end of the
        // constructor execution.

        uint256 size;
        assembly {
            size := extcodesize(account)
        }
        return size > 0;
    }

    /**
     * @dev Replacement for Solidity's `transfer`: sends `amount` wei to
     * `recipient`, forwarding all available gas and reverting on errors.
     *
     * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost
     * of certain opcodes, possibly making contracts go over the 2300 gas limit
     * imposed by `transfer`, making them unable to receive funds via
     * `transfer`. {sendValue} removes this limitation.
     *
     * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more].
     *
     * IMPORTANT: because control is transferred to `recipient`, care must be
     * taken to not create reentrancy vulnerabilities. Consider using
     * {ReentrancyGuard} or the
     * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].
     */
    function sendValue(address payable recipient, uint256 amount) internal {
        require(address(this).balance >= amount, "Address: insufficient balance");

        (bool success, ) = recipient.call{value: amount}("");
        require(success, "Address: unable to send value, recipient may have reverted");
    }

    /**
     * @dev Performs a Solidity function call using a low level `call`. A
     * plain `call` is an unsafe replacement for a function call: use this
     * function instead.
     *
     * If `target` reverts with a revert reason, it is bubbled up by this
     * function (like regular Solidity function calls).
     *
     * Returns the raw returned data. To convert to the expected return value,
     * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].
     *
     * Requirements:
     *
     * - `target` must be a contract.
     * - calling `target` with `data` must not revert.
     *
     * _Available since v3.1._
     */
    function functionCall(address target, bytes memory data) internal returns (bytes memory) {
        return functionCall(target, data, "Address: low-level call failed");
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with
     * `errorMessage` as a fallback revert reason when `target` reverts.
     *
     * _Available since v3.1._
     */
    function functionCall(
        address target,
        bytes memory data,
        string memory errorMessage
    ) internal returns (bytes memory) {
        return functionCallWithValue(target, data, 0, errorMessage);
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
     * but also transferring `value` wei to `target`.
     *
     * Requirements:
     *
     * - the calling contract must have an ETH balance of at least `value`.
     * - the called Solidity function must be `payable`.
     *
     * _Available since v3.1._
     */
    function functionCallWithValue(
        address target,
        bytes memory data,
        uint256 value
    ) internal returns (bytes memory) {
        return functionCallWithValue(target, data, value, "Address: low-level call with value failed");
    }

    /**
     * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but
     * with `errorMessage` as a fallback revert reason when `target` reverts.
     *
     * _Available since v3.1._
     */
    function functionCallWithValue(
        address target,
        bytes memory data,
        uint256 value,
        string memory errorMessage
    ) internal returns (bytes memory) {
        require(address(this).balance >= value, "Address: insufficient balance for call");
        require(isContract(target), "Address: call to non-contract");

        (bool success, bytes memory returndata) = target.call{value: value}(data);
        return verifyCallResult(success, returndata, errorMessage);
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
     * but performing a static call.
     *
     * _Available since v3.3._
     */
    function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {
        return functionStaticCall(target, data, "Address: low-level static call failed");
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
     * but performing a static call.
     *
     * _Available since v3.3._
     */
    function functionStaticCall(
        address target,
        bytes memory data,
        string memory errorMessage
    ) internal view returns (bytes memory) {
        require(isContract(target), "Address: static call to non-contract");

        (bool success, bytes memory returndata) = target.staticcall(data);
        return verifyCallResult(success, returndata, errorMessage);
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
     * but performing a delegate call.
     *
     * _Available since v3.4._
     */
    function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) {
        return functionDelegateCall(target, data, "Address: low-level delegate call failed");
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
     * but performing a delegate call.
     *
     * _Available since v3.4._
     */
    function functionDelegateCall(
        address target,
        bytes memory data,
        string memory errorMessage
    ) internal returns (bytes memory) {
        require(isContract(target), "Address: delegate call to non-contract");

        (bool success, bytes memory returndata) = target.delegatecall(data);
        return verifyCallResult(success, returndata, errorMessage);
    }

    /**
     * @dev Tool to verifies that a low level call was successful, and revert if it wasn't, either by bubbling the
     * revert reason using the provided one.
     *
     * _Available since v4.3._
     */
    function verifyCallResult(
        bool success,
        bytes memory returndata,
        string memory errorMessage
    ) internal pure returns (bytes memory) {
        if (success) {
            return returndata;
        } else {
            // Look for revert reason and bubble it up if present
            if (returndata.length > 0) {
                // The easiest way to bubble the revert reason is using memory via assembly

                assembly {
                    let returndata_size := mload(returndata)
                    revert(add(32, returndata), returndata_size)
                }
            } else {
                revert(errorMessage);
            }
        }
    }
}
Context.sol 23 lines
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

/**
 * @dev Provides information about the current execution context, including the
 * sender of the transaction and its data. While these are generally available
 * via msg.sender and msg.data, they should not be accessed in such a direct
 * manner, since when dealing with meta-transactions the account sending and
 * paying for execution may not be the actual sender (as far as an application
 * is concerned).
 *
 * This contract is only required for intermediate, library-like contracts.
 */
abstract contract Context {
    function _msgSender() internal view virtual returns (address) {
        return msg.sender;
    }

    function _msgData() internal view virtual returns (bytes calldata) {
        return msg.data;
    }
}
Strings.sol 66 lines
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

/**
 * @dev String operations.
 */
library Strings {
    bytes16 private constant _HEX_SYMBOLS = "0123456789abcdef";

    /**
     * @dev Converts a `uint256` to its ASCII `string` decimal representation.
     */
    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);
    }

    /**
     * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation.
     */
    function toHexString(uint256 value) internal pure returns (string memory) {
        if (value == 0) {
            return "0x00";
        }
        uint256 temp = value;
        uint256 length = 0;
        while (temp != 0) {
            length++;
            temp >>= 8;
        }
        return toHexString(value, length);
    }

    /**
     * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation with fixed length.
     */
    function toHexString(uint256 value, uint256 length) internal pure returns (string memory) {
        bytes memory buffer = new bytes(2 * length + 2);
        buffer[0] = "0";
        buffer[1] = "x";
        for (uint256 i = 2 * length + 1; i > 1; --i) {
            buffer[i] = _HEX_SYMBOLS[value & 0xf];
            value >>= 4;
        }
        require(value == 0, "Strings: hex length insufficient");
        return string(buffer);
    }
}
Ownable.sol 71 lines
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

import "../utils/Context.sol";

/**
 * @dev Contract module which provides a basic access control mechanism, where
 * there is an account (an owner) that can be granted exclusive access to
 * specific functions.
 *
 * By default, the owner account will be the one that deploys the contract. This
 * can later be changed with {transferOwnership}.
 *
 * This module is used through inheritance. It will make available the modifier
 * `onlyOwner`, which can be applied to your functions to restrict their use to
 * the owner.
 */
abstract contract Ownable is Context {
    address private _owner;

    event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);

    /**
     * @dev Initializes the contract setting the deployer as the initial owner.
     */
    constructor() {
        _setOwner(_msgSender());
    }

    /**
     * @dev Returns the address of the current owner.
     */
    function owner() public view virtual returns (address) {
        return _owner;
    }

    /**
     * @dev Throws if called by any account other than the owner.
     */
    modifier onlyOwner() {
        require(owner() == _msgSender(), "Ownable: caller is not the owner");
        _;
    }

    /**
     * @dev Leaves the contract without owner. It will not be possible to call
     * `onlyOwner` functions anymore. Can only be called by the current owner.
     *
     * NOTE: Renouncing ownership will leave the contract without an owner,
     * thereby removing any functionality that is only available to the owner.
     */
    function renounceOwnership() public virtual onlyOwner {
        _setOwner(address(0));
    }

    /**
     * @dev Transfers ownership of the contract to a new account (`newOwner`).
     * Can only be called by the current owner.
     */
    function transferOwnership(address newOwner) public virtual onlyOwner {
        require(newOwner != address(0), "Ownable: new owner is the zero address");
        _setOwner(newOwner);
    }

    function _setOwner(address newOwner) private {
        address oldOwner = _owner;
        _owner = newOwner;
        emit OwnershipTransferred(oldOwner, newOwner);
    }
}
Counters.sol 42 lines
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

/**
 * @title Counters
 * @author Matt Condon (@shrugs)
 * @dev Provides counters that can only be incremented, decremented or reset. This can be used e.g. to track the number
 * of elements in a mapping, issuing ERC721 ids, or counting request ids.
 *
 * Include with `using Counters for Counters.Counter;`
 */
library Counters {
    struct Counter {
        // This variable should never be directly accessed by users of the library: interactions must be restricted to
        // the library's function. As of Solidity v0.5.2, this cannot be enforced, though there is a proposal to add
        // this feature: see https://github.com/ethereum/solidity/issues/4637
        uint256 _value; // default: 0
    }

    function current(Counter storage counter) internal view returns (uint256) {
        return counter._value;
    }

    function increment(Counter storage counter) internal {
        unchecked {
            counter._value += 1;
        }
    }

    function decrement(Counter storage counter) internal {
        uint256 value = counter._value;
        require(value > 0, "Counter: decrement overflow");
        unchecked {
            counter._value = value - 1;
        }
    }

    function reset(Counter storage counter) internal {
        counter._value = 0;
    }
}
ERC721.sol 411 lines
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

import "./IERC721.sol";
import "./IERC721Receiver.sol";
import "./extensions/IERC721Metadata.sol";
import "../../utils/Address.sol";
import "../../utils/Context.sol";
import "../../utils/Strings.sol";
import "../../utils/introspection/ERC165.sol";

/**
 * @dev Implementation of https://eips.ethereum.org/EIPS/eip-721[ERC721] Non-Fungible Token Standard, including
 * the Metadata extension, but not including the Enumerable extension, which is available separately as
 * {ERC721Enumerable}.
 */
contract ERC721 is Context, ERC165, IERC721, IERC721Metadata {
    using Address for address;
    using Strings for uint256;

    // Token name
    string private _name;

    // Token symbol
    string private _symbol;

    // Mapping from token ID to owner address
    mapping(uint256 => address) private _owners;

    // Mapping owner address to token count
    mapping(address => uint256) private _balances;

    // Mapping from token ID to approved address
    mapping(uint256 => address) private _tokenApprovals;

    // Mapping from owner to operator approvals
    mapping(address => mapping(address => bool)) private _operatorApprovals;

    /**
     * @dev Initializes the contract by setting a `name` and a `symbol` to the token collection.
     */
    constructor(string memory name_, string memory symbol_) {
        _name = name_;
        _symbol = symbol_;
    }

    /**
     * @dev See {IERC165-supportsInterface}.
     */
    function supportsInterface(bytes4 interfaceId) public view virtual override(ERC165, IERC165) returns (bool) {
        return
            interfaceId == type(IERC721).interfaceId ||
            interfaceId == type(IERC721Metadata).interfaceId ||
            super.supportsInterface(interfaceId);
    }

    /**
     * @dev See {IERC721-balanceOf}.
     */
    function balanceOf(address owner) public view virtual override returns (uint256) {
        require(owner != address(0), "ERC721: balance query for the zero address");
        return _balances[owner];
    }

    /**
     * @dev See {IERC721-ownerOf}.
     */
    function ownerOf(uint256 tokenId) public view virtual override returns (address) {
        address owner = _owners[tokenId];
        require(owner != address(0), "ERC721: owner query for nonexistent token");
        return owner;
    }

    /**
     * @dev See {IERC721Metadata-name}.
     */
    function name() public view virtual override returns (string memory) {
        return _name;
    }

    /**
     * @dev See {IERC721Metadata-symbol}.
     */
    function symbol() public view virtual override returns (string memory) {
        return _symbol;
    }

    /**
     * @dev See {IERC721Metadata-tokenURI}.
     */
    function tokenURI(uint256 tokenId) public view virtual override returns (string memory) {
        require(_exists(tokenId), "ERC721Metadata: URI query for nonexistent token");

        string memory baseURI = _baseURI();
        return bytes(baseURI).length > 0 ? string(abi.encodePacked(baseURI, tokenId.toString())) : "";
    }

    /**
     * @dev Base URI for computing {tokenURI}. If set, the resulting URI for each
     * token will be the concatenation of the `baseURI` and the `tokenId`. Empty
     * by default, can be overriden in child contracts.
     */
    function _baseURI() internal view virtual returns (string memory) {
        return "";
    }

    /**
     * @dev See {IERC721-approve}.
     */
    function approve(address to, uint256 tokenId) public virtual override {
        address owner = ERC721.ownerOf(tokenId);
        require(to != owner, "ERC721: approval to current owner");

        require(
            _msgSender() == owner || isApprovedForAll(owner, _msgSender()),
            "ERC721: approve caller is not owner nor approved for all"
        );

        _approve(to, tokenId);
    }

    /**
     * @dev See {IERC721-getApproved}.
     */
    function getApproved(uint256 tokenId) public view virtual override returns (address) {
        require(_exists(tokenId), "ERC721: approved query for nonexistent token");

        return _tokenApprovals[tokenId];
    }

    /**
     * @dev See {IERC721-setApprovalForAll}.
     */
    function setApprovalForAll(address operator, bool approved) public virtual override {
        require(operator != _msgSender(), "ERC721: approve to caller");

        _operatorApprovals[_msgSender()][operator] = approved;
        emit ApprovalForAll(_msgSender(), operator, approved);
    }

    /**
     * @dev See {IERC721-isApprovedForAll}.
     */
    function isApprovedForAll(address owner, address operator) public view virtual override returns (bool) {
        return _operatorApprovals[owner][operator];
    }

    /**
     * @dev See {IERC721-transferFrom}.
     */
    function transferFrom(
        address from,
        address to,
        uint256 tokenId
    ) public virtual override {
        //solhint-disable-next-line max-line-length
        require(_isApprovedOrOwner(_msgSender(), tokenId), "ERC721: transfer caller is not owner nor approved");

        _transfer(from, to, tokenId);
    }

    /**
     * @dev See {IERC721-safeTransferFrom}.
     */
    function safeTransferFrom(
        address from,
        address to,
        uint256 tokenId
    ) public virtual override {
        safeTransferFrom(from, to, tokenId, "");
    }

    /**
     * @dev See {IERC721-safeTransferFrom}.
     */
    function safeTransferFrom(
        address from,
        address to,
        uint256 tokenId,
        bytes memory _data
    ) public virtual override {
        require(_isApprovedOrOwner(_msgSender(), tokenId), "ERC721: transfer caller is not owner nor approved");
        _safeTransfer(from, to, tokenId, _data);
    }

    /**
     * @dev Safely transfers `tokenId` token from `from` to `to`, checking first that contract recipients
     * are aware of the ERC721 protocol to prevent tokens from being forever locked.
     *
     * `_data` is additional data, it has no specified format and it is sent in call to `to`.
     *
     * This internal function is equivalent to {safeTransferFrom}, and can be used to e.g.
     * implement alternative mechanisms to perform token transfer, such as signature-based.
     *
     * Requirements:
     *
     * - `from` cannot be the zero address.
     * - `to` cannot be the zero address.
     * - `tokenId` token must exist and be owned by `from`.
     * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer.
     *
     * Emits a {Transfer} event.
     */
    function _safeTransfer(
        address from,
        address to,
        uint256 tokenId,
        bytes memory _data
    ) internal virtual {
        _transfer(from, to, tokenId);
        require(_checkOnERC721Received(from, to, tokenId, _data), "ERC721: transfer to non ERC721Receiver implementer");
    }

    /**
     * @dev Returns whether `tokenId` exists.
     *
     * Tokens can be managed by their owner or approved accounts via {approve} or {setApprovalForAll}.
     *
     * Tokens start existing when they are minted (`_mint`),
     * and stop existing when they are burned (`_burn`).
     */
    function _exists(uint256 tokenId) internal view virtual returns (bool) {
        return _owners[tokenId] != address(0);
    }

    /**
     * @dev Returns whether `spender` is allowed to manage `tokenId`.
     *
     * Requirements:
     *
     * - `tokenId` must exist.
     */
    function _isApprovedOrOwner(address spender, uint256 tokenId) internal view virtual returns (bool) {
        require(_exists(tokenId), "ERC721: operator query for nonexistent token");
        address owner = ERC721.ownerOf(tokenId);
        return (spender == owner || getApproved(tokenId) == spender || isApprovedForAll(owner, spender));
    }

    /**
     * @dev Safely mints `tokenId` and transfers it to `to`.
     *
     * Requirements:
     *
     * - `tokenId` must not exist.
     * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer.
     *
     * Emits a {Transfer} event.
     */
    function _safeMint(address to, uint256 tokenId) internal virtual {
        _safeMint(to, tokenId, "");
    }

    /**
     * @dev Same as {xref-ERC721-_safeMint-address-uint256-}[`_safeMint`], with an additional `data` parameter which is
     * forwarded in {IERC721Receiver-onERC721Received} to contract recipients.
     */
    function _safeMint(
        address to,
        uint256 tokenId,
        bytes memory _data
    ) internal virtual {
        _mint(to, tokenId);
        require(
            _checkOnERC721Received(address(0), to, tokenId, _data),
            "ERC721: transfer to non ERC721Receiver implementer"
        );
    }

    /**
     * @dev Mints `tokenId` and transfers it to `to`.
     *
     * WARNING: Usage of this method is discouraged, use {_safeMint} whenever possible
     *
     * Requirements:
     *
     * - `tokenId` must not exist.
     * - `to` cannot be the zero address.
     *
     * Emits a {Transfer} event.
     */
    function _mint(address to, uint256 tokenId) internal virtual {
        require(to != address(0), "ERC721: mint to the zero address");
        require(!_exists(tokenId), "ERC721: token already minted");

        _beforeTokenTransfer(address(0), to, tokenId);

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

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

    /**
     * @dev Destroys `tokenId`.
     * The approval is cleared when the token is burned.
     *
     * Requirements:
     *
     * - `tokenId` must exist.
     *
     * Emits a {Transfer} event.
     */
    function _burn(uint256 tokenId) internal virtual {
        address owner = ERC721.ownerOf(tokenId);

        _beforeTokenTransfer(owner, address(0), tokenId);

        // Clear approvals
        _approve(address(0), tokenId);

        _balances[owner] -= 1;
        delete _owners[tokenId];

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

    /**
     * @dev Transfers `tokenId` from `from` to `to`.
     *  As opposed to {transferFrom}, this imposes no restrictions on msg.sender.
     *
     * Requirements:
     *
     * - `to` cannot be the zero address.
     * - `tokenId` token must be owned by `from`.
     *
     * Emits a {Transfer} event.
     */
    function _transfer(
        address from,
        address to,
        uint256 tokenId
    ) internal virtual {
        require(ERC721.ownerOf(tokenId) == from, "ERC721: transfer of token that is not own");
        require(to != address(0), "ERC721: transfer to the zero address");

        _beforeTokenTransfer(from, to, tokenId);

        // Clear approvals from the previous owner
        _approve(address(0), tokenId);

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

        emit Transfer(from, to, tokenId);
    }

    /**
     * @dev Approve `to` to operate on `tokenId`
     *
     * Emits a {Approval} event.
     */
    function _approve(address to, uint256 tokenId) internal virtual {
        _tokenApprovals[tokenId] = to;
        emit Approval(ERC721.ownerOf(tokenId), to, tokenId);
    }

    /**
     * @dev Internal function to invoke {IERC721Receiver-onERC721Received} on a target address.
     * The call is not executed if the target address is not a contract.
     *
     * @param from address representing the previous owner of the given token ID
     * @param to target address that will receive the tokens
     * @param tokenId uint256 ID of the token to be transferred
     * @param _data bytes optional data to send along with the call
     * @return bool whether the call correctly returned the expected magic value
     */
    function _checkOnERC721Received(
        address from,
        address to,
        uint256 tokenId,
        bytes memory _data
    ) private returns (bool) {
        if (to.isContract()) {
            try IERC721Receiver(to).onERC721Received(_msgSender(), from, tokenId, _data) returns (bytes4 retval) {
                return retval == IERC721Receiver.onERC721Received.selector;
            } catch (bytes memory reason) {
                if (reason.length == 0) {
                    revert("ERC721: transfer to non ERC721Receiver implementer");
                } else {
                    assembly {
                        revert(add(32, reason), mload(reason))
                    }
                }
            }
        } else {
            return true;
        }
    }

    /**
     * @dev Hook that is called before any token transfer. This includes minting
     * and burning.
     *
     * Calling conditions:
     *
     * - When `from` and `to` are both non-zero, ``from``'s `tokenId` will be
     * transferred to `to`.
     * - When `from` is zero, `tokenId` will be minted for `to`.
     * - When `to` is zero, ``from``'s `tokenId` will be burned.
     * - `from` and `to` are never both zero.
     *
     * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks].
     */
    function _beforeTokenTransfer(
        address from,
        address to,
        uint256 tokenId
    ) internal virtual {}
}
IERC721.sol 142 lines
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

import "../../utils/introspection/IERC165.sol";

/**
 * @dev Required interface of an ERC721 compliant contract.
 */
interface IERC721 is IERC165 {
    /**
     * @dev Emitted when `tokenId` token is transferred from `from` to `to`.
     */
    event Transfer(address indexed from, address indexed to, uint256 indexed tokenId);

    /**
     * @dev Emitted when `owner` enables `approved` to manage the `tokenId` token.
     */
    event Approval(address indexed owner, address indexed approved, uint256 indexed tokenId);

    /**
     * @dev Emitted when `owner` enables or disables (`approved`) `operator` to manage all of its assets.
     */
    event ApprovalForAll(address indexed owner, address indexed operator, bool approved);

    /**
     * @dev Returns the number of tokens in ``owner``'s account.
     */
    function balanceOf(address owner) external view returns (uint256 balance);

    /**
     * @dev Returns the owner of the `tokenId` token.
     *
     * Requirements:
     *
     * - `tokenId` must exist.
     */
    function ownerOf(uint256 tokenId) external view returns (address owner);

    /**
     * @dev Safely transfers `tokenId` token from `from` to `to`, checking first that contract recipients
     * are aware of the ERC721 protocol to prevent tokens from being forever locked.
     *
     * Requirements:
     *
     * - `from` cannot be the zero address.
     * - `to` cannot be the zero address.
     * - `tokenId` token must exist and be owned by `from`.
     * - If the caller is not `from`, it must be have been allowed to move this token by either {approve} or {setApprovalForAll}.
     * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer.
     *
     * Emits a {Transfer} event.
     */
    function safeTransferFrom(
        address from,
        address to,
        uint256 tokenId
    ) external;

    /**
     * @dev Transfers `tokenId` token from `from` to `to`.
     *
     * WARNING: Usage of this method is discouraged, use {safeTransferFrom} whenever possible.
     *
     * Requirements:
     *
     * - `from` cannot be the zero address.
     * - `to` cannot be the zero address.
     * - `tokenId` token must be owned by `from`.
     * - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}.
     *
     * Emits a {Transfer} event.
     */
    function transferFrom(
        address from,
        address to,
        uint256 tokenId
    ) external;

    /**
     * @dev Gives permission to `to` to transfer `tokenId` token to another account.
     * The approval is cleared when the token is transferred.
     *
     * Only a single account can be approved at a time, so approving the zero address clears previous approvals.
     *
     * Requirements:
     *
     * - The caller must own the token or be an approved operator.
     * - `tokenId` must exist.
     *
     * Emits an {Approval} event.
     */
    function approve(address to, uint256 tokenId) external;

    /**
     * @dev Returns the account approved for `tokenId` token.
     *
     * Requirements:
     *
     * - `tokenId` must exist.
     */
    function getApproved(uint256 tokenId) external view returns (address operator);

    /**
     * @dev Approve or remove `operator` as an operator for the caller.
     * Operators can call {transferFrom} or {safeTransferFrom} for any token owned by the caller.
     *
     * Requirements:
     *
     * - The `operator` cannot be the caller.
     *
     * Emits an {ApprovalForAll} event.
     */
    function setApprovalForAll(address operator, bool _approved) external;

    /**
     * @dev Returns if the `operator` is allowed to manage all of the assets of `owner`.
     *
     * See {setApprovalForAll}
     */
    function isApprovedForAll(address owner, address operator) external view returns (bool);

    /**
     * @dev Safely transfers `tokenId` token from `from` to `to`.
     *
     * Requirements:
     *
     * - `from` cannot be the zero address.
     * - `to` cannot be the zero address.
     * - `tokenId` token must exist and be owned by `from`.
     * - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}.
     * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer.
     *
     * Emits a {Transfer} event.
     */
    function safeTransferFrom(
        address from,
        address to,
        uint256 tokenId,
        bytes calldata data
    ) external;
}
CheckAddress.sol 35 lines
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

/// @author 1001.digital
/// @title A helper to distinguish external and contract addresses
library CheckAddress {

    /// Check whether an address is a smart contract.
    /// @param account the address to check
    /// @dev checks if the `extcodesize` of `address` is greater zero
    /// @return true for contracts
    function isContract(address account) external view returns (bool) {
        return getSize(account) > 0;
    }

    /// Check whether an address is an external wallet.
    /// @param account the address to check
    /// @dev checks if the `extcodesize` of `address` is zero
    /// @return true for external wallets
    function isExternal(address account) external view returns (bool) {
        return getSize(account) == 0;
    }

    /// Get the size of the code of an address
    /// @param account the address to check
    /// @dev gets the `extcodesize` of `address`
    /// @return the size of the address
    function getSize(address account) internal view returns (uint256) {
        uint256 size;
        assembly {
            size := extcodesize(account)
        }
        return size;
    }
}
ERC165.sol 28 lines
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

import "./IERC165.sol";

/**
 * @dev Implementation of the {IERC165} interface.
 *
 * Contracts that want to implement ERC165 should inherit from this contract and override {supportsInterface} to check
 * for the additional interface id that will be supported. For example:
 *
 * ```solidity
 * function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
 *     return interfaceId == type(MyInterface).interfaceId || super.supportsInterface(interfaceId);
 * }
 * ```
 *
 * Alternatively, {ERC165Storage} provides an easier to use but more expensive implementation.
 */
abstract contract ERC165 is IERC165 {
    /**
     * @dev See {IERC165-supportsInterface}.
     */
    function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
        return interfaceId == type(IERC165).interfaceId;
    }
}
IERC165.sol 24 lines
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

/**
 * @dev Interface of the ERC165 standard, as defined in the
 * https://eips.ethereum.org/EIPS/eip-165[EIP].
 *
 * Implementers can declare support of contract interfaces, which can then be
 * queried by others ({ERC165Checker}).
 *
 * For an implementation, see {ERC165}.
 */
interface IERC165 {
    /**
     * @dev Returns true if this contract implements the interface defined by
     * `interfaceId`. See the corresponding
     * https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[EIP section]
     * to learn more about how these ids are created.
     *
     * This function call must use less than 30 000 gas.
     */
    function supportsInterface(bytes4 interfaceId) external view returns (bool);
}
IERC721Receiver.sol 26 lines
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

/**
 * @title ERC721 token receiver interface
 * @dev Interface for any contract that wants to support safeTransfers
 * from ERC721 asset contracts.
 */
interface IERC721Receiver {
    /**
     * @dev Whenever an {IERC721} `tokenId` token is transferred to this contract via {IERC721-safeTransferFrom}
     * by `operator` from `from`, this function is called.
     *
     * It must return its Solidity selector to confirm the token transfer.
     * If any other value is returned or the interface is not implemented by the recipient, the transfer will be reverted.
     *
     * The selector can be obtained in Solidity with `IERC721.onERC721Received.selector`.
     */
    function onERC721Received(
        address operator,
        address from,
        uint256 tokenId,
        bytes calldata data
    ) external returns (bytes4);
}
OnePerWallet.sol 57 lines
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

import "@openzeppelin/contracts/token/ERC721/ERC721.sol";
import "@1001-digital/check-address/contracts/CheckAddress.sol";

/// @author 1001.digital
/// @title An extension that enables checking that an address only holds one token.
abstract contract OnePerWallet is ERC721 {
    // Mapping owner address to token
    mapping (address => uint256) private _ownedToken;

    /// Require an externally owned account to only hold one token.
    /// @param wallet the address of
    /// @dev Only allow one token per wallet
    modifier onePerWallet(address wallet) {
        if (CheckAddress.isExternal(wallet)) {
            require(_ownedToken[wallet] == 0, "Can only hold one token per wallet");
        }

        _;
    }

    /// Query the owner of a token.
    /// @param owner the address of the owner
    /// @dev Get the the token of an owner
    function tokenOf(address owner) public view virtual returns (uint256) {
        require(_ownedToken[owner] > 0, "No token for this account.");

        // We subtract 1 as we added 1 to account for 0-index based collections
        return _ownedToken[owner] - 1;
    }

    /// Store `_ownedToken` instead of `_balances`.
    /// @param to the address to which to mint the token
    /// @param tokenId the tokenId that should be minted
    /// @dev overrides the OpenZeppelin `_mint` method to accomodate for our own balance tracker
    function _mint(address to, uint256 tokenId) internal virtual override onePerWallet(to) {
        super._mint(to, tokenId);

        // We add one to account for 0-index based collections
        _ownedToken[to] = tokenId + 1;
    }

    /// Track transfers in `_ownedToken` instead of `_balances`
    /// @param from the address from which to transfer the token
    /// @param to the address to which to transfer the token
    /// @param tokenId the tokenId that is being transferred
    /// @dev overrides the OpenZeppelin `_transfer` method to accomodate for our own balance tracker
    function _transfer(address from, address to, uint256 tokenId) internal virtual override onePerWallet(to) {
        super._transfer(from, to, tokenId);

        _ownedToken[from] = 0;
        // We add one to account for 0-index based collections
        _ownedToken[to] = tokenId + 1;
    }
}
RandomlyAssigned.sol 62 lines
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

import "./WithLimitedSupply.sol";

/// @author 1001.digital
/// @title Randomly assign tokenIDs from a given set of tokens.
abstract contract RandomlyAssigned is WithLimitedSupply {
    // Used for random index assignment
    mapping(uint256 => uint256) private tokenMatrix;

    // The initial token ID
    uint256 private startFrom;

    /// Instanciate the contract
    /// @param _totalSupply how many tokens this collection should hold
    /// @param _startFrom the tokenID with which to start counting
    constructor (uint256 _totalSupply, uint256 _startFrom)
        WithLimitedSupply(_totalSupply)
    {
        startFrom = _startFrom;
    }

    /// Get the next token ID
    /// @dev Randomly gets a new token ID and keeps track of the ones that are still available.
    /// @return the next token ID
    function nextToken() internal override ensureAvailability returns (uint256) {
        uint256 maxIndex = totalSupply() - tokenCount();
        uint256 random = uint256(keccak256(
            abi.encodePacked(
                msg.sender,
                block.coinbase,
                block.difficulty,
                block.gaslimit,
                block.timestamp
            )
        )) % maxIndex;

        uint256 value = 0;
        if (tokenMatrix[random] == 0) {
            // If this matrix position is empty, set the value to the generated random number.
            value = random;
        } else {
            // Otherwise, use the previously stored number from the matrix.
            value = tokenMatrix[random];
        }

        // If the last available tokenID is still unused...
        if (tokenMatrix[maxIndex - 1] == 0) {
            // ...store that ID in the current matrix position.
            tokenMatrix[random] = maxIndex - 1;
        } else {
            // ...otherwise copy over the stored number to the current matrix position.
            tokenMatrix[random] = tokenMatrix[maxIndex - 1];
        }

        // Increment counts
        super.nextToken();

        return value + startFrom;
    }
}
WithIPFSMetaData.sol 42 lines
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

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

/// @author 1001.digital
/// @title Handle NFT Metadata stored on IPFS
abstract contract WithIPFSMetaData is ERC721 {
    using Strings for uint256;

    /// @dev The content identifier of the folder containing all JSON files.
    string public cid;

    /// Instantiate the contract
    /// @param _cid the content identifier for the token metadata.
    /// @dev be careful & make sure your metadata is correct - you can't change this
    constructor (string memory _cid) {
        cid = _cid;
    }

    /// Get the tokenURI for a tokenID
    /// @param tokenId the token id for which to get the matadata URL
    /// @dev links to the metadata json file on IPFS.
    /// @return the URL to the token metadata file
    function tokenURI(uint256 tokenId) public view virtual override returns (string memory) {
        require(_exists(tokenId), "ERC721Metadata: URI query for nonexistent token");

        // We don't check whether the _baseURI is set like in the OpenZeppelin implementation
        // as we're deploying the contract with the CID.
        return string(abi.encodePacked(
            _baseURI(), "/", tokenId.toString(), "/metadata.json"
        ));
    }

    /// Configure the baseURI for the tokenURI method.
    /// @dev override the standard OpenZeppelin implementation
    /// @return the IPFS base uri
    function _baseURI() internal view virtual override returns (string memory) {
        return string(abi.encodePacked("ipfs://", cid));
    }
}
WithLimitedSupply.sol 63 lines
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

import "@openzeppelin/contracts/utils/Counters.sol";

/// @author 1001.digital
/// @title A token tracker that limits the token supply and increments token IDs on each new mint.
abstract contract WithLimitedSupply {
    using Counters for Counters.Counter;

    // Keeps track of how many we have minted
    Counters.Counter private _tokenCount;

    /// @dev The maximum count of tokens this token tracker will hold.
    uint256 private _totalSupply;

    /// Instanciate the contract
    /// @param totalSupply_ how many tokens this collection should hold
    constructor (uint256 totalSupply_) {
        _totalSupply = totalSupply_;
    }

    /// @dev Get the max Supply
    /// @return the maximum token count
    function totalSupply() public view returns (uint256) {
        return _totalSupply;
    }

    /// @dev Get the current token count
    /// @return the created token count
    function tokenCount() public view returns (uint256) {
        return _tokenCount.current();
    }

    /// @dev Check whether tokens are still available
    /// @return the available token count
    function availableTokenCount() public view returns (uint256) {
        return totalSupply() - tokenCount();
    }

    /// @dev Increment the token count and fetch the latest count
    /// @return the next token id
    function nextToken() internal virtual ensureAvailability returns (uint256) {
        uint256 token = _tokenCount.current();

        _tokenCount.increment();

        return token;
    }

    /// @dev Check whether another token is still available
    modifier ensureAvailability() {
        require(availableTokenCount() > 0, "No more tokens available");
        _;
    }

    /// @param amount Check whether number of tokens are still available
    /// @dev Check whether tokens are still available
    modifier ensureAvailabilityFor(uint256 amount) {
        require(availableTokenCount() >= amount, "Requested number of tokens not available");
        _;
    }
}
WithContractMetaData.sol 31 lines
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

import "@openzeppelin/contracts/access/Ownable.sol";

/// @author 1001.digital
/// @title Link to your collection's contract meta data right from within your smart contract.
abstract contract WithContractMetaData is Ownable {
    // The URI to the contract meta data.
    string private _contractURI;

    /// Instanciate the contract
    /// @param uri the URL to the contract metadata
    constructor (string memory uri) {
        _contractURI = uri;
    }

    /// Set the contract metadata URI
    /// @param uri the URI to set
    /// @dev the contract metadata should link to a metadata JSON file.
    function setContractURI(string memory uri) public virtual onlyOwner {
        _contractURI = uri;
    }

    /// Expose the contractURI
    /// @return the contract metadata URI.
    function contractURI() public view virtual returns (string memory) {
        return _contractURI;
    }

}
IERC721Metadata.sol 26 lines
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

import "../IERC721.sol";

/**
 * @title ERC-721 Non-Fungible Token Standard, optional metadata extension
 * @dev See https://eips.ethereum.org/EIPS/eip-721
 */
interface IERC721Metadata is IERC721 {
    /**
     * @dev Returns the token collection name.
     */
    function name() external view returns (string memory);

    /**
     * @dev Returns the token collection symbol.
     */
    function symbol() external view returns (string memory);

    /**
     * @dev Returns the Uniform Resource Identifier (URI) for `tokenId` token.
     */
    function tokenURI(uint256 tokenId) external view returns (string memory);
}

Read Contract

availableTokenCount 0xe14ca353 → uint256
balanceOf 0x70a08231 → uint256
cid 0xaa3ec0a9 → string
contractURI 0xe8a3d485 → string
getApproved 0x081812fc → address
isApprovedForAll 0xe985e9c5 → bool
name 0x06fdde03 → string
owner 0x8da5cb5b → address
ownerOf 0x6352211e → address
supportsInterface 0x01ffc9a7 → bool
symbol 0x95d89b41 → string
tokenCount 0x9f181b5e → uint256
tokenOf 0x42ec38e2 → uint256
tokenURI 0xc87b56dd → string
totalSupply 0x18160ddd → uint256

Write Contract 10 functions

These functions modify contract state and require a wallet transaction to execute.

approve 0x095ea7b3
address to
uint256 tokenId
claim 0x4e71d92d
No parameters
claimFor 0xddeae033
address to
renounceOwnership 0x715018a6
No parameters
safeTransferFrom 0x42842e0e
address from
address to
uint256 tokenId
safeTransferFrom 0xb88d4fde
address from
address to
uint256 tokenId
bytes _data
setApprovalForAll 0xa22cb465
address operator
bool approved
setContractURI 0x938e3d7b
string uri
transferFrom 0x23b872dd
address from
address to
uint256 tokenId
transferOwnership 0xf2fde38b
address newOwner

Recent Transactions

No transactions found for this address