简体   繁体   English

如何在 Solidity 智能合约中启用 Claim Tokens?

[英]How to enable Claim Tokens in Solidity Smart Contract?

I am currently using the Open Zapeline smart contract for my Dapp, I wanted to know if there is a way where users can claim my tokens (ie transfer from owner wallet to current user) I know a method with hardcoding the private keys but is there any way wherein the Smart Contract I can set msg.Sender as Owner or Transfer tokens from Owner account to the user without any signatures?我目前正在为我的 Dapp 使用 Open Zapeline 智能合约,我想知道是否有一种方法可以让用户索取我的代币(即从所有者钱包转移到当前用户) 我知道一种对私钥进行硬编码的方法,但是在那里智能合约我可以将 msg.Sender 设置为所有者或将令牌从所有者帐户转移到用户而无需任何签名的任何方式?

You can use the internal function _transfer() ( GitHub link ) that only validates is the from param is the actual owner of the token.您可以使用internal function _transfer()GitHub 链接),它仅验证from参数是令牌的实际所有者。 But it doesn't validate if the msg.sender is the token owner.但它不会验证msg.sender是否是令牌所有者。

Note that this function has internal visibility, so it's only executable from inside of your contract.请注意,此 function 具有internal可见性,因此只能从合约内部执行。

pragma solidity ^0.8;

import "@openzeppelin/contracts/token/ERC721/ERC721.sol";
import "@openzeppelin/contracts/access/Ownable.sol";

contract MyCollection is ERC721, Ownable {

    constructor() ERC721("MyCollection", "MyC") {
        _mint(owner(), 1);
    }

    function claim() external {
        require(ownerOf(1) == owner(), "Already claimed");
        _transfer(owner(), msg.sender, 1);
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM