Usama Hassan
Usama Hassan

Reputation: 23

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. 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? I want to use the Erc20 mint function in my staking smart contract. 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

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

Upvotes: 2

Views: 1458

Answers (1)

Yilmaz
Yilmaz

Reputation: 49671

IERC20 does not contain _mint but ERC20 does so you inherit from 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. But you have an initialization mistake in your constructor:

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

Upvotes: 1

Related Questions