-
Notifications
You must be signed in to change notification settings - Fork 1.4k
/
Copy pathcreate2Deploy.js
54 lines (38 loc) · 1.88 KB
/
create2Deploy.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
// We require the Hardhat Runtime Environment explicitly here. This is optional
// but useful for running the script in a standalone fashion through `node <script>`.
//
// When running the script with `hardhat run <script>` you'll find the Hardhat
// Runtime Environment's members available in the global scope.
const { ethers } = require("hardhat");
async function main() {
const [deployer] = await ethers.getSigners();
console.log("Network ChainId:", (await ethers.provider.getNetwork()).chainId);
console.log(
"Deploying contracts with the account:",
deployer.address
);
console.log("Account balance:", (await deployer.getBalance()).toString());
const factoryContractDeployer = await ethers.getContractFactory("ExampleContractFactory");
const contractDeployer = await ethers.getContractFactory("ExampleContract");
const factoryContractdeployed = await factoryContractDeployer.deploy()
const exampleParam = 1
const salt = 1
const exampleContractBytecode = await factoryContractdeployed.getBytecode(exampleParam);
console.log("bytecode" , exampleContractBytecode)
const contractAddress = await factoryContractdeployed.getAddress(exampleContractBytecode, salt);
console.log("contract address calculated",contractAddress)
const contract = await contractDeployer.attach(contractAddress)
const deploy = await factoryContractdeployed.deployDeterministically(exampleParam,salt)
const receipt = await deploy.wait();
console.log("Factory deployed to:", receipt.events[0].args.contractAddress);
// let val = await contract.exampleVariable();
// console.log("exampleVariable ", val);
}
// We recommend this pattern to be able to use async/await everywhere
// and properly handle errors.
main()
.then(() => process.exit(0))
.catch(error => {
console.error(error);
process.exit(1);
});