Deploying token contract with user defined parameters

Hello. I am trying to create a UI so users can create a token and define the name, symbol and supply. Everything works in remix but when I try to deploy using oz create I get this:

    ✓ Compiled contracts with solc 0.5.17 (commit.d19bba13)
    ? Pick a contract to instantiate TokenFactory
    ? Pick a network rinkeby
    ✓ Added contract TokenFactory
    - Contract Token or an ancestor has a constructor. Change it to an initializer function. See https://docs.openzeppelin.com/upgrades/2.6//writing-upgradeable#initializers.
    ✖ Validating and deploying contract Token
    ✓ Contract TokenFactory deployed
    Token deployment failed with error: Invalid number of parameters for "undefined". Got 0 expected 4!

I am using openzeppelin 2.5. This is my code:

    pragma solidity ^0.5.0;

    import "node_modules/@openzeppelin/contracts/token/ERC20/ERC20.sol";
    import "node_modules/@openzeppelin/contracts/token/ERC20/ERC20Detailed.sol";
    import "node_modules/@openzeppelin/contracts/ownership/Ownable.sol";

    contract TokenFactory  {

        address[] public deployedTokens;

        function createToken(uint256 initialSupply, string memory name, string memory symbol) public {

            address newToken = address(new Token(initialSupply, name, symbol, msg.sender));

            deployedTokens.push(address(newToken));
      
        }

        function getDeployedTokens() public view returns(address[] memory) {
            return deployedTokens;
        }
    }

    contract Token is ERC20, ERC20Detailed, Ownable {

         address public manager;

        constructor(uint256 initialSupply, string memory name, string memory symbol, address creator ) ERC20Detailed(name, symbol, 18) public {
           manager = creator;
            _mint(manager, initialSupply);
             transferOwnership(manager);
        }
    }
1 Like

Hi @Cristian_Perez_Ramir,

I recommend using OpenZeppelin CLI 2.8 to deploy your contract, as it supports upgradeable and non-upgradeable (regular) contracts.

Deploy upgradeable

$ npx oz deploy
✓ Compiled contracts with solc 0.5.17 (commit.d19bba13)
? Choose the kind of deployment upgradeable
? Pick a network development
? Pick a contract to deploy TokenFactory
✓ Added contract TokenFactory
✓ Contract TokenFactory deployed
All implementations have been deployed
? Call a function to initialize the instance after creating it? No
✓ Setting everything up to create contract instances
✓ Instance created at 0xCfEB869F69431e42cdB54A4F4f105C19C080A601
To upgrade this instance run 'oz upgrade'
0xCfEB869F69431e42cdB54A4F4f105C19C080A601

Deploy regular

$ npx oz deploy
✓ Compiled contracts with solc 0.5.17 (commit.d19bba13)
? Choose the kind of deployment regular
? Pick a network development
? Pick a contract to deploy TokenFactory
✓ Deployed instance of TokenFactory
0x254dffcd3277C0b1660F6d42EFbB754edaBAbC2B