我如何接受ERC20代币进行NFT薄荷付款而不是ETH

发布于 2025-02-05 05:52:09 字数 67 浏览 2 评论 0原文

我如何接受ERC 20代币,以根据我的智能合约铸造NFT。我目前正在使用ETH支付铸造,我想接受另一个ERC 20代币。

How do I accept an ERC 20 token for minting NFTS on my smart contract. I’m currently paying for the minting using ETH, and I will like to accept another ERC 20 token.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

烟柳画桥 2025-02-12 05:52:09

您可以更改薄荷功能,以接受首选的令牌类型作为付款。为了防止在ETH中支付天然气,您可以使用双科性前进。检查他们的文档。
https://docs.biconomy.io.io/products/enable-products/enable-pareing-product-product-product--product--enable-poaying--煤气中心20

You can change your mint function in order to accept the preferred token type as payment. And in order to prevent paying gas in eth, you can use biconomy forward.Check out their docs.
https://docs.biconomy.io/products/enable-paying-gas-in-erc20

蒗幽 2025-02-12 05:52:09

您需要从NFT合同到令牌合同的参考。
假设我们有这两个合同:NFTContract,Tokencontract。

 contract NFTContract {
  TokenContract tokenContract;
  ...
   mint() {
   tokensContract.transfer(msg.sender(), addressReceiver, tokensToSend);
   ...
  }
 }

 contract TokenContract {
  transfer(sender, receiver, balance) {}
 }

您可以检查一个示例,说明我是在为论文开发的回购中如何做到这一点的。
https://github.com/nickvanzo/nickvanzo/contracts_for_thesis

You need a reference from the NFT contract to your token contract.
Let's say we have these two contracts: NFTContract, TokenContract.

 contract NFTContract {
  TokenContract tokenContract;
  ...
   mint() {
   tokensContract.transfer(msg.sender(), addressReceiver, tokensToSend);
   ...
  }
 }

 contract TokenContract {
  transfer(sender, receiver, balance) {}
 }

You can check an example of how I did this in my repo I'm developing for my thesis.
https://github.com/NickVanzo/Contracts_For_Thesis

你是暖光i 2025-02-12 05:52:09

也许它对您有用,但要小心您可能会因坚固版本而犯错误。

pragma solidity ^0.8.9;

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

contract LSTNFT is ERC721, ERC721Burnable, Ownable {

    uint256 public cost;
    uint256  maxSupply = 20;
    uint256  maxMintAmountPerTx = 2;

    // address of the ERC-20 contract
    address public erc20Contract = "ERC-20 address is here";
    // instance of the ERC-20 contract
    ERC20 public erc20;

    constructor() ERC721("Lestonz NFT", "LSTN") {
        erc20 = ERC20(erc20Contract);
    }
    
    function _baseURI() internal pure override returns (string memory) {
        return "ipfs://your ipfs url";
    }
    modifier mintPriceCompliance(uint256 _mintAmount) {
        if (msg.sender != owner()) {
            require(msg.value >= cost * _mintAmount, 'Insufficient funds!');
        }
        _;
    }
    function mint(uint256 _mintAmount) public payable  mintPriceCompliance(_mintAmount) {
    require(erc20.balanceOf(msg.sender) >= msg.value, "Not enough ERC-20 tokens");
    _safeMint(_msgSender(), _mintAmount);
    }

      function setCost(uint256 _cost) public onlyOwner {
        cost = _cost;
        }
}

Maybe it will work for you but be careful you can take errors for solidity versions.

pragma solidity ^0.8.9;

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

contract LSTNFT is ERC721, ERC721Burnable, Ownable {

    uint256 public cost;
    uint256  maxSupply = 20;
    uint256  maxMintAmountPerTx = 2;

    // address of the ERC-20 contract
    address public erc20Contract = "ERC-20 address is here";
    // instance of the ERC-20 contract
    ERC20 public erc20;

    constructor() ERC721("Lestonz NFT", "LSTN") {
        erc20 = ERC20(erc20Contract);
    }
    
    function _baseURI() internal pure override returns (string memory) {
        return "ipfs://your ipfs url";
    }
    modifier mintPriceCompliance(uint256 _mintAmount) {
        if (msg.sender != owner()) {
            require(msg.value >= cost * _mintAmount, 'Insufficient funds!');
        }
        _;
    }
    function mint(uint256 _mintAmount) public payable  mintPriceCompliance(_mintAmount) {
    require(erc20.balanceOf(msg.sender) >= msg.value, "Not enough ERC-20 tokens");
    _safeMint(_msgSender(), _mintAmount);
    }

      function setCost(uint256 _cost) public onlyOwner {
        cost = _cost;
        }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文