-
Notifications
You must be signed in to change notification settings - Fork 17
/
hardhat.config.js
137 lines (124 loc) · 3.63 KB
/
hardhat.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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
const fs = require('fs');
const dotenv = require('dotenv');
const taskNames = require('hardhat/builtin-tasks/task-names');
require('@nomiclabs/hardhat-etherscan');
require('@nomiclabs/hardhat-waffle');
require('@nomiclabs/hardhat-ethers');
require('hardhat-gas-reporter');
require('hardhat-deploy');
dotenv.config();
const defaultNetwork = 'localhost';
function mnemonic() {
try {
return fs.readFileSync('./mnemonic.txt').toString().trim();
} catch (e) {
if (defaultNetwork !== 'localhost') {
console.log('☢️ WARNING: No mnemonic file created for a deploy account.');
}
}
return '';
}
const infuraId = process.env.INFURA_ID;
module.exports = {
defaultNetwork,
networks: {
localhost: {
url: 'http://localhost:8545',
},
rinkeby: {
url: 'https://rinkeby.infura.io/v3/' + infuraId,
gasPrice: 50000000000,
accounts: {
mnemonic: mnemonic(),
},
},
mainnet: {
url: 'https://mainnet.infura.io/v3/' + infuraId,
gasPrice: 160000000000,
accounts: {
mnemonic: mnemonic(),
},
},
},
namedAccounts: {
deployer: {
default: 0,
},
feeCollector: {
default: 0,
},
},
solidity: {
version: '0.8.6',
settings: {
optimizer: {
enabled: true,
runs: 10000,
},
},
},
mocha: {
bail: true,
timeout: 6000,
},
gasReporter: {
currency: 'USD',
// gasPrice: 21,
enabled: !!process.env.REPORT_GAS,
showTimeSpent: true,
},
etherscan: {
apiKey: `${process.env.ETHERSCAN_API_KEY}`,
},
};
// List details of deployer account.
task('account', 'Get balance informations for the deployment account.', async (_, { ethers }) => {
const hdkey = require('ethereumjs-wallet/hdkey');
const bip39 = require('bip39');
let mnemonic = fs.readFileSync('./mnemonic.txt').toString().trim();
const seed = await bip39.mnemonicToSeed(mnemonic);
const hdwallet = hdkey.fromMasterSeed(seed);
const wallet_hdpath = "m/44'/60'/0'/0/";
const account_index = 0;
let fullPath = wallet_hdpath + account_index;
const wallet = hdwallet.derivePath(fullPath).getWallet();
var EthUtil = require('ethereumjs-util');
const address = '0x' + EthUtil.privateToAddress(wallet._privKey).toString('hex');
console.log('Deployer Account: ' + address);
for (let n in config.networks) {
try {
let provider = new ethers.providers.JsonRpcProvider(config.networks[n].url);
let balance = await provider.getBalance(address);
console.log(' -- ' + n + ' -- -- -- 📡 ');
console.log(' balance: ' + ethers.utils.formatEther(balance));
console.log(' nonce: ' + (await provider.getTransactionCount(address)));
} catch (e) {
console.log(e);
}
}
});
task('compile:one', 'Compiles a single contract in isolation')
.addPositionalParam('contractName')
.setAction(async function (args, env) {
const sourceName = env.artifacts.readArtifactSync(args.contractName).sourceName;
const dependencyGraph = await env.run(taskNames.TASK_COMPILE_SOLIDITY_GET_DEPENDENCY_GRAPH, {
sourceNames: [sourceName],
});
const resolvedFiles = dependencyGraph.getResolvedFiles().filter((resolvedFile) => {
return resolvedFile.sourceName === sourceName;
});
const compilationJob = await env.run(
taskNames.TASK_COMPILE_SOLIDITY_GET_COMPILATION_JOB_FOR_FILE,
{
dependencyGraph,
file: resolvedFiles[0],
},
);
await env.run(taskNames.TASK_COMPILE_SOLIDITY_COMPILE_JOB, {
compilationJob,
compilationJobs: [compilationJob],
compilationJobIndex: 0,
emitsArtifacts: true,
quiet: true,
});
});