[Ethereum] How to use 2 different constructors with open-zeppelin

erc-20openzeppelin-contractsremixsolidity

I don't understand well how to implement an smart contract to create a capped Token.

If I want to follow the example of a simple token is easy:
https://github.com/OpenZeppelin/openzeppelin-solidity/blob/master/contracts/examples/SimpleToken.sol

It's use ERC20Detailed, which inhertis from IERC20 (as you see in the docs):
https://docs.openzeppelin.org/docs/token_erc20_erc20detailed

So, you only use the constructor for ERC20Detailed.

pragma solidity ^0.5.2;

import "../token/ERC20/ERC20.sol";
import "../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 SimpleToken is ERC20, ERC20Detailed {
    uint8 public constant DECIMALS = 18;
    uint256 public constant INITIAL_SUPPLY = 10000 * (10 ** uint256(DECIMALS));

    /**
     * @dev Constructor that gives msg.sender all of existing tokens.
     */
    constructor () public ERC20Detailed("SimpleToken", "SIM", DECIMALS) {
        _mint(msg.sender, INITIAL_SUPPLY);
    }
}

Ok, but what if I also want to implement ERC20Capped? I see that inherits from ERC20Mintable, which inherits from ERC20. But the constructor method of ERC20Capped doesn't include neither token name, nor symbol nor supply.

I have been also checking the source code of these smart contracts, but don't see very clear.

https://github.com/OpenZeppelin/openzeppelin-solidity/blob/v2.1.2/contracts/token/ERC20/ERC20Detailed.sol

https://github.com/OpenZeppelin/openzeppelin-solidity/blob/v2.1.2/contracts/token/ERC20/ERC20Capped.sol

Thanks

Best Answer

ERC20Capped inherits from ERC20Mintable, which inherits from ERC20.

So if you inherit from ERC20Capped, then you don't need to inherit from ERC20.

Therefore (though without verifying it via compilation), I'm pretty sure that you can do:

contract SimpleToken is ERC20Detailed, ERC20Capped {
    uint8 public constant DECIMALS = 18;

    constructor (uint256 cap)
        ERC20Detailed("SimpleToken", "SIM", DECIMALS)
        ERC20Capped(cap)
        public {
           ...
    }
}
Related Topic