How to set constructor parameter using OpenZeppelin CLI

I have written a simple Token contract and when I deploy it in Remix I get the option to set a constructor parameter to set the Token cap:

Screenshot 2020-03-23 at 14.56.33

When I try to compile and create this token in OpenZeppelin CLI using npx oz create I don’t see an option to insert this constructor parameter, and so it throws:

GGCoin deployment failed with error: Invalid number of parameters for "undefined". Got 0 expected 1!

How do I set this constructor parameter using OpenZeppelin CLI?

:computer: Environment

Remix
OpenZeppelin SDK 2.7.2
Solidity 0.5.0

:1234: Code to reproduce

pragma solidity ^0.5.0;

import "/Users/lennard/Desktop/GGToken/node_modules/@openzeppelin/contracts/token/ERC20/ERC20Detailed.sol";
import "/Users/lennard/Desktop/GGToken/node_modules/@openzeppelin/contracts/token/ERC20/ERC20Capped.sol";
import "/Users/lennard/Desktop/GGToken/node_modules/@openzeppelin/contracts/token/ERC20/ERC20Burnable.sol";

contract GGToken is ERC20Capped, ERC20Detailed, ERC20Burnable {

    constructor (uint256 cap)
        ERC20Detailed("GGToken", "GGT", 18)
        ERC20Capped(cap)
        public {
            _mint(msg.sender, 10000);
    }
}
1 Like

Hi @Lennard_Mulder,

Given that your contract has a constructor (regular contracts) rather than an initializer (upgradeable contracts) I assume you are deploying a regular contract.

OpenZeppelin CLI supports deploying regular (non-upgradeable) contracts from 2.8.

OpenZeppelin CLI 2.8 is currently at release candidate.
To install run npm i @openzeppelin/cli@rc

We can then deploy a regular contract using the OpenZeppelin CLI and the interactive commands will ask for the constructor parameters:

$ 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 Token
? cap: uint256: 1000000000000
✓ Deployed instance of Token
0xe78A0F7E598Cc8b0Bb87894B0F60dD2a88d6a8Ab

As an aside, we don’t need to specify the full path for imports and can start at @openzeppelin.

pragma solidity ^0.5.0;

import "@openzeppelin/contracts/token/ERC20/ERC20Detailed.sol";
import "@openzeppelin/contracts/token/ERC20/ERC20Capped.sol";
import "@openzeppelin/contracts/token/ERC20/ERC20Burnable.sol";

contract Token is ERC20Capped, ERC20Detailed, ERC20Burnable {

    constructor (uint256 cap)
        ERC20Detailed("Token", "TKN", 18)
        ERC20Capped(cap)
        public {
            _mint(msg.sender, 10000);
    }
}

Hi @Lennard_Mulder,

Checking how you got on with this?