This repository has been archived by the owner on Sep 20, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 196
/
truffle.js
118 lines (109 loc) · 3.48 KB
/
truffle.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
109
110
111
112
113
114
115
116
117
118
const HDWalletProvider = require("truffle-hdwallet-provider")
const PrivateKeyProvider = require('truffle-privatekey-provider')
const NonceTrackerSubprovider = require("web3-provider-engine/subproviders/nonce-tracker")
// How many addresses in wallet should we unlock?
// (For deploying test data, we use other addresses as buyers and sellers)
// Note: This is not used for Mainnet - only for Testnet and local deployment.
const numAddressesToUnlock = 4
const providerUrl = process.env.PROVIDER_URL
// Local setup
truffleSetup = {
migrations_directory: "./migrations",
networks: {
development: {
host: "localhost",
port: 8545,
network_id: "*" // Match any network id
}
},
coverage: {
host: "localhost",
network_id: "*",
port: 8555, // <-- If you change this, also set the port option in .solcover.js.
gas: 0xfffffffffff, // <-- Use this high gas value
gasPrice: 0x01 // <-- Use this low gas price
},
solc: { optimizer: { enabled: true, runs: 200 } }
}
// This function adds protection against the "nonce too low" error seen on some
// web3 provider server farms.
//
// For more details see:
// https://ethereum.stackexchange.com/questions/44349/truffle-infura-on-mainnet-nonce-too-low-error
function withNonceTracker(provider) {
const nonceTracker = new NonceTrackerSubprovider()
provider.engine._providers.unshift(nonceTracker)
nonceTracker.setEngine(provider.engine)
return provider
}
// When a mnemonic is set, the first address for that mnemonic is used to do the deployment.
// In future we might consider prompting for mnemonics:
// https://www.npmjs.com/package/prompt
//
if (process.env.MAINNET_PRIVATE_KEY || process.env.MAINNET_MNEMONIC) {
const privateKey = process.env.MAINNET_PRIVATE_KEY
const mnemonic = process.env.MAINNET_MNEMONIC
// Private key takes precedence over mnemonic.
if (privateKey) {
truffleSetup.networks.mainnet = {
provider: function() {
return withNonceTracker(new PrivateKeyProvider(privateKey, providerUrl))
},
network_id: 1
}
console.log('Configured truffle to use PrivateKey provider for Mainnet.')
} else {
truffleSetup.networks.mainnet = {
provider: function() {
return withNonceTracker(new HDWalletProvider(mnemonic, providerUrl))
},
network_id: 1
}
console.log('Configured truffle to use Mnemonic provider for Mainnet.')
}
}
if (process.env.RINKEBY_MNEMONIC) {
truffleSetup.networks.rinkeby = {
provider: function() {
return withNonceTracker(new HDWalletProvider(
process.env.RINKEBY_MNEMONIC,
providerUrl,
0, numAddressesToUnlock
))
},
network_id: 4
}
}
if (process.env.ROPSTEN_MNEMONIC) {
truffleSetup.networks.ropsten = {
provider: function() {
return withNonceTracker(new HDWalletProvider(
process.env.ROPSTEN_MNEMONIC,
providerUrl,
0, numAddressesToUnlock
))
},
gas: 3712388,
network_id: 3
}
}
// Origin's own test network
if (process.env.ORIGIN_MNEMONIC) {
truffleSetup.networks.origin = {
provider: function() {
return withNonceTracker(new HDWalletProvider(
process.env.ORIGIN_MNEMONIC,
providerUrl,
0,
numAddressesToUnlock
))
},
gas: 4712388,
network_id: 2222
}
}
// These are needed to use ES2015+ syntax, such as import. The token tests
// imported from OpenZeppelin need these.
require('@babel/register')
require('@babel/polyfill')
module.exports = truffleSetup