Skip to content

Commit

Permalink
feat: allow configuration of ropsten and ganache with env variables
Browse files Browse the repository at this point in the history
  • Loading branch information
shrugs committed Dec 1, 2017
1 parent 887c1bb commit b9b26e1
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 8 deletions.
5 changes: 5 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -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=
4 changes: 4 additions & 0 deletions migrations/2_deploy_contracts.js
Original file line number Diff line number Diff line change
@@ -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);
};
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,8 @@
"solidity-coverage": "^0.2.2",
"truffle": "^4.0.0",
"truffle-hdwallet-provider": "0.0.3"
},
"dependencies": {
"dotenv": "^4.0.0"
}
}
32 changes: 24 additions & 8 deletions truffle-config.js
Original file line number Diff line number Diff line change
@@ -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: {
Expand All @@ -18,7 +24,7 @@ module.exports = {
network_id: '*'
},
ropsten: {
provider: provider,
provider: ropstenProvider,
network_id: 3 // official id of the ropsten network
},
coverage: {
Expand All @@ -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: '*'
},
}
};

0 comments on commit b9b26e1

Please sign in to comment.