Quick Start
Example
Let's say you're creating an awesome project that requires a 10KTF item to claim an exclusive item from your project. In your contract, you check to see if the person claiming owns at least one 10KTF item. We'll go step by step to see how you can migrate over to using Warm so users can feel more at ease when they're claiming the item from your contract!
Step by Step
- Your current implementation (ERC721)
// contracts/ExclusiveHolderClaim.sol // SPDX-License-Identifier: MIT pragma solidity ^0.8.0; import "@openzeppelin/contracts/token/ERC721/ERC721.sol"; interface TenKTFInterface { function balanceOf(address owner) external view returns (uint256); } contract ExclusiveHolderClaim is ERC721 { address public constant TENKTF_CONTRACT_ADDRESS = 0x0cfb5d82be2b949e8fa73a656df91821e2ad99fd; uint256 public tokenId = 0; constructor() ERC721("ExclusiveItem", "RARE") public {} function claim() external { TenKTFInterface tenKTFInstance = TenKTFInterface(TENKTF_CONTRACT_ADDRESS); require(tenKTFInstance.balanceOf(msg.sender) >= 1); _mint(msg.sender, tokenId++); } }
- First we'll add the Warm contract address to the contract
address public constant TENKTF_CONTRACT_ADDRESS = 0x0cfb5d82be2b949e8fa73a656df91821e2ad99fd; address public constant WARM_CONTRACT_ADDRESS = 0xC3AA9bc72Bd623168860a1e5c6a4530d3D80456c;
- Next we'll update our interface to use the Warm interface instead of the 10KTF interface
interface WarmInterface { function balanceOf(address contractAddress, address owner) external view returns (uint256); }
- Finally we'll update where we're calling balanceOf(), since now we're calling it from the Warm contract
WarmInterface warmInstance = WarmInterface(WARM_CONTRACT_ADDRESS); require(warmInstance.balanceOf(TENKTF_CONTRACT_ADDRESS, msg.sender) >= 1);
- That's all it takes! This should be what the final contract looks like - and now users can verify that they own a 10KTF without the risk of connecting their cold wallet
// contracts/ExclusiveHolderClaim.sol // SPDX-License-Identifier: MIT pragma solidity ^0.8.0; import "@openzeppelin/contracts/token/ERC721/ERC721.sol"; interface WarmInterface { function balanceOf(address contractAddress, address owner) external view returns (uint256); } contract ExclusiveHolderClaim is ERC721 { address public constant TENKTF_CONTRACT_ADDRESS = 0x0cfb5d82be2b949e8fa73a656df91821e2ad99fd; address public constant WARM_CONTRACT_ADDRESS = 0xC3AA9bc72Bd623168860a1e5c6a4530d3D80456c; uint256 public tokenId = 0; constructor() ERC721("ExclusiveItem", "RARE") public {} function claim() external { WarmInterface warmInstance = WarmInterface(WARM_CONTRACT_ADDRESS); require(warmInstance.balanceOf(TENKTF_CONTRACT_ADDRESS, msg.sender) >= 1); _mint(msg.sender, tokenId++); } }
Extra Examples
ERC1155 (checking for REQUIRED_TOKEN_ID)
// contracts/ExclusiveHolderClaim.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import "@openzeppelin/contracts/token/ERC1155/ERC1155.sol";
interface WarmInterface {
function balanceOf(address contractAddress, address owner, uint256 tokenId) external view returns (uint256);
}
contract ExclusiveHolderClaim is ERC1155 {
address public constant ERC_1155_ADDRESS = 0x1234567890123456789012345678901234567890;
address public constant WARM_CONTRACT_ADDRESS = 0xC3AA9bc72Bd623168860a1e5c6a4530d3D80456c;
uint256 public constant REQUIRED_TOKEN_ID = 2;
uint256 public tokenId = 0;
constructor() ERC1155("https://sampleBaseUri.com") public {}
function claim()
external
{
WarmInterface warmInstance = WarmInterface(WARM_CONTRACT_ADDRESS);
require(warmInstance.balanceOf(ERC_1155_ADDRESS, msg.sender, REQUIRED_TOKEN_ID) >= 1);
_mint(msg.sender, tokenId++);
}
}