Address Contract Verified
Address
0x69A04d373e3E2Db13027E9d584eB8203d46a86C7
Balance
0 ETH
Nonce
1
Code Size
21898 bytes
Creator
0xf55042e5...0a41 at tx 0x1be3a7be...c3ffea
Indexed Transactions
0
Contract Bytecode
21898 bytes
0x60806040526004361061019c5760003560e01c80636352211e116100ec578063a22cb4651161008a578063d004b03611610064578063d004b036146105ec578063d57291eb14610629578063e985e9c514610659578063f2fde38b146106965761019c565b8063a22cb4651461055d578063b88d4fde14610586578063c87b56dd146105af5761019c565b806371d458d4116100c657806371d458d41461048d578063869f7594146104ca5780638da5cb5b1461050757806395d89b41146105325761019c565b80636352211e146103fc57806370a0823114610439578063715018a6146104765761019c565b806323b872dd1161015957806342842e0e1161013357806342842e0e146103425780634f6ccce71461036b57806353c8388e146103a8578063564b81ef146103d15761019c565b806323b872dd146102c55780632f745c59146102ee5780633ccfd60b1461032b5761019c565b806301ffc9a7146101a157806306fdde03146101de578063081812fc14610209578063095ea7b31461024657806312065fe01461026f57806318160ddd1461029a575b600080fd5b3480156101ad57600080fd5b506101c860048036038101906101c39190613a77565b6106bf565b6040516101d59190614a6c565b60405180910390f35b3480156101ea57600080fd5b506101f36106d1565b6040516102009190614b80565b60405180910390f35b34801561021557600080fd5b50610230600480360381019061022b9190613ac9565b610763565b60405161023d91906149e3565b60405180910390f35b34801561025257600080fd5b5061026d60048036038101906102689190613a12565b6107e8565b005b34801561027b57600080fd5b50610284610900565b6040516102919190614fe2565b60405180910390f35b3480156102a657600080fd5b506102af610908565b6040516102bc9190614fe2565b60405180910390f35b3480156102d157600080fd5b506102ec60048036038101906102e791906138b8565b610915565b005b3480156102fa57600080fd5b5061031560048036038101906103109190613a12565b610975565b6040516103229190614fe2565b60405180910390f35b34801561033757600080fd5b50610340610a1a565b005b34801561034e57600080fd5b50610369600480360381019061036491906138b8565b610adf565b005b34801561037757600080fd5b50610392600480360381019061038d9190613ac9565b610aff565b60405161039f9190614fe2565b60405180910390f35b3480156103b457600080fd5b506103cf60048036038101906103ca9190613af2565b610b96565b005b3480156103dd57600080fd5b506103e6610d1c565b6040516103f39190614fe2565b60405180910390f35b34801561040857600080fd5b50610423600480360381019061041e9190613ac9565b610d29565b60405161043091906149e3565b60405180910390f35b34801561044557600080fd5b50610460600480360381019061045b9190613853565b610ddb565b60405161046d9190614fe2565b60405180910390f35b34801561048257600080fd5b5061048b610e93565b005b34801561049957600080fd5b506104b460048036038101906104af9190613ac9565b610f1b565b6040516104c19190614fe2565b60405180910390f35b3480156104d657600080fd5b506104f160048036038101906104ec9190613ac9565b610f38565b6040516104fe9190614fe2565b60405180910390f35b34801561051357600080fd5b5061051c610f55565b60405161052991906149e3565b60405180910390f35b34801561053e57600080fd5b50610547610f7f565b6040516105549190614b80565b60405180910390f35b34801561056957600080fd5b50610584600480360381019061057f9190613982565b611011565b005b34801561059257600080fd5b506105ad60048036038101906105a89190613907565b611192565b005b3480156105bb57600080fd5b506105d660048036038101906105d19190613ac9565b6111f4565b6040516105e39190614b80565b60405180910390f35b3480156105f857600080fd5b50610613600480360381019061060e9190613853565b611206565b6040516106209190614a4a565b60405180910390f35b610643600480360381019061063e91906139be565b611302565b6040516106509190614fe2565b60405180910390f35b34801561066557600080fd5b50610680600480360381019061067b919061387c565b611664565b60405161068d9190614a6c565b60405180910390f35b3480156106a257600080fd5b506106bd60048036038101906106b89190613853565b6116f8565b005b60006106ca826117f0565b9050919050565b6060600080546106e090615375565b80601f016020809104026020016040519081016040528092919081815260200182805461070c90615375565b80156107595780601f1061072e57610100808354040283529160200191610759565b820191906000526020600020905b81548152906001019060200180831161073c57829003601f168201915b5050505050905090565b600061076e8261186a565b6107ad576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016107a490614e62565b60405180910390fd5b6004600083815260200190815260200160002060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff169050919050565b60006107f382610d29565b90508073ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff161415610864576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161085b90614f22565b60405180910390fd5b8073ffffffffffffffffffffffffffffffffffffffff166108836118d6565b73ffffffffffffffffffffffffffffffffffffffff1614806108b257506108b1816108ac6118d6565b611664565b5b6108f1576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016108e890614d82565b60405180910390fd5b6108fb83836118de565b505050565b600047905090565b6000600980549050905090565b6109266109206118d6565b82611997565b610965576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161095c90614f62565b60405180910390fd5b610970838383611a75565b505050565b600061098083610ddb565b82106109c1576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016109b890614c22565b60405180910390fd5b600760008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020600083815260200190815260200160002054905092915050565b610a226118d6565b73ffffffffffffffffffffffffffffffffffffffff16610a40610f55565b73ffffffffffffffffffffffffffffffffffffffff1614610a96576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610a8d90614e82565b60405180910390fd5b3373ffffffffffffffffffffffffffffffffffffffff166108fc479081150290604051600060405180830381858888f19350505050158015610adc573d6000803e3d6000fd5b50565b610afa83838360405180602001604052806000815250611192565b505050565b6000610b09610908565b8210610b4a576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610b4190614f82565b60405180910390fd5b60098281548110610b84577f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b90600052602060002001549050919050565b610b9e6118d6565b73ffffffffffffffffffffffffffffffffffffffff16610bbc610f55565b73ffffffffffffffffffffffffffffffffffffffff1614610c12576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610c0990614e82565b60405180910390fd5b6064831115610c56576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610c4d90614fa2565b60405180910390fd5b60011515600c600085815260200190815260200160002060009054906101000a900460ff1615151415610cbe576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610cb590614be2565b60405180910390fd5b610cc9836001611cd1565b610d178383838080601f016020809104026020016040519081016040528093929190818152602001838380828437600081840152601f19601f82011690508083019250505050505050611d00565b505050565b6000804690508091505090565b6000806002600084815260200190815260200160002060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff169050600073ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff161415610dd2576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610dc990614dc2565b60405180910390fd5b80915050919050565b60008073ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff161415610e4c576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610e4390614da2565b60405180910390fd5b600360008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020549050919050565b610e9b6118d6565b73ffffffffffffffffffffffffffffffffffffffff16610eb9610f55565b73ffffffffffffffffffffffffffffffffffffffff1614610f0f576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610f0690614e82565b60405180910390fd5b610f196000611d74565b565b6000600d6000838152602001908152602001600020549050919050565b6000600e6000838152602001908152602001600020549050919050565b6000600b60009054906101000a900473ffffffffffffffffffffffffffffffffffffffff16905090565b606060018054610f8e90615375565b80601f0160208091040260200160405190810160405280929190818152602001828054610fba90615375565b80156110075780601f10610fdc57610100808354040283529160200191611007565b820191906000526020600020905b815481529060010190602001808311610fea57829003601f168201915b5050505050905090565b6110196118d6565b73ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff161415611087576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161107e90614ce2565b60405180910390fd5b80600560006110946118d6565b73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060006101000a81548160ff0219169083151502179055508173ffffffffffffffffffffffffffffffffffffffff166111416118d6565b73ffffffffffffffffffffffffffffffffffffffff167f17307eab39ab6107e8899845ad3d59bd9653f200f220920489ca2b5937696c31836040516111869190614a6c565b60405180910390a35050565b6111a361119d6118d6565b83611997565b6111e2576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016111d990614f62565b60405180910390fd5b6111ee84848484611e3a565b50505050565b60606111ff82611e96565b9050919050565b6060600061121383610ddb565b67ffffffffffffffff811115611252577f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b6040519080825280602002602001820160405280156112805781602001602082028036833780820191505090505b50905060005b61128f84610ddb565b8110156112f8576112a08482610975565b8282815181106112d9577f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b60200260200101818152505080806112f0906153a7565b915050611286565b8192505050919050565b60008061130e83611fe8565b90506000836000013511611357576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161134e90614c82565b60405180910390fd5b600183604001351015801561137157506005836040013511155b6113b0576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016113a790614ea2565b60405180910390fd5b600115158360200160208101906113c79190613a4e565b151514806113fb5750600015158360200160208101906113e79190613a4e565b15151480156113fa575060018360400135145b5b61143a576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161143190614c02565b60405180910390fd5b8073ffffffffffffffffffffffffffffffffffffffff16611459610f55565b73ffffffffffffffffffffffffffffffffffffffff16146114af576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016114a690614d22565b60405180910390fd5b61150a8380606001906114c29190615054565b8080601f016020809104026020016040519081016040528093929190818152602001838380828437600081840152601f19601f8201169050808301925050505050505061205a565b341461154b576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161154290614f42565b60405180910390fd5b600e60008460400135815260200190815260200160002054600d60008560400135815260200190815260200160002054106115bb576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016115b290614f02565b60405180910390fd5b6115db83600001358460200160208101906115d69190613a4e565b611cd1565b6115e88360400135612291565b6115f68484600001356122cb565b611656836000013584806080019061160e9190615054565b8080601f016020809104026020016040519081016040528093929190818152602001838380828437600081840152601f19601f82011690508083019250505050505050611d00565b826000013591505092915050565b6000600560008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff16905092915050565b6117006118d6565b73ffffffffffffffffffffffffffffffffffffffff1661171e610f55565b73ffffffffffffffffffffffffffffffffffffffff1614611774576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161176b90614e82565b60405180910390fd5b600073ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff1614156117e4576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016117db90614c62565b60405180910390fd5b6117ed81611d74565b50565b60007f780e9d63000000000000000000000000000000000000000000000000000000007bffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916827bffffffffffffffffffffffffffffffffffffffffffffffffffffffff191614806118635750611862826122e9565b5b9050919050565b60008073ffffffffffffffffffffffffffffffffffffffff166002600084815260200190815260200160002060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1614159050919050565b600033905090565b816004600083815260200190815260200160002060006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff160217905550808273ffffffffffffffffffffffffffffffffffffffff1661195183610d29565b73ffffffffffffffffffffffffffffffffffffffff167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b92560405160405180910390a45050565b60006119a28261186a565b6119e1576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016119d890614d62565b60405180910390fd5b60006119ec83610d29565b90508073ffffffffffffffffffffffffffffffffffffffff168473ffffffffffffffffffffffffffffffffffffffff161480611a5b57508373ffffffffffffffffffffffffffffffffffffffff16611a4384610763565b73ffffffffffffffffffffffffffffffffffffffff16145b80611a6c5750611a6b8185611664565b5b91505092915050565b8273ffffffffffffffffffffffffffffffffffffffff16611a9582610d29565b73ffffffffffffffffffffffffffffffffffffffff1614611aeb576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401611ae290614ec2565b60405180910390fd5b600073ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff161415611b5b576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401611b5290614cc2565b60405180910390fd5b611b668383836123cb565b611b716000826118de565b6001600360008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000206000828254611bc19190615274565b925050819055506001600360008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000206000828254611c189190615193565b92505081905550816002600083815260200190815260200160002060006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff160217905550808273ffffffffffffffffffffffffffffffffffffffff168473ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef60405160405180910390a4505050565b80600c600084815260200190815260200160002060006101000a81548160ff0219169083151502179055505050565b611d098261186a565b611d48576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401611d3f90614de2565b60405180910390fd5b80600660008481526020019081526020016000209080519060200190611d6f92919061367a565b505050565b6000600b60009054906101000a900473ffffffffffffffffffffffffffffffffffffffff16905081600b60006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff1602179055508173ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e060405160405180910390a35050565b611e45848484611a75565b611e51848484846123db565b611e90576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401611e8790614c42565b60405180910390fd5b50505050565b6060611ea18261186a565b611ee0576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401611ed790614e42565b60405180910390fd5b6000600660008481526020019081526020016000208054611f0090615375565b80601f0160208091040260200160405190810160405280929190818152602001828054611f2c90615375565b8015611f795780601f10611f4e57610100808354040283529160200191611f79565b820191906000526020600020905b815481529060010190602001808311611f5c57829003601f168201915b505050505090506000611f8a612572565b9050600081511415611fa0578192505050611fe3565b600082511115611fd5578082604051602001611fbd929190614988565b60405160208183030381529060405292505050611fe3565b611fde84612589565b925050505b919050565b600080611ff483612630565b905061205281848060a0019061200a9190614ffd565b8080601f016020809104026020016040519081016040528093929190818152602001838380828437600081840152601f19601f820116905080830192505050505050506126f6565b915050919050565b60008082905060008060005b83518110156122855760308482815181106120aa577f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b602001015160f81c60f81b60f81c60ff1610158015612113575060398482815181106120ff577f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b602001015160f81c60f81b60f81c60ff1611155b1561219a57811561212357612285565b600a83612130919061521a565b9250603084828151811061216d577f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b602001015160f81c60f81b60f81c60ff166121889190615274565b836121939190615193565b9250612272565b602e8482815181106121d5577f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b602001015160f81c60f81b60f81c60ff16141561223657811561222d576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161222490614fc2565b60405180910390fd5b60019150612271565b6040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161226890614d02565b60405180910390fd5b5b808061227d906153a7565b915050612066565b50819350505050919050565b6001600d6000838152602001908152602001600020546122b19190615193565b600d60008381526020019081526020016000208190555050565b6122e582826040518060200160405280600081525061271d565b5050565b60007f80ac58cd000000000000000000000000000000000000000000000000000000007bffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916827bffffffffffffffffffffffffffffffffffffffffffffffffffffffff191614806123b457507f5b5e139f000000000000000000000000000000000000000000000000000000007bffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916827bffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916145b806123c457506123c382612778565b5b9050919050565b6123d68383836127e2565b505050565b60006123fc8473ffffffffffffffffffffffffffffffffffffffff166128f6565b15612565578373ffffffffffffffffffffffffffffffffffffffff1663150b7a026124256118d6565b8786866040518563ffffffff1660e01b815260040161244794939291906149fe565b602060405180830381600087803b15801561246157600080fd5b505af192505050801561249257506040513d601f19601f8201168201806040525081019061248f9190613aa0565b60015b612515573d80600081146124c2576040519150601f19603f3d011682016040523d82523d6000602084013e6124c7565b606091505b5060008151141561250d576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161250490614c42565b60405180910390fd5b805181602001fd5b63150b7a0260e01b7bffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916817bffffffffffffffffffffffffffffffffffffffffffffffffffffffff19161491505061256a565b600190505b949350505050565b606060405180602001604052806000815250905090565b60606125948261186a565b6125d3576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016125ca90614ee2565b60405180910390fd5b60006125dd612572565b905060008151116125fd5760405180602001604052806000815250612628565b8061260784612909565b604051602001612618929190614988565b6040516020818303038152906040525b915050919050565b60006126ef7f06d8abb3313abb916e0f4383da4188fe915480acdca8b22318282dd352839228836000013584602001602081019061266e9190613a4e565b85604001358680606001906126839190615054565b60405161269192919061496f565b60405180910390208780608001906126a99190615054565b6040516126b792919061496f565b60405180910390206040516020016126d496959493929190614ada565b60405160208183030381529060405280519060200120612ab6565b9050919050565b60008060006127058585612ad0565b9150915061271281612b53565b819250505092915050565b6127278383612ea4565b61273460008484846123db565b612773576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161276a90614c42565b60405180910390fd5b505050565b60007f01ffc9a7000000000000000000000000000000000000000000000000000000007bffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916827bffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916149050919050565b6127ed838383613072565b600073ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff1614156128305761282b81613077565b61286f565b8173ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff161461286e5761286d83826130c0565b5b5b600073ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff1614156128b2576128ad8161322d565b6128f1565b8273ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff16146128f0576128ef8282613370565b5b5b505050565b600080823b905060008111915050919050565b60606000821415612951576040518060400160405280600181526020017f30000000000000000000000000000000000000000000000000000000000000008152509050612ab1565b600082905060005b6000821461298357808061296c906153a7565b915050600a8261297c91906151e9565b9150612959565b60008167ffffffffffffffff8111156129c5577f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b6040519080825280601f01601f1916602001820160405280156129f75781602001600182028036833780820191505090505b5090505b60008514612aaa57600182612a109190615274565b9150600a85612a1f91906153fa565b6030612a2b9190615193565b60f81b818381518110612a67577f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916908160001a905350600a85612aa391906151e9565b94506129fb565b8093505050505b919050565b6000612ac9612ac36133ef565b836134b2565b9050919050565b600080604183511415612b125760008060006020860151925060408601519150606086015160001a9050612b06878285856134e5565b94509450505050612b4c565b604083511415612b43576000806020850151915060408501519050612b388683836135f2565b935093505050612b4c565b60006002915091505b9250929050565b60006004811115612b8d577f4e487b7100000000000000000000000000000000000000000000000000000000600052602160045260246000fd5b816004811115612bc6577f4e487b7100000000000000000000000000000000000000000000000000000000600052602160045260246000fd5b1415612bd157612ea1565b60016004811115612c0b577f4e487b7100000000000000000000000000000000000000000000000000000000600052602160045260246000fd5b816004811115612c44577f4e487b7100000000000000000000000000000000000000000000000000000000600052602160045260246000fd5b1415612c85576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401612c7c90614ba2565b60405180910390fd5b60026004811115612cbf577f4e487b7100000000000000000000000000000000000000000000000000000000600052602160045260246000fd5b816004811115612cf8577f4e487b7100000000000000000000000000000000000000000000000000000000600052602160045260246000fd5b1415612d39576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401612d3090614bc2565b60405180910390fd5b60036004811115612d73577f4e487b7100000000000000000000000000000000000000000000000000000000600052602160045260246000fd5b816004811115612dac577f4e487b7100000000000000000000000000000000000000000000000000000000600052602160045260246000fd5b1415612ded576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401612de490614d42565b60405180910390fd5b600480811115612e26577f4e487b7100000000000000000000000000000000000000000000000000000000600052602160045260246000fd5b816004811115612e5f577f4e487b7100000000000000000000000000000000000000000000000000000000600052602160045260246000fd5b1415612ea0576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401612e9790614e02565b60405180910390fd5b5b50565b600073ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff161415612f14576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401612f0b90614e22565b60405180910390fd5b612f1d8161186a565b15612f5d576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401612f5490614ca2565b60405180910390fd5b612f69600083836123cb565b6001600360008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000206000828254612fb99190615193565b92505081905550816002600083815260200190815260200160002060006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff160217905550808273ffffffffffffffffffffffffffffffffffffffff16600073ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef60405160405180910390a45050565b505050565b600980549050600a600083815260200190815260200160002081905550600981908060018154018082558091505060019003906000526020600020016000909190919091505550565b600060016130cd84610ddb565b6130d79190615274565b90506000600860008481526020019081526020016000205490508181146131bc576000600760008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020600084815260200190815260200160002054905080600760008773ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020600084815260200190815260200160002081905550816008600083815260200190815260200160002081905550505b6008600084815260200190815260200160002060009055600760008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008381526020019081526020016000206000905550505050565b600060016009805490506132419190615274565b90506000600a6000848152602001908152602001600020549050600060098381548110613297577f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b9060005260206000200154905080600983815481106132df577f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b906000526020600020018190555081600a600083815260200190815260200160002081905550600a6000858152602001908152602001600020600090556009805480613354577f4e487b7100000000000000000000000000000000000000000000000000000000600052603160045260246000fd5b6001900381819060005260206000200160009055905550505050565b600061337b83610ddb565b905081600760008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020600083815260200190815260200160002081905550806008600084815260200190815260200160002081905550505050565b60007f0000000000000000000000000000000000000000000000000000000000000001461415613441577f31751a48158490303a858f99e5d85ac7fc0b3ba76213d25005470c36f44ca69c90506134af565b6134ac7f8b73c3c69bb8fe3d512ecc4cf759cc79239f7b179b0ffacaa9a75d522b39400f7f7b4baec4b08c421dedb38cdf34d325c4eae2a39ec5a5d752b1f820a8edeac9b77fc89efdaa54c0f20c7adf612882df0950f5a951637e0307cdcb4c672f298b8bc6613640565b90505b90565b600082826040516020016134c79291906149ac565b60405160208183030381529060405280519060200120905092915050565b6000807f7fffffffffffffffffffffffffffffff5d576e7357a4501ddfe92f46681b20a08360001c11156135205760006003915091506135e9565b601b8560ff16141580156135385750601c8560ff1614155b1561354a5760006004915091506135e9565b60006001878787876040516000815260200160405260405161356f9493929190614b3b565b6020604051602081039080840390855afa158015613591573d6000803e3d6000fd5b505050602060405103519050600073ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff1614156135e0576000600192509250506135e9565b80600092509250505b94509492505050565b6000806000807f7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff85169150601b8560ff1c019050613632878288856134e5565b935093505050935093915050565b6000838383463060405160200161365b959493929190614a87565b6040516020818303038152906040528051906020012090509392505050565b82805461368690615375565b90600052602060002090601f0160209004810192826136a857600085556136ef565b82601f106136c157805160ff19168380011785556136ef565b828001600101855582156136ef579182015b828111156136ee5782518255916020019190600101906136d3565b5b5090506136fc9190613700565b5090565b5b80821115613719576000816000905550600101613701565b5090565b600061373061372b846150dc565b6150ab565b90508281526020810184848401111561374857600080fd5b613753848285615333565b509392505050565b60008135905061376a816154f8565b92915050565b60008135905061377f8161550f565b92915050565b60008135905061379481615526565b92915050565b6000815190506137a981615526565b92915050565b600082601f8301126137c057600080fd5b81356137d084826020860161371d565b91505092915050565b60008083601f8401126137eb57600080fd5b8235905067ffffffffffffffff81111561380457600080fd5b60208301915083600182028301111561381c57600080fd5b9250929050565b600060c0828403121561383557600080fd5b81905092915050565b60008135905061384d8161553d565b92915050565b60006020828403121561386557600080fd5b60006138738482850161375b565b91505092915050565b6000806040838503121561388f57600080fd5b600061389d8582860161375b565b92505060206138ae8582860161375b565b9150509250929050565b6000806000606084860312156138cd57600080fd5b60006138db8682870161375b565b93505060206138ec8682870161375b565b92505060406138fd8682870161383e565b9150509250925092565b6000806000806080858703121561391d57600080fd5b600061392b8782880161375b565b945050602061393c8782880161375b565b935050604061394d8782880161383e565b925050606085013567ffffffffffffffff81111561396a57600080fd5b613976878288016137af565b91505092959194509250565b6000806040838503121561399557600080fd5b60006139a38582860161375b565b92505060206139b485828601613770565b9150509250929050565b600080604083850312156139d157600080fd5b60006139df8582860161375b565b925050602083013567ffffffffffffffff8111156139fc57600080fd5b613a0885828601613823565b9150509250929050565b60008060408385031215613a2557600080fd5b6000613a338582860161375b565b9250506020613a448582860161383e565b9150509250929050565b600060208284031215613a6057600080fd5b6000613a6e84828501613770565b91505092915050565b600060208284031215613a8957600080fd5b6000613a9784828501613785565b91505092915050565b600060208284031215613ab257600080fd5b6000613ac08482850161379a565b91505092915050565b600060208284031215613adb57600080fd5b6000613ae98482850161383e565b91505092915050565b600080600060408486031215613b0757600080fd5b6000613b158682870161383e565b935050602084013567ffffffffffffffff811115613b3257600080fd5b613b3e868287016137d9565b92509250509250925092565b6000613b568383614942565b60208301905092915050565b613b6b816152a8565b82525050565b6000613b7c8261511c565b613b86818561514a565b9350613b918361510c565b8060005b83811015613bc2578151613ba98882613b4a565b9750613bb48361513d565b925050600181019050613b95565b5085935050505092915050565b613bd8816152ba565b82525050565b613be7816152c6565b82525050565b613bfe613bf9826152c6565b6153f0565b82525050565b6000613c10838561516c565b9350613c1d838584615333565b82840190509392505050565b6000613c3482615127565b613c3e818561515b565b9350613c4e818560208601615342565b613c57816154e7565b840191505092915050565b6000613c6d82615132565b613c778185615177565b9350613c87818560208601615342565b613c90816154e7565b840191505092915050565b6000613ca682615132565b613cb08185615188565b9350613cc0818560208601615342565b80840191505092915050565b6000613cd9601883615177565b91507f45434453413a20696e76616c6964207369676e617475726500000000000000006000830152602082019050919050565b6000613d19601f83615177565b91507f45434453413a20696e76616c6964207369676e6174757265206c656e677468006000830152602082019050919050565b6000613d59602683615177565b91507f546865206d6574616461746120666f72207468697320746f6b656e206973206c60008301527f6f636b65642e00000000000000000000000000000000000000000000000000006020830152604082019050919050565b6000613dbf603083615177565b91507f4f6e6c792066697273742065646974696f6e204e465427732063616e2062652060008301527f6d696e74656420756e6c6f636b65642e000000000000000000000000000000006020830152604082019050919050565b6000613e25602b83615177565b91507f455243373231456e756d657261626c653a206f776e657220696e646578206f7560008301527f74206f6620626f756e64730000000000000000000000000000000000000000006020830152604082019050919050565b6000613e8b603283615177565b91507f4552433732313a207472616e7366657220746f206e6f6e20455243373231526560008301527f63656976657220696d706c656d656e74657200000000000000000000000000006020830152604082019050919050565b6000613ef1602683615177565b91507f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160008301527f64647265737300000000000000000000000000000000000000000000000000006020830152604082019050919050565b6000613f57601183615177565b91507f496e76616c696420546f6b656e2049442e0000000000000000000000000000006000830152602082019050919050565b6000613f97601c83615177565b91507f4552433732313a20746f6b656e20616c7265616479206d696e746564000000006000830152602082019050919050565b6000613fd7600283615188565b91507f19010000000000000000000000000000000000000000000000000000000000006000830152600282019050919050565b6000614017602483615177565b91507f4552433732313a207472616e7366657220746f20746865207a65726f2061646460008301527f72657373000000000000000000000000000000000000000000000000000000006020830152604082019050919050565b600061407d601983615177565b91507f4552433732313a20617070726f766520746f2063616c6c6572000000000000006000830152602082019050919050565b60006140bd602c83615177565b91507f4e6f6e2d6e756d6572616c2063686172616374657220656e636f756e7465726560008301527f6420696e20737472696e672100000000000000000000000000000000000000006020830152604082019050919050565b6000614123601883615177565b91507f5468697320766f756368657220697320696e76616c69642e00000000000000006000830152602082019050919050565b6000614163602283615177565b91507f45434453413a20696e76616c6964207369676e6174757265202773272076616c60008301527f75650000000000000000000000000000000000000000000000000000000000006020830152604082019050919050565b60006141c9602c83615177565b91507f4552433732313a206f70657261746f7220717565727920666f72206e6f6e657860008301527f697374656e7420746f6b656e00000000000000000000000000000000000000006020830152604082019050919050565b600061422f603883615177565b91507f4552433732313a20617070726f76652063616c6c6572206973206e6f74206f7760008301527f6e6572206e6f7220617070726f76656420666f7220616c6c00000000000000006020830152604082019050919050565b6000614295602a83615177565b91507f4552433732313a2062616c616e636520717565727920666f7220746865207a6560008301527f726f2061646472657373000000000000000000000000000000000000000000006020830152604082019050919050565b60006142fb602983615177565b91507f4552433732313a206f776e657220717565727920666f72206e6f6e657869737460008301527f656e7420746f6b656e00000000000000000000000000000000000000000000006020830152604082019050919050565b6000614361602e83615177565b91507f45524337323155524953746f726167653a2055524920736574206f66206e6f6e60008301527f6578697374656e7420746f6b656e0000000000000000000000000000000000006020830152604082019050919050565b60006143c7602283615177565b91507f45434453413a20696e76616c6964207369676e6174757265202776272076616c60008301527f75650000000000000000000000000000000000000000000000000000000000006020830152604082019050919050565b600061442d602083615177565b91507f4552433732313a206d696e7420746f20746865207a65726f20616464726573736000830152602082019050919050565b600061446d603183615177565b91507f45524337323155524953746f726167653a2055524920717565727920666f722060008301527f6e6f6e6578697374656e7420746f6b656e0000000000000000000000000000006020830152604082019050919050565b60006144d3602c83615177565b91507f4552433732313a20617070726f76656420717565727920666f72206e6f6e657860008301527f697374656e7420746f6b656e00000000000000000000000000000000000000006020830152604082019050919050565b6000614539602083615177565b91507f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e65726000830152602082019050919050565b6000614579603583615177565b91507f496e76616c696420746f6b656e20646174612e202845646974696f6e206d757360008301527f74206265206265747765656e203120616e6420352900000000000000000000006020830152604082019050919050565b60006145df602983615177565b91507f4552433732313a207472616e73666572206f6620746f6b656e2074686174206960008301527f73206e6f74206f776e00000000000000000000000000000000000000000000006020830152604082019050919050565b6000614645602f83615177565b91507f4552433732314d657461646174613a2055524920717565727920666f72206e6f60008301527f6e6578697374656e7420746f6b656e00000000000000000000000000000000006020830152604082019050919050565b60006146ab602583615177565b91507f4e6f206d6f7265204e4654277320617661696c61626c6520746f206265206d6960008301527f6e7465642e0000000000000000000000000000000000000000000000000000006020830152604082019050919050565b6000614711602183615177565b91507f4552433732313a20617070726f76616c20746f2063757272656e74206f776e6560008301527f72000000000000000000000000000000000000000000000000000000000000006020830152604082019050919050565b6000614777601d83615177565b91507f496e636f727265637420616d6f756e74206f66204554482073656e742e0000006000830152602082019050919050565b60006147b7603183615177565b91507f4552433732313a207472616e736665722063616c6c6572206973206e6f74206f60008301527f776e6572206e6f7220617070726f7665640000000000000000000000000000006020830152604082019050919050565b600061481d602c83615177565b91507f455243373231456e756d657261626c653a20676c6f62616c20696e646578206f60008301527f7574206f6620626f756e647300000000000000000000000000000000000000006020830152604082019050919050565b6000614883603b83615177565b91507f437573746f6d697a6174696f6e7320617265206f6e6c7920617661696c61626c60008301527f6520666f72207468652066697273742031303020746f6b656e732e00000000006020830152604082019050919050565b60006148e9602c83615177565b91507f4d6f7265207468616e206f6e6520646563696d616c20656e636f756e7465726560008301527f6420696e20737472696e672100000000000000000000000000000000000000006020830152604082019050919050565b61494b8161531c565b82525050565b61495a8161531c565b82525050565b61496981615326565b82525050565b600061497c828486613c04565b91508190509392505050565b60006149948285613c9b565b91506149a08284613c9b565b91508190509392505050565b60006149b782613fca565b91506149c38285613bed565b6020820191506149d38284613bed565b6020820191508190509392505050565b60006020820190506149f86000830184613b62565b92915050565b6000608082019050614a136000830187613b62565b614a206020830186613b62565b614a2d6040830185614951565b8181036060830152614a3f8184613c29565b905095945050505050565b60006020820190508181036000830152614a648184613b71565b905092915050565b6000602082019050614a816000830184613bcf565b92915050565b600060a082019050614a9c6000830188613bde565b614aa96020830187613bde565b614ab66040830186613bde565b614ac36060830185614951565b614ad06080830184613b62565b9695505050505050565b600060c082019050614aef6000830189613bde565b614afc6020830188614951565b614b096040830187613bcf565b614b166060830186614951565b614b236080830185613bde565b614b3060a0830184613bde565b979650505050505050565b6000608082019050614b506000830187613bde565b614b5d6020830186614960565b614b6a6040830185613bde565b614b776060830184613bde565b95945050505050565b60006020820190508181036000830152614b9a8184613c62565b905092915050565b60006020820190508181036000830152614bbb81613ccc565b9050919050565b60006020820190508181036000830152614bdb81613d0c565b9050919050565b60006020820190508181036000830152614bfb81613d4c565b9050919050565b60006020820190508181036000830152614c1b81613db2565b9050919050565b60006020820190508181036000830152614c3b81613e18565b9050919050565b60006020820190508181036000830152614c5b81613e7e565b9050919050565b60006020820190508181036000830152614c7b81613ee4565b9050919050565b60006020820190508181036000830152614c9b81613f4a565b9050919050565b60006020820190508181036000830152614cbb81613f8a565b9050919050565b60006020820190508181036000830152614cdb8161400a565b9050919050565b60006020820190508181036000830152614cfb81614070565b9050919050565b60006020820190508181036000830152614d1b816140b0565b9050919050565b60006020820190508181036000830152614d3b81614116565b9050919050565b60006020820190508181036000830152614d5b81614156565b9050919050565b60006020820190508181036000830152614d7b816141bc565b9050919050565b60006020820190508181036000830152614d9b81614222565b9050919050565b60006020820190508181036000830152614dbb81614288565b9050919050565b60006020820190508181036000830152614ddb816142ee565b9050919050565b60006020820190508181036000830152614dfb81614354565b9050919050565b60006020820190508181036000830152614e1b816143ba565b9050919050565b60006020820190508181036000830152614e3b81614420565b9050919050565b60006020820190508181036000830152614e5b81614460565b9050919050565b60006020820190508181036000830152614e7b816144c6565b9050919050565b60006020820190508181036000830152614e9b8161452c565b9050919050565b60006020820190508181036000830152614ebb8161456c565b9050919050565b60006020820190508181036000830152614edb816145d2565b9050919050565b60006020820190508181036000830152614efb81614638565b9050919050565b60006020820190508181036000830152614f1b8161469e565b9050919050565b60006020820190508181036000830152614f3b81614704565b9050919050565b60006020820190508181036000830152614f5b8161476a565b9050919050565b60006020820190508181036000830152614f7b816147aa565b9050919050565b60006020820190508181036000830152614f9b81614810565b9050919050565b60006020820190508181036000830152614fbb81614876565b9050919050565b60006020820190508181036000830152614fdb816148dc565b9050919050565b6000602082019050614ff76000830184614951565b92915050565b6000808335600160200384360303811261501657600080fd5b80840192508235915067ffffffffffffffff82111561503457600080fd5b60208301925060018202360383131561504c57600080fd5b509250929050565b6000808335600160200384360303811261506d57600080fd5b80840192508235915067ffffffffffffffff82111561508b57600080fd5b6020830192506001820236038313156150a357600080fd5b509250929050565b6000604051905081810181811067ffffffffffffffff821117156150d2576150d16154b8565b5b8060405250919050565b600067ffffffffffffffff8211156150f7576150f66154b8565b5b601f19601f8301169050602081019050919050565b6000819050602082019050919050565b600081519050919050565b600081519050919050565b600081519050919050565b6000602082019050919050565b600082825260208201905092915050565b600082825260208201905092915050565b600081905092915050565b600082825260208201905092915050565b600081905092915050565b600061519e8261531c565b91506151a98361531c565b9250827fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff038211156151de576151dd61542b565b5b828201905092915050565b60006151f48261531c565b91506151ff8361531c565b92508261520f5761520e61545a565b5b828204905092915050565b60006152258261531c565b91506152308361531c565b9250817fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff04831182151516156152695761526861542b565b5b828202905092915050565b600061527f8261531c565b915061528a8361531c565b92508282101561529d5761529c61542b565b5b828203905092915050565b60006152b3826152fc565b9050919050565b60008115159050919050565b6000819050919050565b60007fffffffff0000000000000000000000000000000000000000000000000000000082169050919050565b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b6000819050919050565b600060ff82169050919050565b82818337600083830152505050565b60005b83811015615360578082015181840152602081019050615345565b8381111561536f576000848401525b50505050565b6000600282049050600182168061538d57607f821691505b602082108114156153a1576153a0615489565b5b50919050565b60006153b28261531c565b91507fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff8214156153e5576153e461542b565b5b600182019050919050565b6000819050919050565b60006154058261531c565b91506154108361531c565b9250826154205761541f61545a565b5b828206905092915050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601260045260246000fd5b7f4e487b7100000000000000000000000000000000000000000000000000000000600052602260045260246000fd5b7f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b6000601f19601f8301169050919050565b615501816152a8565b811461550c57600080fd5b50565b615518816152ba565b811461552357600080fd5b50565b61552f816152d0565b811461553a57600080fd5b50565b6155468161531c565b811461555157600080fd5b5056fea2646970667358221220d1fdcb859005b8626cc37f62b0664c72c37a0a6538e14770bc4cf68b363cf33664736f6c63430008000033
Verified Source Code Full Match
Compiler: v0.8.0+commit.c7dfd78e
EVM: istanbul
Optimization: No
MintedTeddyNFT.sol 226 lines
//Contract based on [https://docs.openzeppelin.com/contracts/3.x/erc721](https://docs.openzeppelin.com/contracts/3.x/erc721)
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import "@openzeppelin/contracts/token/ERC721/ERC721.sol";
import "@openzeppelin/contracts/token/ERC721/extensions/ERC721Enumerable.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
import "@openzeppelin/contracts/token/ERC721/extensions/ERC721URIStorage.sol";
import "@openzeppelin/contracts/utils/cryptography/ECDSA.sol";
import "@openzeppelin/contracts/utils/cryptography/draft-EIP712.sol";
contract MintedTeddyNFT is ERC721URIStorage, ERC721Enumerable, EIP712, Ownable {
string private constant SIGNING_DOMAIN = "MintedTeddy-Voucher";
string private constant SIGNATURE_VERSION = "1";
mapping(uint256 => bool) private _locks;
mapping(uint256 => uint256) private _editions;
mapping(uint256 => uint256) private _maxSupply;
/// @notice Sets the supply limits for each Minted Teddy drop. These are hard limits that cannot be changed.
constructor()
ERC721("MintedTeddy", "MINTEDTEDDY")
EIP712(SIGNING_DOMAIN, SIGNATURE_VERSION) {
_maxSupply[1] = 100;
_maxSupply[2] = 1000;
_maxSupply[3] = 10000;
_maxSupply[4] = 10;
_maxSupply[5] = 1;
}
/// @notice The NFTVoucher struct describes a mintable voucher.
/// @param tokenId This is the Token ID that will be minted.
/// @param locked If the NFT is unlocked, the metadata can be updated. This allows a minter to order a custom nft.
/// @param edition This is the Minted Teddy edition. It corresponds to the _maxSupply values.
/// @param initialPrice This is how much it costs to mint the teddy.
/// @param uri This is a URI that points to the metadata file.
/// @param signature This is generated when the signer signs the voucher when it's created.
struct NFTVoucher {
uint256 tokenId;
bool locked;
uint256 edition;
string initialPrice;
string uri;
bytes signature;
}
/// @dev See {IERC721Metadata-tokenURI}.
function tokenURI(uint256 tokenId) public view override(ERC721, ERC721URIStorage) returns (string memory)
{
return super.tokenURI(tokenId);
}
/// @dev See {IERC165-supportsInterface}.
function supportsInterface(bytes4 interfaceId) public view override(ERC721, ERC721Enumerable) returns (bool) {
return super.supportsInterface(interfaceId);
}
/// @notice This gets the balance of the ETH stored in the contract.
function getBalance() external view returns (uint256) {
return address(this).balance;
}
/// @notice Returns the chain id of the current blockchain.
/// @dev This is used to workaround an issue with ganache returning different values from the on-chain chainid() function and
/// the eth_chainId RPC method. See https://github.com/protocol/nft-website/issues/121 for context.
function getChainID() external view returns (uint256) {
uint256 id;
assembly {
id := chainid()
}
return id;
}
/// @notice This returns the number of Teddies that can be minted in an edition.
function maxSupply(uint256 edition) external view returns (uint256) {
return _maxSupply[edition];
}
/// @notice This mints a teddy.
/// @param recipient This is the address of the user who is minting the teddy.
/// @param voucher This is the unique NFTVoucher that is to be minted.
function mintNFT(address recipient, NFTVoucher calldata voucher) external payable returns (uint256) {
address signer = _verify(voucher);
require(voucher.tokenId > 0, "Invalid Token ID.");
require(voucher.edition >= 1 && voucher.edition <= 5, "Invalid token data. (Edition must be between 1 and 5)");
require(voucher.locked == true || (voucher.locked == false && voucher.edition == 1), "Only first edition NFT's can be minted unlocked.");
require(owner() == signer, "This voucher is invalid.");
require(msg.value == _safeParseInt(voucher.initialPrice), "Incorrect amount of ETH sent.");
require(_editions[voucher.edition] < _maxSupply[voucher.edition], "No more NFT's available to be minted.");
_setTokenLock(voucher.tokenId, voucher.locked);
_incrementEditionCount(voucher.edition);
_safeMint(recipient, voucher.tokenId);
_setTokenURI(voucher.tokenId, voucher.uri);
return voucher.tokenId;
}
/// @notice This returns the number of teddies that have been minted in an edition.
function totalEditionSupply(uint256 edition) external view returns (uint256) {
return _editions[edition];
}
/// @notice When a user orders a custom NFT, the user works with our designer to build the perfect NFT.
/// Once happy with the product, the metadata is updated using this function and locked.
/// @param tokenId The Token ID to be updated
/// @param uri The new URI to be set on the token.
function updateMetadata(uint256 tokenId, string calldata uri) external onlyOwner {
require(tokenId <= 100, "Customizations are only available for the first 100 tokens.");
require(_locks[tokenId] != true, "The metadata for this token is locked.");
_setTokenLock(tokenId, true);
_setTokenURI(tokenId, uri);
}
/// @notice This will transfer all ETH from the smart contract to the contract owner.
function withdraw() external onlyOwner {
payable(msg.sender).transfer(address(this).balance);
}
/// @notice Gets all the tokens that the address owns.
/// @param _owner The address of an owner you want to view tokens of.
function getTokenIds(address _owner) external view returns (uint[] memory) {
uint[] memory _tokensOfOwner = new uint[](balanceOf(_owner));
uint i;
for (i = 0; i < balanceOf(_owner); i++) {
_tokensOfOwner[i] = tokenOfOwnerByIndex(_owner, i);
}
return (_tokensOfOwner);
}
/// @notice Returns a hash of the given NFTVoucher, prepared using EIP712 typed data hashing rules.
/// @param voucher An NFTVoucher to hash.
function _hash(NFTVoucher calldata voucher) private view returns (bytes32) {
return _hashTypedDataV4(keccak256(abi.encode(
keccak256("NFTVoucher(uint256 tokenId,bool locked,uint256 edition,string initialPrice,string uri)"),
voucher.tokenId,
voucher.locked,
voucher.edition,
keccak256(bytes(voucher.initialPrice)),
keccak256(bytes(voucher.uri))
)));
}
/// @notice This safely converts a string into an uint.
/// @param _a This is the string to be converted into a uint.
function _safeParseInt(string memory _a) private pure returns (uint _parsedInt) {
bytes memory bresult = bytes(_a);
uint mint = 0;
bool decimals = false;
for (uint i = 0; i < bresult.length; i++) {
if ((uint(uint8(bresult[i])) >= 48) && (uint(uint8(bresult[i])) <= 57)) {
if (decimals) {
break;
}
mint *= 10;
mint += uint(uint8(bresult[i])) - 48;
} else if (uint(uint8(bresult[i])) == 46) {
require(!decimals, 'More than one decimal encountered in string!');
decimals = true;
} else {
revert("Non-numeral character encountered in string!");
}
}
return mint;
}
/// @notice This will increment the number of tokens that have been minted for an edition
/// @param edition The edition number for which we are incrementing
function _incrementEditionCount(uint256 edition) private {
_editions[edition] = _editions[edition] + 1;
}
/// @notice This will set the lock value for a token
/// @param tokenId The ID of the token you are setting
/// @param locked The state you wish to put the token into
function _setTokenLock(uint256 tokenId, bool locked) private {
_locks[tokenId] = locked;
}
/// @notice Verifies the signature for a given NFTVoucher, returning the address of the signer.
/// @dev Will revert if the signature is invalid. Does not verify that the signer is authorized to mint NFTs.
/// @param voucher An NFTVoucher describing an unminted NFT.
function _verify(NFTVoucher calldata voucher) private view returns (address) {
bytes32 digest = _hash(voucher);
return ECDSA.recover(digest, voucher.signature);
}
/**
* @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 override(ERC721, ERC721Enumerable) {
super._beforeTokenTransfer(from, to, tokenId);
}
/**
* @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 _burn(uint256 tokenId) internal override(ERC721, ERC721URIStorage) {
super._burn(tokenId);
}
}
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);
}
}
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;
}
ECDSA.sol 219 lines
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
/**
* @dev Elliptic Curve Digital Signature Algorithm (ECDSA) operations.
*
* These functions can be used to verify that a message was signed by the holder
* of the private keys of a given address.
*/
library ECDSA {
enum RecoverError {
NoError,
InvalidSignature,
InvalidSignatureLength,
InvalidSignatureS,
InvalidSignatureV
}
function _throwError(RecoverError error) private pure {
if (error == RecoverError.NoError) {
return; // no error: do nothing
} else if (error == RecoverError.InvalidSignature) {
revert("ECDSA: invalid signature");
} else if (error == RecoverError.InvalidSignatureLength) {
revert("ECDSA: invalid signature length");
} else if (error == RecoverError.InvalidSignatureS) {
revert("ECDSA: invalid signature 's' value");
} else if (error == RecoverError.InvalidSignatureV) {
revert("ECDSA: invalid signature 'v' value");
}
}
/**
* @dev Returns the address that signed a hashed message (`hash`) with
* `signature` or error string. This address can then be used for verification purposes.
*
* The `ecrecover` EVM opcode allows for malleable (non-unique) signatures:
* this function rejects them by requiring the `s` value to be in the lower
* half order, and the `v` value to be either 27 or 28.
*
* IMPORTANT: `hash` _must_ be the result of a hash operation for the
* verification to be secure: it is possible to craft signatures that
* recover to arbitrary addresses for non-hashed data. A safe way to ensure
* this is by receiving a hash of the original message (which may otherwise
* be too long), and then calling {toEthSignedMessageHash} on it.
*
* Documentation for signature generation:
* - with https://web3js.readthedocs.io/en/v1.3.4/web3-eth-accounts.html#sign[Web3.js]
* - with https://docs.ethers.io/v5/api/signer/#Signer-signMessage[ethers]
*
* _Available since v4.3._
*/
function tryRecover(bytes32 hash, bytes memory signature) internal pure returns (address, RecoverError) {
// Check the signature length
// - case 65: r,s,v signature (standard)
// - case 64: r,vs signature (cf https://eips.ethereum.org/EIPS/eip-2098) _Available since v4.1._
if (signature.length == 65) {
bytes32 r;
bytes32 s;
uint8 v;
// ecrecover takes the signature parameters, and the only way to get them
// currently is to use assembly.
assembly {
r := mload(add(signature, 0x20))
s := mload(add(signature, 0x40))
v := byte(0, mload(add(signature, 0x60)))
}
return tryRecover(hash, v, r, s);
} else if (signature.length == 64) {
bytes32 r;
bytes32 vs;
// ecrecover takes the signature parameters, and the only way to get them
// currently is to use assembly.
assembly {
r := mload(add(signature, 0x20))
vs := mload(add(signature, 0x40))
}
return tryRecover(hash, r, vs);
} else {
return (address(0), RecoverError.InvalidSignatureLength);
}
}
/**
* @dev Returns the address that signed a hashed message (`hash`) with
* `signature`. This address can then be used for verification purposes.
*
* The `ecrecover` EVM opcode allows for malleable (non-unique) signatures:
* this function rejects them by requiring the `s` value to be in the lower
* half order, and the `v` value to be either 27 or 28.
*
* IMPORTANT: `hash` _must_ be the result of a hash operation for the
* verification to be secure: it is possible to craft signatures that
* recover to arbitrary addresses for non-hashed data. A safe way to ensure
* this is by receiving a hash of the original message (which may otherwise
* be too long), and then calling {toEthSignedMessageHash} on it.
*/
function recover(bytes32 hash, bytes memory signature) internal pure returns (address) {
(address recovered, RecoverError error) = tryRecover(hash, signature);
_throwError(error);
return recovered;
}
/**
* @dev Overload of {ECDSA-tryRecover} that receives the `r` and `vs` short-signature fields separately.
*
* See https://eips.ethereum.org/EIPS/eip-2098[EIP-2098 short signatures]
*
* _Available since v4.3._
*/
function tryRecover(
bytes32 hash,
bytes32 r,
bytes32 vs
) internal pure returns (address, RecoverError) {
bytes32 s;
uint8 v;
assembly {
s := and(vs, 0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff)
v := add(shr(255, vs), 27)
}
return tryRecover(hash, v, r, s);
}
/**
* @dev Overload of {ECDSA-recover} that receives the `r and `vs` short-signature fields separately.
*
* _Available since v4.2._
*/
function recover(
bytes32 hash,
bytes32 r,
bytes32 vs
) internal pure returns (address) {
(address recovered, RecoverError error) = tryRecover(hash, r, vs);
_throwError(error);
return recovered;
}
/**
* @dev Overload of {ECDSA-tryRecover} that receives the `v`,
* `r` and `s` signature fields separately.
*
* _Available since v4.3._
*/
function tryRecover(
bytes32 hash,
uint8 v,
bytes32 r,
bytes32 s
) internal pure returns (address, RecoverError) {
// EIP-2 still allows signature malleability for ecrecover(). Remove this possibility and make the signature
// unique. Appendix F in the Ethereum Yellow paper (https://ethereum.github.io/yellowpaper/paper.pdf), defines
// the valid range for s in (301): 0 < s < secp256k1n ÷ 2 + 1, and for v in (302): v ∈ {27, 28}. Most
// signatures from current libraries generate a unique signature with an s-value in the lower half order.
//
// If your library generates malleable signatures, such as s-values in the upper range, calculate a new s-value
// with 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141 - s1 and flip v from 27 to 28 or
// vice versa. If your library also generates signatures with 0/1 for v instead 27/28, add 27 to v to accept
// these malleable signatures as well.
if (uint256(s) > 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF5D576E7357A4501DDFE92F46681B20A0) {
return (address(0), RecoverError.InvalidSignatureS);
}
if (v != 27 && v != 28) {
return (address(0), RecoverError.InvalidSignatureV);
}
// If the signature is valid (and not malleable), return the signer address
address signer = ecrecover(hash, v, r, s);
if (signer == address(0)) {
return (address(0), RecoverError.InvalidSignature);
}
return (signer, RecoverError.NoError);
}
/**
* @dev Overload of {ECDSA-recover} that receives the `v`,
* `r` and `s` signature fields separately.
*/
function recover(
bytes32 hash,
uint8 v,
bytes32 r,
bytes32 s
) internal pure returns (address) {
(address recovered, RecoverError error) = tryRecover(hash, v, r, s);
_throwError(error);
return recovered;
}
/**
* @dev Returns an Ethereum Signed Message, created from a `hash`. This
* produces hash corresponding to the one signed with the
* https://eth.wiki/json-rpc/API#eth_sign[`eth_sign`]
* JSON-RPC method as part of EIP-191.
*
* See {recover}.
*/
function toEthSignedMessageHash(bytes32 hash) internal pure returns (bytes32) {
// 32 is the length in bytes of hash,
// enforced by the type signature above
return keccak256(abi.encodePacked("\x19Ethereum Signed Message:\n32", hash));
}
/**
* @dev Returns an Ethereum Signed Typed Data, created from a
* `domainSeparator` and a `structHash`. This produces hash corresponding
* to the one signed with the
* https://eips.ethereum.org/EIPS/eip-712[`eth_signTypedData`]
* JSON-RPC method as part of EIP-712.
*
* See {recover}.
*/
function toTypedDataHash(bytes32 domainSeparator, bytes32 structHash) internal pure returns (bytes32) {
return keccak256(abi.encodePacked("\x19\x01", domainSeparator, structHash));
}
}
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);
}
draft-EIP712.sol 101 lines
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import "./ECDSA.sol";
/**
* @dev https://eips.ethereum.org/EIPS/eip-712[EIP 712] is a standard for hashing and signing of typed structured data.
*
* The encoding specified in the EIP is very generic, and such a generic implementation in Solidity is not feasible,
* thus this contract does not implement the encoding itself. Protocols need to implement the type-specific encoding
* they need in their contracts using a combination of `abi.encode` and `keccak256`.
*
* This contract implements the EIP 712 domain separator ({_domainSeparatorV4}) that is used as part of the encoding
* scheme, and the final step of the encoding to obtain the message digest that is then signed via ECDSA
* ({_hashTypedDataV4}).
*
* The implementation of the domain separator was designed to be as efficient as possible while still properly updating
* the chain id to protect against replay attacks on an eventual fork of the chain.
*
* NOTE: This contract implements the version of the encoding known as "v4", as implemented by the JSON RPC method
* https://docs.metamask.io/guide/signing-data.html[`eth_signTypedDataV4` in MetaMask].
*
* _Available since v3.4._
*/
abstract contract EIP712 {
/* solhint-disable var-name-mixedcase */
// Cache the domain separator as an immutable value, but also store the chain id that it corresponds to, in order to
// invalidate the cached domain separator if the chain id changes.
bytes32 private immutable _CACHED_DOMAIN_SEPARATOR;
uint256 private immutable _CACHED_CHAIN_ID;
bytes32 private immutable _HASHED_NAME;
bytes32 private immutable _HASHED_VERSION;
bytes32 private immutable _TYPE_HASH;
/* solhint-enable var-name-mixedcase */
/**
* @dev Initializes the domain separator and parameter caches.
*
* The meaning of `name` and `version` is specified in
* https://eips.ethereum.org/EIPS/eip-712#definition-of-domainseparator[EIP 712]:
*
* - `name`: the user readable name of the signing domain, i.e. the name of the DApp or the protocol.
* - `version`: the current major version of the signing domain.
*
* NOTE: These parameters cannot be changed except through a xref:learn::upgrading-smart-contracts.adoc[smart
* contract upgrade].
*/
constructor(string memory name, string memory version) {
bytes32 hashedName = keccak256(bytes(name));
bytes32 hashedVersion = keccak256(bytes(version));
bytes32 typeHash = keccak256(
"EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)"
);
_HASHED_NAME = hashedName;
_HASHED_VERSION = hashedVersion;
_CACHED_CHAIN_ID = block.chainid;
_CACHED_DOMAIN_SEPARATOR = _buildDomainSeparator(typeHash, hashedName, hashedVersion);
_TYPE_HASH = typeHash;
}
/**
* @dev Returns the domain separator for the current chain.
*/
function _domainSeparatorV4() internal view returns (bytes32) {
if (block.chainid == _CACHED_CHAIN_ID) {
return _CACHED_DOMAIN_SEPARATOR;
} else {
return _buildDomainSeparator(_TYPE_HASH, _HASHED_NAME, _HASHED_VERSION);
}
}
function _buildDomainSeparator(
bytes32 typeHash,
bytes32 nameHash,
bytes32 versionHash
) private view returns (bytes32) {
return keccak256(abi.encode(typeHash, nameHash, versionHash, block.chainid, address(this)));
}
/**
* @dev Given an already https://eips.ethereum.org/EIPS/eip-712#definition-of-hashstruct[hashed struct], this
* function returns the hash of the fully encoded EIP712 message for this domain.
*
* This hash can be used together with {ECDSA-recover} to obtain the signer of a message. For example:
*
* ```solidity
* bytes32 digest = _hashTypedDataV4(keccak256(abi.encode(
* keccak256("Mail(address to,string contents)"),
* mailTo,
* keccak256(bytes(mailContents))
* )));
* address signer = ECDSA.recover(digest, signature);
* ```
*/
function _hashTypedDataV4(bytes32 structHash) internal view virtual returns (bytes32) {
return ECDSA.toTypedDataHash(_domainSeparatorV4(), structHash);
}
}
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);
}
ERC721Enumerable.sol 162 lines
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import "../ERC721.sol";
import "./IERC721Enumerable.sol";
/**
* @dev This implements an optional extension of {ERC721} defined in the EIP that adds
* enumerability of all the token ids in the contract as well as all token ids owned by each
* account.
*/
abstract contract ERC721Enumerable is ERC721, IERC721Enumerable {
// Mapping from owner to list of owned token IDs
mapping(address => mapping(uint256 => uint256)) private _ownedTokens;
// Mapping from token ID to index of the owner tokens list
mapping(uint256 => uint256) private _ownedTokensIndex;
// Array with all token ids, used for enumeration
uint256[] private _allTokens;
// Mapping from token id to position in the allTokens array
mapping(uint256 => uint256) private _allTokensIndex;
/**
* @dev See {IERC165-supportsInterface}.
*/
function supportsInterface(bytes4 interfaceId) public view virtual override(IERC165, ERC721) returns (bool) {
return interfaceId == type(IERC721Enumerable).interfaceId || super.supportsInterface(interfaceId);
}
/**
* @dev See {IERC721Enumerable-tokenOfOwnerByIndex}.
*/
function tokenOfOwnerByIndex(address owner, uint256 index) public view virtual override returns (uint256) {
require(index < ERC721.balanceOf(owner), "ERC721Enumerable: owner index out of bounds");
return _ownedTokens[owner][index];
}
/**
* @dev See {IERC721Enumerable-totalSupply}.
*/
function totalSupply() public view virtual override returns (uint256) {
return _allTokens.length;
}
/**
* @dev See {IERC721Enumerable-tokenByIndex}.
*/
function tokenByIndex(uint256 index) public view virtual override returns (uint256) {
require(index < ERC721Enumerable.totalSupply(), "ERC721Enumerable: global index out of bounds");
return _allTokens[index];
}
/**
* @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` cannot be the zero address.
* - `to` cannot be the zero address.
*
* 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 override {
super._beforeTokenTransfer(from, to, tokenId);
if (from == address(0)) {
_addTokenToAllTokensEnumeration(tokenId);
} else if (from != to) {
_removeTokenFromOwnerEnumeration(from, tokenId);
}
if (to == address(0)) {
_removeTokenFromAllTokensEnumeration(tokenId);
} else if (to != from) {
_addTokenToOwnerEnumeration(to, tokenId);
}
}
/**
* @dev Private function to add a token to this extension's ownership-tracking data structures.
* @param to address representing the new owner of the given token ID
* @param tokenId uint256 ID of the token to be added to the tokens list of the given address
*/
function _addTokenToOwnerEnumeration(address to, uint256 tokenId) private {
uint256 length = ERC721.balanceOf(to);
_ownedTokens[to][length] = tokenId;
_ownedTokensIndex[tokenId] = length;
}
/**
* @dev Private function to add a token to this extension's token tracking data structures.
* @param tokenId uint256 ID of the token to be added to the tokens list
*/
function _addTokenToAllTokensEnumeration(uint256 tokenId) private {
_allTokensIndex[tokenId] = _allTokens.length;
_allTokens.push(tokenId);
}
/**
* @dev Private function to remove a token from this extension's ownership-tracking data structures. Note that
* while the token is not assigned a new owner, the `_ownedTokensIndex` mapping is _not_ updated: this allows for
* gas optimizations e.g. when performing a transfer operation (avoiding double writes).
* This has O(1) time complexity, but alters the order of the _ownedTokens array.
* @param from address representing the previous owner of the given token ID
* @param tokenId uint256 ID of the token to be removed from the tokens list of the given address
*/
function _removeTokenFromOwnerEnumeration(address from, uint256 tokenId) private {
// To prevent a gap in from's tokens array, we store the last token in the index of the token to delete, and
// then delete the last slot (swap and pop).
uint256 lastTokenIndex = ERC721.balanceOf(from) - 1;
uint256 tokenIndex = _ownedTokensIndex[tokenId];
// When the token to delete is the last token, the swap operation is unnecessary
if (tokenIndex != lastTokenIndex) {
uint256 lastTokenId = _ownedTokens[from][lastTokenIndex];
_ownedTokens[from][tokenIndex] = lastTokenId; // Move the last token to the slot of the to-delete token
_ownedTokensIndex[lastTokenId] = tokenIndex; // Update the moved token's index
}
// This also deletes the contents at the last position of the array
delete _ownedTokensIndex[tokenId];
delete _ownedTokens[from][lastTokenIndex];
}
/**
* @dev Private function to remove a token from this extension's token tracking data structures.
* This has O(1) time complexity, but alters the order of the _allTokens array.
* @param tokenId uint256 ID of the token to be removed from the tokens list
*/
function _removeTokenFromAllTokensEnumeration(uint256 tokenId) private {
// To prevent a gap in the tokens array, we store the last token in the index of the token to delete, and
// then delete the last slot (swap and pop).
uint256 lastTokenIndex = _allTokens.length - 1;
uint256 tokenIndex = _allTokensIndex[tokenId];
// When the token to delete is the last token, the swap operation is unnecessary. However, since this occurs so
// rarely (when the last minted token is burnt) that we still do the swap here to avoid the gas cost of adding
// an 'if' statement (like in _removeTokenFromOwnerEnumeration)
uint256 lastTokenId = _allTokens[lastTokenIndex];
_allTokens[tokenIndex] = lastTokenId; // Move the last token to the slot of the to-delete token
_allTokensIndex[lastTokenId] = tokenIndex; // Update the moved token's index
// This also deletes the contents at the last position of the array
delete _allTokensIndex[tokenId];
_allTokens.pop();
}
}
ERC721URIStorage.sol 66 lines
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import "../ERC721.sol";
/**
* @dev ERC721 token with storage based token URI management.
*/
abstract contract ERC721URIStorage is ERC721 {
using Strings for uint256;
// Optional mapping for token URIs
mapping(uint256 => string) private _tokenURIs;
/**
* @dev See {IERC721Metadata-tokenURI}.
*/
function tokenURI(uint256 tokenId) public view virtual override returns (string memory) {
require(_exists(tokenId), "ERC721URIStorage: URI query for nonexistent token");
string memory _tokenURI = _tokenURIs[tokenId];
string memory base = _baseURI();
// If there is no base URI, return the token URI.
if (bytes(base).length == 0) {
return _tokenURI;
}
// If both are set, concatenate the baseURI and tokenURI (via abi.encodePacked).
if (bytes(_tokenURI).length > 0) {
return string(abi.encodePacked(base, _tokenURI));
}
return super.tokenURI(tokenId);
}
/**
* @dev Sets `_tokenURI` as the tokenURI of `tokenId`.
*
* Requirements:
*
* - `tokenId` must exist.
*/
function _setTokenURI(uint256 tokenId, string memory _tokenURI) internal virtual {
require(_exists(tokenId), "ERC721URIStorage: URI set of nonexistent token");
_tokenURIs[tokenId] = _tokenURI;
}
/**
* @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 override {
super._burn(tokenId);
if (bytes(_tokenURIs[tokenId]).length != 0) {
delete _tokenURIs[tokenId];
}
}
}
IERC721Enumerable.sol 28 lines
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import "../IERC721.sol";
/**
* @title ERC-721 Non-Fungible Token Standard, optional enumeration extension
* @dev See https://eips.ethereum.org/EIPS/eip-721
*/
interface IERC721Enumerable is IERC721 {
/**
* @dev Returns the total amount of tokens stored by the contract.
*/
function totalSupply() external view returns (uint256);
/**
* @dev Returns a token ID owned by `owner` at a given `index` of its token list.
* Use along with {balanceOf} to enumerate all of ``owner``'s tokens.
*/
function tokenOfOwnerByIndex(address owner, uint256 index) external view returns (uint256 tokenId);
/**
* @dev Returns a token ID at a given `index` of all the tokens stored by the contract.
* Use along with {totalSupply} to enumerate all tokens.
*/
function tokenByIndex(uint256 index) external view returns (uint256);
}
Read Contract
balanceOf 0x70a08231 → uint256
getApproved 0x081812fc → address
getBalance 0x12065fe0 → uint256
getChainID 0x564b81ef → uint256
getTokenIds 0xd004b036 → uint256[]
isApprovedForAll 0xe985e9c5 → bool
maxSupply 0x869f7594 → uint256
name 0x06fdde03 → string
owner 0x8da5cb5b → address
ownerOf 0x6352211e → address
supportsInterface 0x01ffc9a7 → bool
symbol 0x95d89b41 → string
tokenByIndex 0x4f6ccce7 → uint256
tokenOfOwnerByIndex 0x2f745c59 → uint256
tokenURI 0xc87b56dd → string
totalEditionSupply 0x71d458d4 → uint256
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
mintNFT 0x61662298
address recipient
tuple voucher
returns: uint256
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
transferFrom 0x23b872dd
address from
address to
uint256 tokenId
transferOwnership 0xf2fde38b
address newOwner
updateMetadata 0x53c8388e
uint256 tokenId
string uri
withdraw 0x3ccfd60b
No parameters
Recent Transactions
No transactions found for this address