-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathdeploy_contract.js
More file actions
30 lines (21 loc) · 876 Bytes
/
deploy_contract.js
File metadata and controls
30 lines (21 loc) · 876 Bytes
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
const provider = require('./provider');
var ethers = require('ethers');
const fs = require('fs');
const ownerPrivateKey = fs.readFileSync(process.argv[2]).toString();
const wallet = new ethers.Wallet(ownerPrivateKey, provider);
const bytecodeFile = 'contract.bytecode'; //Default
const abiFile = 'contract.abi'; //Default
if (process.argv[3]) {
bytecodeFile = process.argv[3];
}
if (process.argv[4]) {
abiFile = process.argv[4];
}
const bytecode = fs.readFileSync(bytecodeFile).toString();
const abi = JSON.parse(fs.readFileSync(abiFile));
var deployTransaction = ethers.Contract.getDeployTransaction('0x'+bytecode, abi);
var sendPromise = wallet.sendTransaction(deployTransaction);
sendPromise.then(function(transaction) {
var contractAddress = ethers.utils.getContractAddress(transaction);
console.log(`Contract Address: ${contractAddress}`);
});