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 =
bytes32ToString(uintToBytes(tokenNumberIndex));
address _tokenAddress =
(new REP).value(msg.value)(_tokenSymbol, _tokenName);
erc20SymbolAddresses[_tokenSymbol] = _tokenAddress;
proposalIndex = safeAdd(proposalIndex, 1);
emit NewProposalCreated(proposalIndex);
newProposalInternal(
proposalIndex,
_tokenSymbol,
_tokenName,
_tokenName,
msg.sender,
msg.value);
}
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?