Skip to content

Instantly share code, notes, and snippets.

@webbravo
Created March 11, 2022 09:46
Show Gist options
  • Save webbravo/4b8e5aea69983e26a00b2c08378c7c56 to your computer and use it in GitHub Desktop.
Save webbravo/4b8e5aea69983e26a00b2c08378c7c56 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=
// 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
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;
}
// addr: 0x5B38Da6a701c568545dCfcB03FcB875f56beddC4,
// addr: 0x4B20993Bc481177ec7E8f571ceCaE8A9e22C02db,
// URL: 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));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment