generated from ahmedali8/hardhat-ts-template
-
Notifications
You must be signed in to change notification settings - Fork 2
/
verify.ts
62 lines (57 loc) · 1.65 KB
/
verify.ts
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
61
62
/* eslint-disable @typescript-eslint/no-explicit-any */
import type { TransactionResponse } from "ethers";
import { run } from "hardhat";
import { delayLog } from "./misc";
/**
* Waits for the specified number of confirmations for a given transaction.
*
* @param tx - The transaction response to wait for confirmations.
* @param waitConfirmations - The number of confirmations to wait for. Default is 5.
* @returns A promise that resolves when the specified number of confirmations have been received.
*/
export async function waitForConfirmations(
tx: TransactionResponse,
waitConfirmations: number = 5
): Promise<void> {
if (!tx) {
return;
}
console.log(`Waiting for ${waitConfirmations} confirmations...`);
await tx.wait(waitConfirmations);
}
/**
* Interface for the input parameters of `verifyContract` function.
*/
interface VerifyContractParams {
contractAddress: string;
args?: any[];
contractPath?: string;
delay?: number;
}
/**
* Programmatically verify the given contract using the specified parameters.
*
* @param params - The parameters for contract verification.
* @returns A promise that resolves when the contract has been verified.
*/
export async function verifyContract({
contractAddress,
args = [],
contractPath,
delay = 60_000,
}: VerifyContractParams): Promise<void> {
await delayLog(delay);
try {
await run("verify:verify", {
address: contractAddress,
constructorArguments: args,
contract: contractPath,
});
} catch (error: any) {
if (error.message.toLowerCase().includes("already verified")) {
console.log("Already verified!");
} else {
console.log(error);
}
}
}