简体   繁体   English

铸造 erc721 但用 erc20 代币而不是以太币支付

[英]Minting erc721 but paying with erc20 token instead of ether

hope all is well.希望一切安好。

I have erc721 contract from openzeppelin @openzeppelin/contracts/token/ERC721/extensions/ERC721Enumerable.sol我有来自 openzeppelin @openzeppelin/contracts/token/ERC721/extensions/ERC721Enumerable.sol 的 erc721 合同

Where I today let users mint with ether:我今天让用户用以太币铸造的地方:

function mint(address _to, uint256 _mintAmount) public payable {
    uint256 supply = totalSupply();
    require(!paused);
    require(_mintAmount > 0);
    require(_mintAmount <= maxMintAmount);
    

    if (msg.sender != owner()) {
        if(whitelisted[msg.sender] != true) {
          require(msg.value >= cost * _mintAmount);
        }
    }

    for (uint256 i = 1; i <= _mintAmount; i++) {
      _safeMint(_to, supply + i);
    }
  }

Ive been trying to figure out how to switch the ether into my own erc20 token for days now and have been googling around but cannot find anything.几天来,我一直试图弄清楚如何将以太币转换为我自己的 erc20 代币,并且一直在谷歌搜索,但找不到任何东西。 If someone has any ideas they can share or links to point me into right direction that would be much appreciated!如果有人有任何想法,他们可以分享或链接以将我指向正确的方向,我们将不胜感激!

thanks in advance提前致谢

For doing this you should implement ERC20 into your ERC721 contract.为此,您应该在您的 ERC721 合约中实施 ERC20。

I would suggest first importing the ERC20 file from openzeppelin, and then creating an ERC20 variable which will be a pointer to your existing ERC20 token.我建议首先从 openzeppelin 导入 ERC20 文件,然后创建一个 ERC20 变量,该变量将指向您现有的 ERC20 令牌。 Something like this:像这样的东西:

ERC20 token = ERC20('address to your desired ERC20 Token');

Then you will be able to interact with the ERC20 token balance of the msg.sender using the 'balanceOf', 'approve', and 'transferFrom' functions.然后,您将能够使用“balanceOf”、“approve”和“transferFrom”函数与 msg.sender 的 ERC20 代币余额进行交互。

Hope you find this information useful:)希望您发现此信息有用:)

are you found the solution?你找到解决方案了吗? i have my own ERC20 token我有自己的 ERC20 代币

and i want to create ERC721 too so i want to used my token to mint,sell,buy on my ERC721 too.我也想创建 ERC721,所以我也想用我的代币在我的 ERC721 上铸造、销售、购买。 but i dont know how to edit the smartcontract.sol for accepted only my token not ether但我不知道如何编辑 smartcontract.sol 只接受我的令牌而不是以太

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

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