0

Trying to deal with Ethereum contracts using OpenZeppelin examples and Remix. There is a token contract deployed in the test network:

pragma solidity ^0.5.0;

import "./ERC20.sol";
import "./ERC20Detailed.sol";
import "./Ownable.sol";

contract TestToken is Ownable, ERC20, ERC20Detailed {
  /**
   * @dev Constructor that gives _msgSender() all of existing tokens.
   */
  constructor () public ERC20Detailed("TestToken", "TST", 18) {
    _mint(_msgSender(), 100000 * (10 ** uint256(decimals())));
  }
}

I don’t understand how to make crowdsale contract take TestToken tokens:

pragma solidity ^0.5.0;

import "./Crowdsale.sol";

contract MyCrowdsale is Crowdsale {
  constructor (
    uint256 rate,
    address payable wallet,
    IERC20 token
  ) 
  public
  Crowdsale(1000000000, wallet, token)
  {
  }
}

if I substitute the address of the contract instead of token, for example Crowdsale (1000000000, wallet, 0x7D01c89107B0d682D06cbC635C320EE531146E6A), I get an error.

I will be grateful for an example.

  • What error are you getting? – goodvibration Nov 2 at 16:58
  • browser/MyCrowdsale.sol:16:39: TypeError: Invalid type for argument in modifier invocation. Invalid implicit conversion from address payable to contract IERC20 requested. Crowdsale(1000000000, wallet, 0x7D01c89107B0d682D06cbC635C320EE531146E6A) ^----------------------------------------^ – Dmitry Nov 2 at 17:09
0
constructor (
        uint256 rate,
        address payable wallet,
        address tokenContractAddress
        ) 
        public
        Crowdsale(1000000000, wallet, IERC20(tokenContractAddress))
        {}

The type IERC20 cannot be created externally, and only basic types can be used if you invoke the constructor. So instead you have to pass the address of the contract and tell solidity that in such address there is a contract that "speaks" the ERC20 interface.

Note that you are not creating a new contract, since the keyword "new" is not present. Instead you are just declaring the interface of a contract at a given address. And in case you are curious: no checks are performed at all to make sure that address actually respects such interface.

  • thanks, all worked well – Dmitry Nov 3 at 0:20
  • I'm glad to know! :-) – Molina Nov 3 at 8:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.