-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeploy.js
More file actions
49 lines (39 loc) · 1.55 KB
/
deploy.js
File metadata and controls
49 lines (39 loc) · 1.55 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
const { ethers } = require("hardhat");
async function main() {
console.log("Deploying ImprovedOnChainBattleship...");
// Get the ContractFactory and Signers
const [deployer] = await ethers.getSigners();
console.log("Deploying contracts with the account:", deployer.address);
console.log("Account balance:", (await deployer.getBalance()).toString());
// Deploy the contract
const ImprovedOnChainBattleship = await ethers.getContractFactory("ImprovedOnChainBattleship");
const contract = await ImprovedOnChainBattleship.deploy();
await contract.deployed();
console.log("ImprovedOnChainBattleship deployed to:", contract.address);
console.log("Transaction hash:", contract.deployTransaction.hash);
// Wait for a few block confirmations
console.log("Waiting for block confirmations...");
await contract.deployTransaction.wait(6);
console.log("Contract deployed successfully!");
console.log("Contract address:", contract.address);
console.log("Block number:", await ethers.provider.getBlockNumber());
// Verify the contract (optional)
if (network.name !== "hardhat" && network.name !== "localhost") {
console.log("Verifying contract...");
try {
await hre.run("verify:verify", {
address: contract.address,
constructorArguments: [],
});
console.log("Contract verified successfully!");
} catch (error) {
console.log("Error verifying contract:", error.message);
}
}
}
main()
.then(() => process.exit(0))
.catch((error) => {
console.error(error);
process.exit(1);
});