简体   繁体   English

从其他智能合约铸造新的 ERC20 代币

[英]Mint new ERC20 token from other smart contract

Recently I am facing an issue while working on a smart contract that has staking functionality.最近我在处理具有质押功能的智能合约时遇到了一个问题。 Through the IERC20 interface, I manage to interact with Erc20 token from another contract but there is still one confusion left.通过 IERC20 接口,我设法与来自另一个合约的 Erc20 令牌进行交互,但仍然存在一个困惑。 I am working on a smart contract in which users can stake my token(token is already deployed in.network) in smart contract and when the staking duration ends stakeholder can get their staking amount along with the rewarded token.我正在开发一个智能合约,用户可以在智能合约中抵押我的代币(代币已经部署在网络中),当抵押期限结束时,利益相关者可以获得他们的抵押金额以及奖励代币。 For rewarded tokens I want to mint new tokens to give rewards to the stakeholder in my smart contract.对于奖励代币,我想铸造新代币以奖励我智能合约中的利益相关者。 How can I use the mint function in another smart contract?我如何在另一个智能合约中使用 mint function? I want to use the Erc20 mint function in my staking smart contract.我想在我的抵押智能合约中使用 Erc20 mint function。 Waiting for your positive response.等待您的积极回应。

IERC20 private _token;
constructor(IERC20 token) {
    _mytoken = token;

  }

transfer and approve is working perfectly but there is no option of mint in IERC20传输和批准工作正常,但 IERC20 中没有薄荷选项

 _mytoken.approve(address(this),quantity);
 _mytoken.safeTransferFrom(msg.sender,address(this),quantity);

IERC20 does not contain _mint but ERC20 does so you inherit from ERC20 IERC20 不包含_mint但 ERC20 包含所以你继承自 ERC20

contract RewardToken is ERC20 {
    constructor() public ERC20("Reward Token","RWD"){
        // give initial supply 1million + 18 zeros
        _mint(msg.sender,1000000000000000000000000);
    }

Your RewardToken has _mint functionality and it can still inherit from IERC20.您的 RewardToken 具有 _mint 功能,它仍然可以继承自 IERC20。 But you have an initialization mistake in your constructor:但是你的构造函数中有一个初始化错误:

constructor(IERC20 token) {
    // you have to initialize with IERC20
    _mytoken = IERC20(token);
  }

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

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