Skip to content

Instantly share code, notes, and snippets.

@simonvc
Created April 13, 2021 13:18
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save simonvc/33b7a45e9e0015e47a0cec23d3d103b2 to your computer and use it in GitHub Desktop.
Save simonvc/33b7a45e9e0015e47a0cec23d3d103b2 to your computer and use it in GitHub Desktop.
TreeDAO NFT Contract
// SPDX-License-Identifier: GPL-3.0
pragma solidity >=0.7.0 <0.9.0;
import "https://raw.githubusercontent.com/OpenZeppelin/openzeppelin-contracts/master/contracts/token/ERC721/presets/ERC721PresetMinterPauserAutoId.sol";
interface TreeToken {
function burnFrom(address, uint) external;
function allowance(address, address) external view returns (uint256);
function balanceOf(address) external view returns (uint256);
}
contract NFTree is ERC721PresetMinterPauserAutoId("TreeDAO NFTrees", "NFTrees", "https://treedao.org/trees/" ) {
TreeToken public TreeTokenContract;
function SetTreeTokenAddress(address tt) public {
// TODO access control here
require(hasRole(MINTER_ROLE, msg.sender), "Caller is not a minter");
TreeTokenContract = TreeToken(tt);
}
function GetTreeTokenAddress() public view returns (TreeToken) {
return TreeTokenContract;
}
function ClaimNFTs(uint numberOfNFTrees) public {
// The dapp must first approve this contract to allow this contract to burn their TreeTokens in exchange for NFTrees
require(TreeTokenContract.allowance(msg.sender, address(this)) >= numberOfNFTrees * 10**18, "You must approve the NFTree contract to spend your TreeTokens.");
require(TreeTokenContract.balanceOf(msg.sender) >= numberOfNFTrees * 10**18, "Your balance is too low to claim this many NFTrees");
// burnFrom msg.sender on the TreeTokenContract
TreeTokenContract.burnFrom(msg.sender, numberOfNFTrees * 10**18);
// mint that many NFTs taking care to remember the 18 decimal place difference in resolution
for (uint i=0; i<numberOfNFTrees; i++) {
mint(msg.sender);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment