클레이아 신 스테이크어
Antes de comenzar
Para este tutorial ocuparás Metamask u otra 지갑 호환 con fondos en Goerli que puedes obtener desde un faucet .
로스 NFT
Primero lanzamos el contrato de NFTs, toma nota de la función
register
que hace posible esta magia.// SPDX-License-Identifier: MIT
pragma solidity 0.8.16;
import "@openzeppelin/contracts/token/ERC721/ERC721.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
interface ITokenContract
{
function register(uint tokenId) external;
}
contract NFTContract is ERC721, Ownable {
ITokenContract tokenContract;
uint public price = 0.001 ether;
uint public constant MAX_SUPPLY = 10000;
uint public supply;
constructor () ERC721 ("My NFT", "MNFT") {
}
function mint(uint _amount) public payable {
require( supply + _amount <= MAX_SUPPLY, "Can't mint more than max supply" );
require( msg.value == price * _amount, "Wrong amount of ETH sent" );
require( _amount >= 1, "Must mint at least one" );
for(uint i; i < _amount; i++){
_safeMint( msg.sender, supply + i );
tokenContract.register(supply + i);
}
}
function withdrawETH() public onlyOwner
{
(bool sent, bytes memory data) = address(owner()).call{value: address(this).balance}("");
require(sent, "Failed to send Ether");
data;
}
function setTokenContract(address tokenContractAddress) public onlyOwner {
tokenContract = ITokenContract(tokenContractAddress);
}
}
로스토큰
El mismo contrato de tokens se encarga de distribuir las recompenzas a los holders. Luego de Lanzarlo el contrato de tokens, asegurate de conectarlo con el contrato de NFTs ejecutando la función
setTokenContract
. Esto permitirá a quienes minteen los nfts empezar a mintear y recibir recompenzas.// SPDX-License-Identifier: MIT
pragma solidity 0.8.16;
import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
interface INFTContract
{
function ownerOf(uint tokenId) external view returns (address owner);
}
contract TokenContract is ERC20, Ownable {
uint public REWARD_PER_BLOCK = 0.1 ether;
INFTContract public myERC721Contract;
mapping(uint => uint) public checkpoints;
mapping(uint => bool) public isRegistered;
constructor(address nftContractAddress) ERC20("My Token", "TKN") {
myERC721Contract = INFTContract(nftContractAddress);
}
function register(uint tokenId) public
{
require(msg.sender == address(myERC721Contract));
isRegistered[tokenId] = true;
checkpoints[tokenId] = block.number;
}
function claim(uint tokenId) public
{
require(myERC721Contract.ownerOf(tokenId) == msg.sender, "Must be token owner");
uint256 reward = calculateReward(tokenId);
_mint(msg.sender, reward);
checkpoints[tokenId] = block.number;
}
function calculateReward(uint tokenId) public view returns(uint256)
{
if(!isRegistered[tokenId])
{
return 0;
}
uint256 checkpoint = checkpoints[tokenId];
return REWARD_PER_BLOCK * (block.number-checkpoint);
}
}
Gracias por ver este 비디오!
Sígannos en dev.to y en para todo lo relacionado al desarrollo en Blockchain en Español.
Reference
이 문제에 관하여(클레이아 신 스테이크어), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://dev.to/turupawn/claimea-sin-stakear-1ofo텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념 (Collection and Share based on the CC Protocol.)