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
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