From b9b26e1d8a625152c4f31e5db4143fcd6bb8a94f Mon Sep 17 00:00:00 2001 From: Matt Condon Date: Fri, 24 Nov 2017 13:11:04 +0200 Subject: [PATCH] feat: allow configuration of ropsten and ganache with env variables --- .env.example | 5 +++++ migrations/2_deploy_contracts.js | 4 ++++ package.json | 3 +++ truffle-config.js | 32 ++++++++++++++++++++++++-------- 4 files changed, 36 insertions(+), 8 deletions(-) create mode 100644 .env.example diff --git a/.env.example b/.env.example new file mode 100644 index 000000000..889306334 --- /dev/null +++ b/.env.example @@ -0,0 +1,5 @@ +# configure your infura api key (not technically required) +INFURA_API_KEY= + +# change the mnemonic that your hd wallet is seeded with +MNEMONIC= diff --git a/migrations/2_deploy_contracts.js b/migrations/2_deploy_contracts.js index 2ce0dfa08..dd7257eb4 100644 --- a/migrations/2_deploy_contracts.js +++ b/migrations/2_deploy_contracts.js @@ -1,5 +1,9 @@ //var Ownable = artifacts.require("ownership/Ownable.sol"); +// NOTE: Use this file to easily deploy the contracts you're writing. +// (but make sure to reset this file before committing +// with `git checkout HEAD -- migrations/2_deploy_contracts.js`) + module.exports = function(deployer) { //deployer.deploy(Ownable); }; diff --git a/package.json b/package.json index a0b911b29..43847aaa9 100644 --- a/package.json +++ b/package.json @@ -41,5 +41,8 @@ "solidity-coverage": "^0.2.2", "truffle": "^4.0.0", "truffle-hdwallet-provider": "0.0.3" + }, + "dependencies": { + "dotenv": "^4.0.0" } } diff --git a/truffle-config.js b/truffle-config.js index 31397e46e..8b0f41df3 100644 --- a/truffle-config.js +++ b/truffle-config.js @@ -1,14 +1,20 @@ +require('dotenv').config(); require('babel-register'); require('babel-polyfill'); -var provider; -var HDWalletProvider = require('truffle-hdwallet-provider'); -var mnemonic = '[REDACTED]'; +const HDWalletProvider = require('truffle-hdwallet-provider'); -if (!process.env.SOLIDITY_COVERAGE){ - provider = new HDWalletProvider(mnemonic, 'https://ropsten.infura.io/') -} +const providerWithMnemonic = (mnemonic, rpcEndpoint) => + new HDWalletProvider(mnemonic, rpcEndpoint) +const infuraProvider = network => providerWithMnemonic( + process.env.MNEMONIC, + `https://${network}.infura.io/${process.env.INFURA_API_KEY}` +) + +const ropstenProvider = process.env.SOLIDITY_COVERAGE + ? undefined + : infuraProvider('ropsten') module.exports = { networks: { @@ -18,7 +24,7 @@ module.exports = { network_id: '*' }, ropsten: { - provider: provider, + provider: ropstenProvider, network_id: 3 // official id of the ropsten network }, coverage: { @@ -27,6 +33,16 @@ module.exports = { port: 8555, gas: 0xfffffffffff, gasPrice: 0x01 - } + }, + testrpc: { + host: 'localhost', + port: 8545, + network_id: '*' + }, + ganache: { + host: 'localhost', + port: 7545, + network_id: '*' + }, } };