The PixotchiPassport contract is an upgradeable ERC721-based NFT contract that allows users to mint and update NFTs using a signature-based mechanism. It leverages OpenZeppelin's upgradeable libraries and EIP-712 for secure signature verification.
- Minting and Updating: Users can mint new NFTs or update existing ones using signed vouchers.
- Upgradeable: The contract is designed to be upgradeable, ensuring future enhancements without disrupting the existing state.
- Signature Verification: Utilizes EIP-712 for secure and efficient signature verification.
- Enumerable and URI Storage: Extends
ERC721EnumerableUpgradeableandERC721URIStorageUpgradeablefor enhanced functionality.
-
Plant
struct Plant { uint256 id; uint256 level; uint256 score; string name; uint256 stars; uint256 timeUntilStarving; uint256 timePlantBorn; string strain; string ipfsHash; address owner; address contractAddress; }
-
Voucher
struct Voucher { address wallet; Plant plant; uint256 nonce; uint256 optionalUpdateId; bool update; }
-
MemoryCard
struct MemoryCard { string memoryCardUuid; string landUuid; string gardenUuid; string plotUuid; string salt; uint256 born; uint256 size; }
mapping(address => uint256) public nonce;mapping(uint256 => Plant) public plants;mapping(uint256 => MemoryCard) public memoryCards;
address public signer;bool public enabled;
event PlantMinted(address indexed to, uint256 indexed tokenId, Plant plant);
-
initialize
function initialize(address _signer) initializer public;
-
setSigner
function setSigner(address _signer) external onlyOwner;
-
signatureMint
function signatureMint(Voucher memory _voucher, bytes memory signature) external nonReentrant;
-
signatureUpdate
function signatureUpdate(Voucher memory _voucher, bytes memory signature) external nonReentrant;
-
tokenURI
function tokenURI(uint256 tokenId) public view override(ERC721Upgradeable) returns (string memory);
-
getIpfsHash
function getIpfsHash(uint256 tokenId) external view returns (string memory);
-
getNonce
function getNonce(address wallet) external view returns (uint256);
-
getPlant
function getPlant(uint256 tokenId) external view returns (Plant memory);
-
getPlants
function getPlants(uint256[] calldata tokenIds) external view returns (Plant[] memory);
-
getMemoryCard
function getMemoryCard(uint256 tokenId) external view returns (MemoryCard memory);
-
_hash
function _hash(Voucher memory _voucher) internal view returns (bytes32);
-
_verify
function _verify(bytes32 digest, bytes memory signature) internal view returns (bool);
- Deploy the contract using a tool like Truffle or Hardhat.
- Initialize the contract with the signer's address:
initialize(address _signer);
- Create a
Voucherstruct with the necessary plant data and nonce. - Sign the voucher off-chain using the signer's private key.
- Call the
signatureMintfunction with the voucher and signature:signatureMint(Voucher memory _voucher, bytes memory signature);
- Create a
Voucherstruct with the updated plant data, nonce, and setupdatetotrue. - Sign the voucher off-chain using the signer's private key.
- Call the
signatureUpdatefunction with the voucher and signature:signatureUpdate(Voucher memory _voucher, bytes memory signature);
Licensed under the MIT License. See the LICENSE file at the project root for details.
Built with ❤️ for the Pixotchi community