0

first of all really nice to find this forum, I'm starting coding Solidity.

Here the problem I get compiling a template of crowdsale smart contract ExampleTokenCrowdsale.sol, from this tutorial.

The screenshots:

enter image description here

TypeError: Invalid type for argument in modifier invocation. Invalid implicit conversion from address to address payable requested.
    Crowdsale(_rate, _wallet, _token)

code:

    pragma solidity ^0.5.0;


    import "openzeppelin-solidity/contracts/crowdsale/Crowdsale.sol";
    import "openzeppelin-solidity/contracts/crowdsale/emission/MintedCrowdsale.sol";
    import "openzeppelin-solidity/contracts/crowdsale/validation/CappedCrowdsale.sol";


    contract ExampleTokenCrowdsale is Crowdsale, MintedCrowdsale, CappedCrowdsale{

    //minimum investor Contribution - 20000000000000000000
    //minimum investor Contribution - 50000000000000000000
    uint256 public investorMinCap = 20000000000000000000;
    uint256 public investorHardCap = 50000000000000000000;

    mapping(address => uint256) public contributions;

    constructor(uint256 _rate,
      address _wallet,
      ERC20 _token,
      uint256 _cap)
    Crowdsale(_rate, _wallet, _token)
    CappedCrowdsale(_cap)
    public{
    }


    function _preValidatePurchase(
    address _beneficiary,
    uint256 _weiAmount
     )
    internal view
    {
    super._preValidatePurchase(_beneficiary, _weiAmount);
    uint256 _existingContribution = contributions[_beneficiary];
    uint256 _newContribution = _existingContribution.add(_weiAmount);
    require(_newContribution >= investorMinCap && _newContribution <= investorHardCap);
    contributions[_beneficiary] = _newContribution;
   }

   }

thanks!

[edited]:

  • 1
    Please share actual code, not images. Code in images isn't searchable and is inaccessible to readers who are visually impaired. – user19510 Mar 7 at 23:33
  • Your constructor syntax is totally wrong. – Mahesh Rajput Mar 8 at 5:22
  • I assume you're using old OpenZeppelin versions with new compiler, or something similar. Check for example ethereum.stackexchange.com/a/63080/31933 and its comments. – Lauri Peltonen Mar 8 at 13:43
2

Okay i understand know the reason why the tutorial code work and your code doesn't work is because of this is because in new solidity the CrowdSale is actually:

constructor (uint256 rate, address payable wallet, IERC20 token) public {
    require(rate > 0);
    require(wallet != address(0));
    require(address(token) != address(0));

    _rate = rate;
    _wallet = wallet;
    _token = token;
}

But the old open zeppellin that was used for tutorial is:

constructor (uint256 rate, address wallet, IERC20 token) public {
    require(rate > 0);
    require(wallet != address(0));
    require(address(token) != address(0));

    _rate = rate;
    _wallet = wallet;
    _token = token;
}

As you can see the _wallet type of variable from the old one is address but the new one from solidity 0.5.0 address got split into address and address payable so if the old example contract is out of date.

the main reason why your code break is because in solidity 0.5.0 you can't convert address to address payable like solidity 0.4.24. More information can be found in here: https://solidity.readthedocs.io/en/v0.5.0/050-breaking-changes.html#explicitness-requirements

An address payable can be directly converted to an address, but the other way around is not allowed.

So to fix this problem simple turn address _wallet into address payable _wallet

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.