2

My Token contract compiles fine using 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);
    }
}

When I deploy this contract in Remix I get the option to set a constructor argument:

enter image description here

When I try to deploy the same contract using OpenZeppelin CLI's npx oz create I don't see this option, and it throws error: Invalid number of parameters for "undefined". Got 0 expected 1!

How do I set this constructor argument using OpenZeppelin CLI?

3

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. https://forum.openzeppelin.com/t/openzeppelin-cli-2-8-release-candidate/2297

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);
    }
}
| improve this answer | |

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.