I have a function which dynamically creates an ERC20 contract on calling a function in another contract as follows:

function createDao(string _tokenName) public payable {

  tokenNumberIndex = safeAdd(tokenNumberIndex, 1);

  string memory _tokenSymbol = 

  address _tokenAddress = 
       (new REP).value(msg.value)(_tokenSymbol, _tokenName);

  erc20SymbolAddresses[_tokenSymbol] = _tokenAddress;

  proposalIndex = safeAdd(proposalIndex, 1);

  emit NewProposalCreated(proposalIndex);


I am confident that the following code is executing correctly:

address _tokenAddress = 
   (new REP).value(msg.value)(_tokenSymbol, _tokenName);
erc20SymbolAddresses[_tokenSymbol] = _tokenAddress;

However, erc20SymbolAddresses gives 0 address for all possible token symbols. How long does creation of rep take? How would I know if the creation fails?

REP Contract code is as follwing:

contract REP is ERC20Interface, SafeMath {
string public symbol;
string public  name;
uint8 public decimals;
uint public _totalSupply;

mapping(address => uint) balances;
mapping(address => mapping(address => uint)) allowed;

constructor(string _tokenSymbol, string _name) public payable{
    symbol = _tokenSymbol;
    name = _name;
    decimals = 18;
    _totalSupply = msg.value;
    balances[msg.sender] = _totalSupply;
    emit Transfer(address(0), msg.sender, _totalSupply);

What am I missing here?

1 Answer 1


I suspect you are calling the parameters wrong try using and not include the msg.value property, I don't see the benefit of including it in your particular contract.

address _tokenAddress = (new REP(_tokenSymbol, _tokenName);

There are a number of reference truffle boxes you can examine as well that have erc20 factories such as EIP20Factory

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.