This repository has been archived by the owner on Feb 18, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtruffle-config.js
108 lines (100 loc) · 2.95 KB
/
truffle-config.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
process.env.DEBUG = process.env.DEBUG || "DEBUG-*,INFO-*,WARN-*,ERROR-*"
const assert = require('assert')
const debug = require("debug")("DEBUG-truffle")
const HDWalletProvider = require('truffle-hdwallet-provider')
const GAS_PRICE_GWEI = process.env.GAS_PRICE_GWEI || 5
const GAS_LIMIT = 6.5e6
const DEFAULT_MNEMONIC = 'candy maple cake sugar pudding cream honey rich smooth crumble sweet treat'
// Load env vars
require('dotenv').config()
// Get the mnemonic
const privateKey = process.env.PK
let mnemonic = process.env.MNEMONIC
if (!privateKey && !mnemonic) {
mnemonic = DEFAULT_MNEMONIC
}
const infuraProjectId = process.env.INFURA_KEY || '9408f47dedf04716a03ef994182cf150'
function truffleConfig({
mnemonic = DEFAULT_MNEMONIC,
privateKey,
gasPriceGWei = GAS_PRICE_GWEI,
gas = GAS_LIMIT,
optimizedEnabled = true,
urlRinkeby = 'https://rinkeby.infura.io/v3/' + infuraProjectId,
urlKovan = 'https://kovan.infura.io/v3/' + infuraProjectId,
urlMainnet = 'https://mainnet.infura.io/v3/' + infuraProjectId,
urlDevelopment = 'localhost',
portDevelopment = 8545
} = {}) {
assert(mnemonic, 'The mnemonic has not been provided');
debug(`Using gas limit: ${gas / 1000} K`);
debug(`Using gas price: ${gasPriceGWei} Gwei`);
debug(`Optimizer enabled: ${optimizedEnabled}`);
debug('Using default mnemonic: %s', mnemonic === DEFAULT_MNEMONIC);
const gasPrice = gasPriceGWei * 1e9;
let _getProvider
if (privateKey) {
debug('Using private key')
_getProvider = url => {
return () => {
assert(infuraProjectId, "Need an infura ProjectID. INFURA_KEY env var")
return new HDWalletProvider([privateKey], url)
}
}
} else {
debug(mnemonic === DEFAULT_MNEMONIC ? 'Using default mnemonic' : 'Using custom mnemonic')
_getProvider = url => {
return () => {
assert(infuraProjectId, "Need an infura ProjectID. INFURA_KEY env var")
return new HDWalletProvider(mnemonic, url)
}
}
}
return {
networks: {
development: {
host: process.env.RPC_URL || urlDevelopment,
port: portDevelopment,
gas,
gasPrice,
network_id: '*'
},
mainnet: {
provider: _getProvider(urlMainnet),
network_id: '1',
gas,
gasPrice
},
rinkeby: {
provider: _getProvider(urlRinkeby),
network_id: '4',
gas,
gasPrice
},
kovan: {
provider: _getProvider(urlKovan),
network_id: '42',
gas,
gasPrice
},
},
compilers: {
solc: {
version: '0.5.2',
docker: process.env.SOLC_USE_DOCKER === 'true' || false,
settings: {
optimizer: {
enabled: optimizedEnabled, // Default: false
runs: 200
}
// evmVersion: "byzantium" // Default: "byzantium". Others: "homestead", ...
}
}
}
};
}
module.exports = truffleConfig({
optimizedEnabled: true,
mnemonic,
privateKey
})