-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdeploy.js
More file actions
56 lines (43 loc) · 2.39 KB
/
deploy.js
File metadata and controls
56 lines (43 loc) · 2.39 KB
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
/*
Author: Soham Zemse (https://github.com/zemse)
*/
const path = require('path');
const fs = require('fs-extra');
const ethers = require('ethers');
if(!process.argv[2]) {
throw '\nNOTE: Please pass a file name or all flag, your network (homestead, ropsten, ...) as first comand line argument and private key as second command line argument.\neg => node deploy.js deployall rinkeby 0xa6779f54dc1e9959b81f448769450b97a9fcb2b41c53d4b2ab50e5055a170ce7\n';
}
if(!process.argv[3]) {
throw '\nNOTE: Please pass your network (homestead, ropsten, ...) as first comand line argument and private key as second command line argument.\neg => node deploy.js deployall rinkeby 0xa6779f54dc1e9959b81f448769450b97a9fcb2b41c53d4b2ab50e5055a170ce7\n';
if(!['homestead', 'ropsten', 'kovan', 'rinkeby', 'goerli'].includes(process.argv[3])) {
throw `\nNOTE: Network should be: homestead, ropsten, kovan, rinkeby or goerli\n`
}
}
if(!process.argv[4]) {
throw '\nNOTE: Please pass your private key as comand line argument after network.\neg => node deploy.js deployall rinkeby 0xa6779f54dc1e9959b81f448769450b97a9fcb2b41c53d4b2ab50e5055a170ce7\n';
}
const provider = ethers.getDefaultProvider(process.argv[3]);
console.log(`\nUsing ${process.argv[3]} network...`);
console.log('\nLoading wallet...');
const wallet = new ethers.Wallet(process.argv[4], provider);
console.log(`Wallet loaded ${wallet.address}\n`);
const buildFolderPath = path.resolve(__dirname, 'build');
const deployFile = async jsonFileName => {
console.log(`Preparing to deploy '${jsonFileName}' contract`);
const jsonFilePath = path.resolve(__dirname, 'build', jsonFileName);
const contractJSON = JSON.parse(fs.readFileSync(jsonFilePath, 'utf8'));
const ContractFactory = new ethers.ContractFactory(
contractJSON.abi,
contractJSON.evm.bytecode.object,
wallet
);
const contractInstance = await ContractFactory.deploy(...process.argv.slice(5));
console.log(`Deploying '${jsonFileName}' contract at ${contractInstance.address}\nhttps://${process.argv[3] !== 'homestead' ? process.argv[3] : 'www'}.etherscan.io/tx/${contractInstance.deployTransaction.hash}\nwaiting for confirmation...`);
await contractInstance.deployTransaction.wait();
console.log(`Contract is deployed at ${contractInstance.address}\n`);
};
if(process.argv[2] === 'deployall') {
fs.readdirSync(buildFolderPath).forEach(deployFile);
} else {
deployFile(process.argv[2]);
}