Error: StandaloneERC20 Factory

Has anyone tried creating a StandaloneERC20 Factory

I have tried two options and both of them are returning errors:

Option 1

Smart Contact
address newStandaloneERC20 = new StandaloneERC20();

openzeppelin check
TypeError: Type contract StandaloneERC20 is not implicitly convertible to expected type address.


Option 2

Smart Contact
address newStandaloneERC20 = new StandaloneERC20.initialize(_name, _ticker, decimals, initialSupply, _owner, _owner, _owner);

openzeppelin check
DeclarationError: Identifier not found or not unique.

1 Like

The errror here is in the assignment, you need to cast the type explicitly to store it as an address:

address newStandaloneERC20 = address(new StandaloneERC20();)

1 Like

Thank you @nventuro I made the edits as suggested.

The previous error is fixed, and I am getting a new error:

Smart Contract

address newStandaloneERC20 = address(new StandaloneERC20());
newStandaloneERC20.initialize(_name, _ticker, decimals, initialSupply, _owner, _owner, _owner);
return newStandaloneERC20;

openzeppelin check
Member “initialize” not found or not visible after argument-dependent lookup in address.

1 Like

Hi @abcoathup @nventuro do you have any clues on why this is failing?

Smart Contract

pragma solidity >=0.5.0 <0.7.0;

/// dependencies
import "@openzeppelin/upgrades/contracts/Initializable.sol";
import "@openzeppelin/contracts-ethereum-package/contracts/math/SafeMath.sol";
import "@openzeppelin/contracts-ethereum-package/contracts/ownership/Ownable.sol";
import "@openzeppelin/contracts-ethereum-package/contracts/lifecycle/Pausable.sol";
import "@openzeppelin/contracts-ethereum-package/contracts/token/ERC20/StandaloneERC20.sol";

contract STFactory is Initializable, Ownable, Pausable, StandaloneERC20 {
    using SafeMath for uint256;
    /// states
    address stFactoryOwner = address(0);
    uint8 public constant DECIMALS = 18;
    uint256 public constant INITIALSUPPLY = 1 * (10 ** uint256(DECIMALS));

    /// functions
    /// initialize function
    function initialize() public initializer {
        stFactoryOwner = owner();
        Pausable.initialize(stFactoryOwner);
    }
    /// deployToken function
    function deployToken(
        string calldata _ticker,
        string calldata _name,
        address _owner
    )
        external
        returns(address)
    {
        address tokenAddress = _deployToken(
            _ticker,
            _name,
            _owner
        );
        return tokenAddress;
    }
    /// _deployToken internal function
    function _deployToken(
        string memory _ticker,
        string memory _name,
        address _owner
    )
        internal
        returns(address)
    {
        /// intantiate ERC20
        address newStandaloneERC20 = address(new StandaloneERC20());
        // address newStandaloneERC20 = address(new StandaloneERC20(_name, _ticker, decimals, initialSupply, _owner, _owner, _owner));
        newStandaloneERC20.initialize(_name, _ticker, DECIMALS, INITIALSUPPLY, _owner, _owner, _owner);
        return newStandaloneERC20;
    }
}

openzeppelin check error
TypeError: Member “initialize” not found or not visible after argument-dependent lookup in address.
newStandaloneERC20.initialize(_name, _ticker, DECIMALS, INITIALSUPPLY, _owner, _owner, _owner);

1 Like

Hi @pkr,

As an aside, you could create StandaloneERC20 using OpenZeppelin CLI rather than an onchain factory.

To resolve I modified STFactorys.sol:

pragma solidity >=0.5.0 <0.7.0;

/// dependencies
import "@openzeppelin/upgrades/contracts/Initializable.sol";
import "@openzeppelin/contracts-ethereum-package/contracts/math/SafeMath.sol";
import "@openzeppelin/contracts-ethereum-package/contracts/ownership/Ownable.sol";
import "@openzeppelin/contracts-ethereum-package/contracts/lifecycle/Pausable.sol";
import "@openzeppelin/contracts-ethereum-package/contracts/token/ERC20/StandaloneERC20.sol";

contract STFactory is Initializable, Ownable, Pausable {
    using SafeMath for uint256;
    /// states
    address stFactoryOwner;
    uint8 public constant DECIMALS = 18;
    uint256 public constant INITIALSUPPLY = 1 * (10 ** uint256(DECIMALS));

    /// functions
    /// initialize function
    function initialize(address owner) public initializer {
        stFactoryOwner = owner;
        Pausable.initialize(stFactoryOwner);
    }
    /// deployToken function
    function deployToken(
        string calldata _ticker,
        string calldata _name,
        address _owner
    )
        external
        returns(address)
    {
        address tokenAddress = _deployToken(
            _ticker,
            _name,
            _owner
        );
        return tokenAddress;
    }
    /// _deployToken internal function
    function _deployToken(
        string memory _ticker,
        string memory _name,
        address _owner
    )
        internal
        returns(address)
    {
        /// intantiate ERC20
        StandaloneERC20 newStandaloneERC20 = new StandaloneERC20();
        newStandaloneERC20.initialize(_name, _ticker, DECIMALS, INITIALSUPPLY, _owner, new address[](0), new address[](0));

        return address(newStandaloneERC20);
    }
}

Create Factory

$ oz create
✓ Compiled contracts with solc 0.5.11 (commit.c082d0b4)
? Pick a contract to instantiate STFactory
? Pick a network development
- Variable _pausers (PauserRole) contains a struct or enum. These are not automatically checked for storage compatibility in the current version. See https://docs.openzeppelin.com/sdk/2.5/writing_contracts.html#modifying-your-contracts for more info.
✓ Contract STFactory deployed
All contracts have been deployed
? Do you want to call a function on the instance after creating it? Yes
? Select which function * initialize(owner: address)
? owner (address): 0x13ebd3443fa5575F0Eb173e323D8419F7452CfB1
✓ Setting everything up to create contract instances
✓ Instance created at 0x630589690929E9cdEFDeF0734717a9eF3Ec7Fcfe
0x630589690929E9cdEFDeF0734717a9eF3Ec7Fcfe

Deploy Token

$ oz send-tx
? Pick a network development
? Pick an instance STFactory at 0x630589690929E9cdEFDeF0734717a9eF3Ec7Fcfe
? Select which function deployToken(_ticker: string, _name: string, _owner: address)
? _ticker (string): My Token
? _name (string): TKN
? _owner (address): 0x13ebd3443fa5575F0Eb173e323D8419F7452CfB1
✓ Transaction successful. Transaction hash: 0xb899f41b80e745cd34654883f87bb3c037a681c6cddb28c12bd7fc053cfe8167
Events emitted:
 - PauserAdded(0x61d47DA73822B4a77c4a9Bae56Ba25729669b9F1)
 - PauserRemoved(0x61d47DA73822B4a77c4a9Bae56Ba25729669b9F1)

Thank you heaps @abcoathup …managed to create factory and deploy token is failing now

oz send-tx
? Pick a network development
? Pick an instance STFactory at 0xE0Ba71BF785A2d67632f399D6Ea7307e1dA94B6e
? Select which function deployToken(_ticker: string, _name: string, _owner: address)
? _ticker (string): ABC
? _name (string): ABC
? _owner (address): 0xf1a6D546A5baa618ebEBBE37f10be668239bE20e
✖ Calling: 'deployToken' with:
- _ticker (string): "ABC"
- _name (string): "ABC"
- _owner (address): "0xf1a6D546A5baa618ebEBBE37f10be668239bE20e"
Error while trying to send transaction to 0xE0Ba71BF785A2d67632f399D6Ea7307e1dA94B6e. Error: Returned error: VM Exception while processing transaction: revert

And my smart contract for reference

pragma solidity >=0.5.0 <0.7.0;

/// dependencies
import "@openzeppelin/upgrades/contracts/Initializable.sol";
import "@openzeppelin/contracts-ethereum-package/contracts/math/SafeMath.sol";
import "@openzeppelin/contracts-ethereum-package/contracts/ownership/Ownable.sol";
import "@openzeppelin/contracts-ethereum-package/contracts/lifecycle/Pausable.sol";
import "@openzeppelin/contracts-ethereum-package/contracts/token/ERC20/StandaloneERC20.sol";

contract STFactory is Initializable, Ownable, Pausable {
    using SafeMath for uint256;
    /// states
    address stFactoryOwner;
    uint8 public constant DECIMALS = 18;
    uint256 public constant INITIALSUPPLY = 1 * (10 ** uint256(DECIMALS));
    /// functions
    /// initialize function
    function initialize(address _owner) public initializer {
        stFactoryOwner = _owner;
        Pausable.initialize(stFactoryOwner);
    }
    /// deployToken function
    function deployToken(
        string calldata _ticker,
        string calldata _name,
        address _owner
    )
        external
        returns(address)
    {
        address tokenAddress = _deployToken(
            _ticker,
            _name,
            _owner
        );
        return tokenAddress;
    }
    /// _deployToken internal function
    function _deployToken(
        string memory _ticker,
        string memory _name,
        address _owner
    )
        internal
        returns(address)
    {
        address[] memory minterArray;
        minterArray[0] = _owner;
        address[] memory pauserArray;
        pauserArray[0] = _owner;
        /// intantiate ERC20
        StandaloneERC20 newStandaloneERC20 = new StandaloneERC20();
        newStandaloneERC20.initialize(_name, _ticker, DECIMALS, INITIALSUPPLY, _owner, minterArray, pauserArray);
        // newStandaloneERC20.initialize(_name, _ticker, DECIMALS, INITIALSUPPLY, _owner, new address[](0), new address[](0));
        return address(newStandaloneERC20);
    }
}
1 Like

I understand we can create an instance of StandaloneERC20 using OZ CLI.

How can we create a StandaloneERC20 Factory using OZ CLI and store the contract addresses on-chain?

1 Like

The arrays need to be initialized.

        address[] memory minterArray = new address[](1);
        minterArray[0] = _owner;
        address[] memory pauserArray = new address[](1);
        pauserArray[0] = _owner;

I also added an event to log the address of the newly deployed token.

STFactory

pragma solidity >=0.5.0 <0.7.0;

/// dependencies
import "@openzeppelin/upgrades/contracts/Initializable.sol";
import "@openzeppelin/contracts-ethereum-package/contracts/math/SafeMath.sol";
import "@openzeppelin/contracts-ethereum-package/contracts/ownership/Ownable.sol";
import "@openzeppelin/contracts-ethereum-package/contracts/lifecycle/Pausable.sol";
import "@openzeppelin/contracts-ethereum-package/contracts/token/ERC20/StandaloneERC20.sol";

contract STFactory is Initializable, Ownable, Pausable {
    using SafeMath for uint256;
    /// states
    address stFactoryOwner;
    uint8 public constant DECIMALS = 18;
    uint256 public constant INITIALSUPPLY = 1 * (10 ** uint256(DECIMALS));

    event TokenDeployed(address token);

    /// functions
    /// initialize function
    function initialize(address _owner) public initializer {
        stFactoryOwner = _owner;
        Pausable.initialize(stFactoryOwner);
    }
    /// deployToken function
    function deployToken(
        string calldata _ticker,
        string calldata _name,
        address _owner
    )
        external
        returns(address)
    {
        address tokenAddress = _deployToken(
            _ticker,
            _name,
            _owner
        );
        return tokenAddress;
    }
    /// _deployToken internal function
    function _deployToken(
        string memory _ticker,
        string memory _name,
        address _owner
    )
        internal
        returns(address)
    {
        address[] memory minterArray = new address[](1);
        minterArray[0] = _owner;
        address[] memory pauserArray = new address[](1);
        pauserArray[0] = _owner;
        /// intantiate ERC20
        StandaloneERC20 newStandaloneERC20 = new StandaloneERC20();
        newStandaloneERC20.initialize(_name, _ticker, DECIMALS, INITIALSUPPLY, _owner, minterArray, pauserArray);
        // newStandaloneERC20.initialize(_name, _ticker, DECIMALS, INITIALSUPPLY, _owner, new address[](0), new address[](0));

        emit TokenDeployed(address(newStandaloneERC20));

        return address(newStandaloneERC20);
    }
}

Create

$ oz create
✓ Compiling contracts with Truffle, using settings from truffle.js file
Truffle output:

Compiling your contracts...
===========================
> Compiling ./contracts/Migrations.sol
> Compiling ./contracts/STFactory.sol
> Compiling @openzeppelin/contracts-ethereum-package/contracts/GSN/Context.sol
> Compiling @openzeppelin/contracts-ethereum-package/contracts/access/Roles.sol
> Compiling @openzeppelin/contracts-ethereum-package/contracts/access/roles/MinterRole.sol
> Compiling @openzeppelin/contracts-ethereum-package/contracts/access/roles/PauserRole.sol
> Compiling @openzeppelin/contracts-ethereum-package/contracts/lifecycle/Pausable.sol
> Compiling @openzeppelin/contracts-ethereum-package/contracts/math/SafeMath.sol
> Compiling @openzeppelin/contracts-ethereum-package/contracts/ownership/Ownable.sol
> Compiling @openzeppelin/contracts-ethereum-package/contracts/token/ERC20/ERC20.sol
> Compiling @openzeppelin/contracts-ethereum-package/contracts/token/ERC20/ERC20Detailed.sol
> Compiling @openzeppelin/contracts-ethereum-package/contracts/token/ERC20/ERC20Mintable.sol
> Compiling @openzeppelin/contracts-ethereum-package/contracts/token/ERC20/ERC20Pausable.sol
> Compiling @openzeppelin/contracts-ethereum-package/contracts/token/ERC20/IERC20.sol
> Compiling @openzeppelin/contracts-ethereum-package/contracts/token/ERC20/StandaloneERC20.sol
> Compiling @openzeppelin/upgrades/contracts/Initializable.sol
> Artifacts written to /mnt/c/Users/andre/Documents/projects/forum/tokenfactory/build/contracts
> Compiled successfully using:
   - solc: 0.5.8+commit.23d335f2.Emscripten.clang


? Pick a contract to instantiate STFactory
? Pick a network development
✓ Deploying @openzeppelin/contracts-ethereum-package dependency to network dev-1568857681604
✓ Contract STFactory deployed
All contracts have been deployed
? Do you want to call a function on the instance after creating it? Yes
? Select which function * initialize(_owner: address)
? _owner (address): 0x13ebd3443fa5575F0Eb173e323D8419F7452CfB1
✓ Setting everything up to create contract instances
✓ Instance created at 0x8914a9E5C5E234fDC3Ce9dc155ec19F43947ab59
0x8914a9E5C5E234fDC3Ce9dc155ec19F43947ab59

Deploy token

$ oz send-tx
? Pick a network development
? Pick an instance STFactory at 0x8914a9E5C5E234fDC3Ce9dc155ec19F43947ab59
? Select which function deployToken(_ticker: string, _name: string, _owner: address)
? _ticker (string): My Token
? _name (string): TKN
? _owner (address): 0x13ebd3443fa5575F0Eb173e323D8419F7452CfB1
✓ Transaction successful. Transaction hash: 0xbff08f640515d175a33eb06e7002a2430721414dd022a3534f9e4d325d5c1dd5
Events emitted:
 - PauserRemoved(0x6edEA6a3AC207DDD1173448f62eb0819bb0f571A)
 - TokenDeployed(0x6edEA6a3AC207DDD1173448f62eb0819bb0f571A)

Hi @pkr,

You could create a registry contract and programmatically create tokens and update the registry, though that doesn’t sound better than using an on-chain factory.
https://docs.openzeppelin.com/sdk/2.5/zos-lib

Please be aware that the tokens created via the factory are not upgradeable whilst the tokens created via the CLI can be upgraded.

You’re such a rock star mate.
Thank you @abcoathup the recent changes work.

Create Contract

$ oz create
Nothing to compile, all contracts are up to date.
? Pick a contract to instantiate STFactory
? Pick a network development
All contracts are up to date
? Do you want to call a function on the instance after creating it? Yes
? Select which function * initialize(_owner: address)
? _owner (address): 0xf1a6D546A5baa618ebEBBE37f10be668239bE20e
✓ Instance created at 0x591db31df99717845B53e3Fe58Bbd973CFfcF398
0x591db31df99717845B53e3Fe58Bbd973CFfcF398

Deploy Token

$ oz send-tx
? Pick a network development
? Pick an instance STFactory at 0x591db31df99717845B53e3Fe58Bbd973CFfcF398
? Select which function deployToken(_ticker: string, _name: string, _owner: address)
? _ticker (string): ABC
? _name (string): ABC
? _owner (address): 0xf1a6D546A5baa618ebEBBE37f10be668239bE20e
✓ Transaction successful. Transaction hash: 0x4768347d816ebfdf32cceb8a280760c1d1c9c9da79503b09dd9538887e7cedda
Events emitted: 
 - PauserRemoved(0x19Fc5dE13D76ead5B622c9B73DA37cD48ceb1181)
 - TokenDeployed(0x19Fc5dE13D76ead5B622c9B73DA37cD48ceb1181)

Check Balance 1

$ oz balance
? Enter an address to query its balance 0xf1a6D546A5baa618ebEBBE37f10be668239bE20e
? Pick a network development
Balance: 99.7921448 ETH
99792144800000000000

Check Balance 2

$ oz balance
? Enter an address to query its balance 0x19Fc5dE13D76ead5B622c9B73DA37cD48ceb1181
? Pick a network development
Balance: 0 ETH
0

How can I check the ERC20 token balance? Is there a oz CLI command?

Also thanks for the suggestion on Registry contract – I am almost finished building one, will post soon. But I want to call the oz CLI from this Registry contract, such that the new contracts/tokens are upgradeable (if needed).

1 Like

Hi @pkr,

Currently there isn’t an OpenZeppelin CLI command to interact with contracts not created via the CLI.

I created a new truffle based project, so I could use truffle console and initialized it with truffle and openzeppelin.

npm init -y
npm i truffle 
npx truffle init 
oz init 
oz link @openzeppelin/contracts-ethereum-package  
npm i @openzeppelin/upgrades 

I added the factory contract to the project in my IDE.
I updated truffle-config.js to uncomment out the development network.
I then created the factory contract and deployed a new token (copying the address emitted from the event) using the OpenZeppelin CLI

I then interacted using truffle console.

$ truffle console 
truffle(development)> token = await StandaloneERC20.at("0x6edEA6a3AC207DDD1173448f62eb0819bb0f571A")
truffle(development)> await token.symbol()

STRegistry Smart Contract

pragma solidity >=0.5.0 <0.7.0;

/// dependencies
import "@openzeppelin/upgrades/contracts/Initializable.sol";
import "@openzeppelin/contracts-ethereum-package/contracts/math/SafeMath.sol";
import "@openzeppelin/contracts-ethereum-package/contracts/ownership/Ownable.sol";
import "@openzeppelin/contracts-ethereum-package/contracts/lifecycle/Pausable.sol";
import "./STFactory.sol";

contract STRegister is Initializable, Ownable, Pausable, STFactory {
  using SafeMath for uint256;
  /// states
  address stRegisterOwner;
  uint256 registeredTickerCount;
  uint256 registeredTokenCount;

  struct STTickerRegister {
    string _ticker;
    uint256 _registrationDate;
    address _owner;
  }
  mapping (uint256 => STTickerRegister) tickers;

  struct STTokenRegister {
    string _ticker;
    string _name;
    uint256 _registrationDate;
    address _tokenAddress;
    address _owner;
  }
  mapping (uint256 => STTokenRegister) tokens;

  /// events
  /// emit when a ticker is registered
  event RegisterTicker(
    string _ticker,
    uint256 _registrationDate,
    address indexed _owner
  );
  /// emit when a token is registered
  event RegisterToken(
    string _ticker,
    string _name,
    uint256 _registrationDate,
    address indexed _tokenAddress,
    address indexed _owner
  );

  /// modifiers

  /// functions
  /// initialize function
  function initialize(address _owner) public initializer {
    stRegisterOwner = _owner;
    Pausable.initialize(stRegisterOwner);
    registeredTickerCount = 0;
    registeredTokenCount = 0;
  }
  /// registerNewTicker function
  function registerNewTicker(
    string memory _ticker,
    address _owner
  )
    public whenNotPaused onlyOwner
  {
    _addTicker(_ticker, now, _owner);
  }
  /// _addTicker internal function
  function _addTicker(
    string memory _ticker,
    uint256 _registrationDate,
    address _owner
  )
    internal
  {
    uint256 idx = registeredTickerCount;
    tickers[idx]._ticker = _ticker;
    tickers[idx]._registrationDate = _registrationDate;
    tickers[idx]._owner = _owner;
    registeredTickerCount++;
    emit RegisterTicker(_ticker, _registrationDate, _owner);
  }
  /// registerNewToken function
  function registerNewToken(
    string memory _ticker,
    string memory _name,
    address _owner
  )
    public whenNotPaused onlyOwner
  {
    address _tokenAddress = _deployToken(_ticker, _name, _owner);
    _addToken(_ticker, _name, now, _tokenAddress, _owner);
  }
  /// _addToken internal function
  function _addToken(
    string memory _ticker,
    string memory _name,
    uint256 _registrationDate,
    address _tokenAddress,
    address _owner
  )
    internal
  {
    uint256 idx = registeredTokenCount;
    tokens[idx]._ticker = _ticker;
    tokens[idx]._name = _name;
    tokens[idx]._registrationDate = _registrationDate;
    tokens[idx]._tokenAddress = _tokenAddress;
    tokens[idx]._owner = _owner;
    registeredTokenCount++;
    emit RegisterToken (_ticker, _name, _registrationDate, _tokenAddress, _owner);
  }
}

Create Contract

$ oz create
Nothing to compile, all contracts are up to date.
? Pick a contract to instantiate STRegister
? Pick a network development
✓ Added contract STRegister
✓ Deploying @openzeppelin/contracts-ethereum-package dependency to network dev-1568869704928
✓ Contract STFactory deployed
✖ Validating and deploying contract STRegister
STRegister deployment failed with error: Returned error: VM Exception while processing transaction: out of gas

Colour Commentary
Looks like it doesn’t like something – STFactory is deployed, but STRegistry ran out of gas.

1 Like

Hi @pkr,

I was able to deploy STRegister using OpenZeppelin CLI (though it was using truffle-config.js for config.

You may need to increase your configured gas limit.

$ oz create
✓ Compiling contracts with Truffle, using settings from truffle.js file
Truffle output:

Compiling your contracts...
===========================
> Compiling ./contracts/Migrations.sol
> Compiling ./contracts/STFactory.sol
> Compiling ./contracts/STRegister.sol
> Compiling @openzeppelin/contracts-ethereum-package/contracts/GSN/Context.sol
> Compiling @openzeppelin/contracts-ethereum-package/contracts/access/Roles.sol
> Compiling @openzeppelin/contracts-ethereum-package/contracts/access/roles/MinterRole.sol
> Compiling @openzeppelin/contracts-ethereum-package/contracts/access/roles/PauserRole.sol
> Compiling @openzeppelin/contracts-ethereum-package/contracts/lifecycle/Pausable.sol
> Compiling @openzeppelin/contracts-ethereum-package/contracts/math/SafeMath.sol
> Compiling @openzeppelin/contracts-ethereum-package/contracts/ownership/Ownable.sol
> Compiling @openzeppelin/contracts-ethereum-package/contracts/token/ERC20/ERC20.sol
> Compiling @openzeppelin/contracts-ethereum-package/contracts/token/ERC20/ERC20Detailed.sol
> Compiling @openzeppelin/contracts-ethereum-package/contracts/token/ERC20/ERC20Mintable.sol
> Compiling @openzeppelin/contracts-ethereum-package/contracts/token/ERC20/ERC20Pausable.sol
> Compiling @openzeppelin/contracts-ethereum-package/contracts/token/ERC20/IERC20.sol
> Compiling @openzeppelin/contracts-ethereum-package/contracts/token/ERC20/StandaloneERC20.sol
> Compiling @openzeppelin/upgrades/contracts/Initializable.sol
> Artifacts written to /mnt/c/Users/andre/Documents/projects/forum/tokenfactory/build/contracts
> Compiled successfully using:
   - solc: 0.5.8+commit.23d335f2.Emscripten.clang


? Pick a contract to instantiate STRegister
? Pick a network development
✓ Deploying @openzeppelin/contracts-ethereum-package dependency to network dev-1568939673368
✓ Contract STFactory deployed
✓ Contract STRegister deployed
All contracts have been deployed
? Do you want to call a function on the instance after creating it? Yes
? Select which function * initialize(_owner: address)
? _owner (address): 0x13ebd3443fa5575F0Eb173e323D8419F7452CfB1
✓ Setting everything up to create contract instances
✓ Instance created at 0x26b4AFb60d6C903165150C6F0AA14F8016bE4aec
0x26b4AFb60d6C903165150C6F0AA14F8016bE4aec

Thank you @abcoathup let me try this approach w/ truffle + oz

Should I be using the following steps for all my oz projects?

npm init -y
npm i truffle 
npx truffle init 
oz init 
oz link @openzeppelin/contracts-ethereum-package  
npm i @openzeppelin/upgrades 

Next Steps:

  • Want to deploy these 2 contracts in Rinkeby network
  • User Terminal to configure APIs (Transaction, GraphQL)
  • Wire-up the DApp
1 Like

Hi @pkr,

I only used Truffle and OpenZeppelin as that is the last project I had around with your code in. You should be fine with OpenZeppelin CLI by itself, you probably just need to increase the gas limit.

Deploying your contracts to a public network is straight forward, there is a guide in the documentation: https://docs.openzeppelin.com/sdk/2.5/public-deploy

3 posts were split to a new topic: Openzeppelin accounts not working

What did you increase it by, to make it work?

networks.js

require('dotenv').config();

const HDWalletProvider = require('truffle-hdwallet-provider');
const infuraProjectId = process.env.INFURA_PROJECT_ID;

module.exports = {
  networks: {
    development: {
      protocol: 'http',
      host: 'localhost',
      port: 8545,
      gas: 50000000,
      gasPrice: 5e9,
      networkId: '*',
    },
    ropsten: {
      provider: () => new HDWalletProvider(process.env.DEV_MNEMONIC, "https://ropsten.infura.io/v3/" + infuraProjectId),
      networkId: 3,       // Ropsten's id
    },
    rinkeby: {
      provider: () => new HDWalletProvider(process.env.DEV_MNEMONIC, "https://rinkeby.infura.io/v3/" + infuraProjectId),
      networkId: 4,       // Rinkeby's id
    },
    mainnet: {
      provider: () => new HDWalletProvider(process.env.DEV_MNEMONIC, "https://mainnet.infura.io/v3/" + infuraProjectId),
      networkId: 1,       // Mainnet's id
    },
  },
};
1 Like

Hi @pkr,

Try upping the gas limit to 6000000.

Also I recommend that for mainnet deployment you use a different mnemonic than the one you use for the testnets. e.g. process.env.MAINNET_MNEMONIC