클레임즈 산 스테이커
전위 드 초보자
Pour ce video tu auras besoin de Metamask ou n'importe quel wallet compatible avec l'EVM et aussi du GoerliETH que tu peux trouver gratuitement en un faucet .
레 NFT
D'abord on lance un contrat d'NFTs, remarquez la funcion
registre
que fait tout ça possible.// 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);
}
}
레 토큰
Le même contrat de tokens distribue les récompenses aux 소지자. Tout de suite avoir déployé le contrat des tokens exécutez la function
setTokenContract
dans le contrat d'NFTs et passez comme paramètre l'adresse du contrat de tokens.// 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);
}
}
¡ Merci pour voir ce 비디오!
Suivez nous ici en dev.to et en pour ce qui a à voir avec Blockchain en Francais.
Reference
이 문제에 관하여(클레임즈 산 스테이커), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://dev.to/filosofiacodigofra/claimez-sans-staker-1opn텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념 (Collection and Share based on the CC Protocol.)