OpenZeppelin CLI Testnet and Mainnet configuration

The following shows the configuration for accessing testnet and mainnet with OpenZeppelin CLI. See Connecting to Public Test Networks for details.

Similar configuration can be used for Truffle.

network.js

const { projectId, mnemonic } = require('./secrets.json');
const HDWalletProvider = require('@truffle/hdwallet-provider');

module.exports = {
  networks: {
    development: {
      protocol: 'http',
      host: 'localhost',
      port: 8545,
      gas: 5000000,
      gasPrice: 5e9,
      networkId: '*',
    },
    rinkeby: {
      provider: () => new HDWalletProvider(
        mnemonic, `https://rinkeby.infura.io/v3/${projectId}`
      ),
      networkId: 4,
      gasPrice: 10e9
    },
    mainnet: {
      provider: () => new HDWalletProvider(
        mnemonic, `https://mainnet.infura.io/v3/${projectId}`
      ),
      networkId: 1,
      gasPrice: 30e9  // check https://www.ethgasstation.info/
    },
  },
};

secrets.json

:warning: Do not commit secrets to version control (they can be used by bots or others).
Mnemonics need to be kept secure. Be cautious of value and access controlled by this mnemonic.

{
    "mnemonic": "twelve word seed phrase keep secret do not commit...",
    "projectId": "zzzzInfuraProjectIDzzzzz"
}

package.json

{
  "name": "mainnet",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "keywords": [],
  "author": "",
  "license": "MIT",
  "dependencies": {
    "@openzeppelin/cli": "^2.8.2",
    "@truffle/hdwallet-provider": "^1.0.36"
  }
}

Get accounts

$ npx oz accounts
? Pick a network mainnet
Accounts for mainnet:
Default: 0x77737a65C296012C67F8c7f656d1Df81827c9541
All:
- 0: 0x77737a65C296012C67F8c7f656d1Df81827c9541
- 1: 0x059aE37646900CaA1680473d1280246AfCCC3114
- 2: 0x74CbeDB8db9787429525ae08430b98d201488289
- 3: 0x52Af299cD058BC0855B49058099d28D58BD6276b
- 4: 0xc177224c30b4f538948B3740106c97bBac42F0b3
- 5: 0x9112E0ec0138dD29701f89b4e778622B663B9418
- 6: 0xFAF6DAb0cFe4271ea9aE203790ac0883349B80c1
- 7: 0x2FCf9A112b62D5f2Faa11a70521d5100407A1a6e
- 8: 0xBe3F5b240Fa1ffc2e2bbC81db497958f5d3e984A
- 9: 0x5f308f47Cd94f0782ba1Cb9adc7cAE697524C74E

Balance

$ npx oz balance
? Enter an address to query its balance 0x77737a65C296012C67F8c7f656d1Df81827c9541
? Pick a network mainnet
Balance: 0 ETH
0

I get “unexpected identifier” when I try to run with these settings. Checked the ProjectID and it seems to be correct.

1 Like

I assume that you have a malformed network.js.

Can you share your network.js? Please don’t include any secrets (mnemonic, Infura Project ID).

Hi Andrew,

Thanks, I got it to work now, happy about that.

  1. These configuration files are more clear and easier to get started with than the ones in the link you sent previously
  2. I also had an issue on my side, I was working on a server using SSH so I got some formatting issues which were causing the error. I will try to update my setup so it won’t happen again.

See you next time.

1 Like

Hi @TivoliLocust,

I’m glad you were able to resolve.

I created these using the Learn guide, though I agree it can be easier just to copy and paste the whole contents of the file.