Created
March 11, 2022 09:49
-
-
Save webbravo/fd3c014c2eaa7b5447bdfd2580c7ca88 to your computer and use it in GitHub Desktop.
Created using remix-ide: Realtime Ethereum Contract Compiler and Runtime. Load this file by pasting this gists URL or ID at https://remix.ethereum.org/#version=undefined&optimize=false&runs=200&gist=
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// contracts/GameItem.sol | |
// SPDX-License-Identifier: MIT | |
pragma solidity >=0.7.0 <0.9.0; | |
import "@openzeppelin/contracts/token/ERC721/extensions/ERC721URIStorage.sol"; | |
import "@openzeppelin/contracts/utils/Counters.sol"; | |
import "@openzeppelin/contracts/access/Ownable.sol"; | |
contract LandToken is ERC721URIStorage, Ownable { | |
using Counters for Counters.Counter; | |
Counters.Counter private _tokenIds; | |
constructor() ERC721("zkLandToken", "ZKL") {} | |
// Set an array of hashes to hold all | |
bytes32[] private hashes; | |
// Set a static public on-chain TokenURL | |
// Set TokenURL as a constant to as to save gas | |
function assignLands(address receiver, string memory tokenURI) | |
public | |
onlyOwner | |
returns (uint256) | |
{ | |
// Increment our token ID by one | |
_tokenIds.increment(); | |
// Generate a token ID for the NFT to be created | |
uint256 newItemId = _tokenIds.current(); | |
// Mints a new land NFT | |
_mint(receiver, newItemId); | |
_setTokenURI(newItemId, tokenURI); | |
// Hash all data and assign to hashes array | |
hashes.push(hash(msg.sender, receiver, newItemId, tokenURI)); | |
return newItemId; | |
} | |
function getAllHashed() public view returns (bytes32[] memory) { | |
return hashes; | |
} | |
// addr1: 0x5B38Da6a701c568545dCfcB03FcB875f56beddC4, | |
// addr2: 0x4B20993Bc481177ec7E8f571ceCaE8A9e22C02db, | |
// TokenURL: https://gateway.pinata.cloud/ipfs/QmbdGNCYQp5oZxvphJ9CSNFbtSDb6vvpcgJ6Q97k1ZP6fA | |
function hash( | |
address _sender, | |
address _receiver, | |
uint256 _newItemId, | |
string memory _tokenURI) | |
private pure returns (bytes32) { | |
return keccak256(abi.encodePacked(_sender, _receiver, _newItemId, _tokenURI)); | |
} | |
} | |
contract ERC721MerkleDrop is ERC721 { | |
bytes32 immutable public root; | |
constructor(string memory name, string memory symbol, bytes32 merkleroot) | |
ERC721(name, symbol) | |
{ | |
root = merkleroot; | |
} | |
function redeem(address account, uint256 tokenId, bytes32[] calldata proof) | |
external | |
{ | |
require(_verify(_leaf(account, tokenId), proof), "Invalid merkle proof"); | |
_safeMint(account, tokenId); | |
} | |
function _leaf(address account, uint256 tokenId) | |
internal pure returns (bytes32) | |
{ | |
return keccak256(abi.encodePacked(tokenId, account)); | |
} | |
function _verify(bytes32 leaf, bytes32[] memory proof) | |
internal view returns (bool) | |
{ | |
return MerkleProof.verify(proof, root, leaf); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment