OpenZeppelin Error – Type address payable Not Implicitly Convertible to Contract “IERC20”

crowdsaleerroropenzeppelinopenzeppelin-contracts

So I'm testing out deploying a crowdsale contract (using remix).

First I deployed the token contract (I tried multiple versions, but here's one contract example taken from the openzeppelin forums):

// contracts/SimpleToken.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.5.5;

import "@openzeppelin/[email protected]/token/ERC20/ERC20.sol";
import "@openzeppelin/[email protected]/token/ERC20/ERC20Detailed.sol";

/**
 * @title SimpleToken
 * @dev Very simple ERC20 Token example, where all tokens are pre-assigned to the creator.
 * Note they can later distribute these tokens as they wish using `transfer` and other
 * `ERC20` functions.
 */
contract TestCoinForCrowdsale is Context, ERC20, ERC20Detailed {
    /**
     * @dev Constructor that gives _msgSender() all of existing tokens.
     */
    constructor() public ERC20Detailed("CoolToken", "CLTK", 18) {
        _mint(_msgSender(), 110000000000000000000);
    }
}

Then I wanted to deploy a very simple crowdsale contract:

pragma solidity ^0.5.17;

// import "@openzeppelin/[email protected]/crowdsale/crowdsale.sol";
import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/v2.5.0/contracts/crowdsale/Crowdsale.sol";

contract HGTokenCrowdsale is Crowdsale {
    constructor (
    uint256 rate,
    address payable wallet,
    IERC20 token
    
        /**
         * @dev The rate is the conversion between wei and the smallest and indivisible
     * token unit. So, if you are using a rate of 1 with a ERC20Detailed token
     * with 3 decimals called TOK, 1 wei will give you 1 unit, or 0.001 TOK.
     */
    ) public Crowdsale(rate=100, wallet=0x6b0962bc4dFf11B6f96934d777EA4b2088dDD33c, token=0x7e77c3277239F7D1d557cA98C295bDb63cC26ee8) {}
}

But when I want to compile the code for the second contract, I get this error:

contracts/GratitudeCoinTCrowdsale.sol:17:91: TypeError: Type address payable is not implicitly convertible to expected type contract IERC20. ) public Crowdsale(rate=100, wallet=0x6b0962bc4dFf11B6f96934d777EA4b2088dDD33c, token=0x7e77c3277239F7D1d557cA98C295bDb63cC26ee8) {}

^----------------------------------------^

This error comes up when trying to compile when using the VM as well as on the Rinkeby Test Network
The contract address that I specified for the token variable is a working address on the Rinkeby network. Can anyone help with figuring out the solution to this error?

Thank you!

Best Answer

You have this error because you are trying to assign a payable address to a IERC20 parameter. Such an implicit conversion will not be done by solidity itself, you must do it explicitly. This has nothing to do with the network you are working on.

This is the issue :

Crowdsale(rate=100, wallet=0x6b0962bc4dFf11B6f96934d777EA4b2088dDD33c, token=0x7e77c3277239F7D1d557cA98C295bDb63cC26ee8)

As CrowdSale expect the token parameter to be of type IERC20.

Try with explicit type conversion :

// SPDX-License-Identifier: MIT
pragma solidity ^0.5.5;

import "@openzeppelin/[email protected]/token/ERC20/ERC20.sol";
import "@openzeppelin/[email protected]/token/ERC20/ERC20Detailed.sol";
import "@openzeppelin/[email protected]/crowdsale/Crowdsale.sol";

contract HGTokenCrowdsale is Crowdsale {
    constructor (
    uint256 rate,
    address payable wallet,
    IERC20 token
    
        /**
         * @dev The rate is the conversion between wei and the smallest and indivisible
     * token unit. So, if you are using a rate of 1 with a ERC20Detailed token
     * with 3 decimals called TOK, 1 wei will give you 1 unit, or 0.001 TOK.
     */
    ) public Crowdsale(rate=100, wallet=0x6b0962bc4dFf11B6f96934d777EA4b2088dDD33c, token=IERC20(0x7e77c3277239F7D1d557cA98C295bDb63cC26ee8)) {}
}

/**
 * @title SimpleToken
 * @dev Very simple ERC20 Token example, where all tokens are pre-assigned to the creator.
 * Note they can later distribute these tokens as they wish using `transfer` and other
 * `ERC20` functions.
 */
contract TestCoinForCrowdsale is Context, ERC20, ERC20Detailed {
    /**
     * @dev Constructor that gives _msgSender() all of existing tokens.
     */
    constructor() public ERC20Detailed("CoolToken", "CLTK", 18) {
        _mint(_msgSender(), 110000000000000000000);
    }
}
Related Topic