0

I would like to write a smart contract that can issue an erc20 token when asked (with some required parameter, as name, symbol, decimals, and owner address).

From what I understood I have to deploy a new smart contract every time I want to issue a new ERC-20 token. Can I do this inside a smart contract?

I also saw that there is this new erc1155 standard, but from what I understand is mostly for issuing erc721 tokens.

0

Sure it is, for example:

contract ERC20Token {
    string  public name;
    string  public symbol;
    uint8   public decimals;
    uint256 public totalSupply;

    event Transfer(address indexed _from, address indexed _to, uint256 _value);
    event Approval(address indexed _owner, address indexed _spender, uint256 _value);

    constructor(string _name, string _symbol, uint8 _decimals, uint256 _totalSupply) public {
        ...
    }

    function transfer(address _to, uint256 _value public returns (bool) {
        ...
    }

    function transferFrom(address _from, address _to, uint256 _value (bool) {
        ...
    }

    function approve(address _spender, uint256 _value) (bool) {
        ...
    }
}

contract ERC20TokenFactory {
    function createToken(string _name, string _symbol, uint8 _decimals, uint256 _totalSupply) public returns (ERC20Token) {
        return new ERC20Token(_name, _symbol, _decimals, _totalSupply);
    }
}
2
  • Thanks for the answer. Do I need to extend the ERC20 interface or some openzeppelin library? – Agilulfo Apr 23 '20 at 19:36
  • @Agilulfo: You're welcome. You can do whatever you like, as long as it conforms to the ERC20 standard. OpenZeppelin has it all implemented, including the IERC20 interface (which can be useful elsewhere in your code), Safe-Math handling and so forth. So yes, you may as well use it. I did not specify this in my answer, because it was not in the context of your question. – goodvibration Apr 23 '20 at 19:52

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.