-
Notifications
You must be signed in to change notification settings - Fork 2
/
deploy.js
60 lines (50 loc) · 1.7 KB
/
deploy.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
"use strict";
const { ethers } = require("hardhat");
const { preDeployConsole, postDeployConsole } = require("../utils/contracts");
const { toWei } = require("../utils/format");
const { verifyContract } = require("../utils/verify");
async function main() {
const { chainId } = await ethers.provider.getNetwork();
const [owner] = await ethers.getSigners();
const currentTimestampInSeconds = Math.round(Date.now() / 1000);
const ONE_YEAR_IN_SECS = 365 * 24 * 60 * 60;
const unlockTime = currentTimestampInSeconds + ONE_YEAR_IN_SECS;
const lockedAmount = toWei("1");
const CONTRACT_NAME = "Lock";
await preDeployConsole({
signerAddress: owner.address,
contractName: CONTRACT_NAME,
});
const LockFactory = await ethers.getContractFactory(CONTRACT_NAME);
let lock = await LockFactory.connect(owner).deploy(unlockTime, {
value: lockedAmount,
});
lock = await postDeployConsole({
contractName: CONTRACT_NAME,
contract: lock,
});
const lockAddress = await lock.getAddress();
console.log(
`Lock with 1 ETH and unlock timestamp ${unlockTime} deployed to ${lockAddress}`
);
// You don't want to verify on localhost
// uncomment below code to programmatically verify contract
try {
if (chainId != 31337 && chainId != 1337) {
const contractPath = `contracts/${CONTRACT_NAME}.sol:${CONTRACT_NAME}`;
await verifyContract({
contractPath: contractPath,
contractAddress: lockAddress,
args: [unlockTime],
});
}
} catch (error) {
console.log(error);
}
}
main()
.then(() => process.exit(0))
.catch((error) => {
console.log(error);
process.exit(1);
});