I'm looking over the Bancor Smart Token code and noticed that when the SmartToken constructor is called in place of where modifiers usually go there is a declaration of the ERC20Token constructor function ERC20Token(_name, _symbol, _decimals)

I can't seem to find any documentation or posts about this, however I'm guessing this is how you would specify which constructors should be called from parent contracts that a child might inherit?

I was able to get the same effects by changing the smart token contract declaration from contract SmartToken is ISmartToken, Owned, ERC20Token, TokenHolder to contract SmartToken is ISmartToken, Owned, ERC20Token("some name", "some symbol", 18), TokenHolder

Smart Token Constructor Function:

function SmartToken(string _name, string _symbol, uint8 _decimals)
    ERC20Token(_name, _symbol, _decimals)

ERC20 Token Constructor Function:

function ERC20Token(string _name, string _symbol, uint8 _decimals) {
    require(bytes(_name).length > 0 && bytes(_symbol).length > 0); // validate input

    name = _name;
    symbol = _symbol;
    decimals = _decimals;

1 Answer 1


It is very well explained in the solidity documentation Arguments for Base Constructors

Derived contracts need to provide all arguments needed for the base constructors. This can be done in two ways:

pragma solidity ^0.4.0;

contract Base {
    uint x;
    function Base(uint _x) public { x = _x; }

contract Derived is Base(7) {
    function Derived(uint _y) Base(_y * _y) public {

One way is directly in the inheritance list (is Base(7)). The other is in the way a modifier would be invoked as part of the header of the derived constructor (Base(_y * _y)).

The first way to do it is more convenient if the constructor argument is a constant and defines the behaviour of the contract or describes it.

The second way has to be used if the constructor arguments of the base depend on those of the derived contract. If, as in this silly example, both places are used, the modifier-style argument takes precedence.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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