Skip to content

Commit a24d26c

Browse files
committed
Add verify contract script
1 parent 0b47708 commit a24d26c

File tree

2 files changed

+64
-1
lines changed

2 files changed

+64
-1
lines changed

packages/hardhat/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
"lint": "eslint",
2020
"lint-staged": "eslint",
2121
"test": "REPORT_GAS=true hardhat test --network hardhat",
22-
"verify": "hardhat etherscan-verify"
22+
"verify": "hardhat run scripts/verifyContract.ts"
2323
},
2424
"dependencies": {
2525
"@inquirer/password": "^4.0.2",
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
import { exec } from "child_process";
2+
import fs from "fs";
3+
import path from "path";
4+
import util from "util";
5+
6+
const execPromise = util.promisify(exec);
7+
8+
async function main() {
9+
try {
10+
// Get the deployments directory path
11+
const deploymentsPath = path.join(__dirname, "../deployments/monadTestnet");
12+
13+
// Read all files in the deployments directory
14+
const files = fs.readdirSync(deploymentsPath);
15+
16+
// Filter for .json files and get the latest one by modification time
17+
const jsonFiles = files
18+
.filter(file => file.endsWith(".json"))
19+
.map(file => ({
20+
name: file,
21+
time: fs.statSync(path.join(deploymentsPath, file)).mtime.getTime(),
22+
}))
23+
.sort((a, b) => b.time - a.time);
24+
25+
if (jsonFiles.length === 0) {
26+
throw new Error("No deployment files found");
27+
}
28+
29+
// Read the latest deployment file
30+
const latestDeployment = JSON.parse(fs.readFileSync(path.join(deploymentsPath, jsonFiles[0].name), "utf8"));
31+
32+
const contractAddress = latestDeployment.address;
33+
const constructorArgs = latestDeployment.args;
34+
35+
console.log(`Latest deployed contract address: ${contractAddress}`);
36+
console.log(`Contract name: ${jsonFiles[0].name.replace(".json", "")}`);
37+
console.log(`Constructor arguments: ${constructorArgs.join(", ")}`);
38+
39+
// Run the verify command with constructor arguments
40+
console.log("Starting verification...");
41+
const { stdout, stderr } = await execPromise(
42+
`yarn hardhat verify --network monadTestnet ${contractAddress} ${constructorArgs.join(" ")}`,
43+
);
44+
45+
console.log("Verification output:");
46+
console.log(stdout);
47+
48+
if (stderr) {
49+
console.error("Verification errors:");
50+
console.error(stderr);
51+
}
52+
} catch (error) {
53+
console.error("Error during verification:", error);
54+
process.exit(1);
55+
}
56+
}
57+
58+
main()
59+
.then(() => process.exit(0))
60+
.catch(error => {
61+
console.error(error);
62+
process.exit(1);
63+
});

0 commit comments

Comments
 (0)