-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement hardhat API request for verifyContractABI (#250)
### TL;DR Added support for zkSync network contract verification using ABI-based verification method. ### What changed? - Introduced a new `VerificationService` class to handle ABI-based contract verification - Added zkSync network detection (chainIds: 300, 324, 37111) - Moved error handling logic to a separate file - Created new error types for username/project validation - Implemented ABI verification flow for zkSync contracts ### How to test? 1. Configure your Tenderly credentials in `hardhat.config.js`: ```javascript { tenderly: { username: "your-username", project: "your-project" } } ``` 2. Deploy a contract to zkSync network 3. Verify the contract using: ```javascript await hre.tenderly.verify({ address: "deployed-contract-address", name: "ContractName" }); ``` ### Why make this change? zkSync networks require a different verification approach due to their unique architecture. This change enables contract verification on zkSync networks by implementing an ABI-based verification method, ensuring compatibility with Tenderly's verification system.
- Loading branch information
Showing
4 changed files
with
101 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,27 @@ | ||
import { PLUGIN_NAME } from "./constants"; | ||
import { HardhatRuntimeEnvironment } from "hardhat/types"; | ||
|
||
export class UndefinedChainIdError extends Error { | ||
constructor(networkName: string) { | ||
super(`Couldn't find chainId for the network: ${networkName}. \nPlease provide the chainId in the network config object`); | ||
} | ||
} | ||
|
||
export class UsernameOrProjectNotProvidedError extends Error { | ||
constructor() { | ||
super(`Please provide the username and project fields in the tenderly object in hardhat.config.js`); | ||
} | ||
} | ||
|
||
|
||
export async function throwIfUsernameOrProjectNotSet( | ||
hre: HardhatRuntimeEnvironment, | ||
): Promise<void> { | ||
if (hre.config.tenderly?.username === undefined) { | ||
throw new UsernameOrProjectNotProvidedError(); | ||
} | ||
if (hre.config.tenderly?.project === undefined) { | ||
throw new UsernameOrProjectNotProvidedError(); | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { VerificationService } from "./service" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import { TenderlyService } from "@tenderly/api-client"; | ||
import { | ||
VerifyContractABIRequest, | ||
VerifyContractABIResponse | ||
} from "@tenderly/api-client"; | ||
import { HardhatRuntimeEnvironment } from "hardhat/types"; | ||
import { throwIfUsernameOrProjectNotSet } from "../errors"; | ||
import { getChainId } from "../utils/util"; | ||
|
||
export class VerificationService { | ||
private readonly tenderlyService: TenderlyService; | ||
|
||
constructor( | ||
tenderlyService: TenderlyService | ||
) { | ||
this.tenderlyService = tenderlyService; | ||
} | ||
|
||
public async verifyContractABI( | ||
hre: HardhatRuntimeEnvironment, | ||
address: string, | ||
contractName: string, | ||
): Promise<VerifyContractABIResponse> { | ||
await throwIfUsernameOrProjectNotSet(hre); | ||
|
||
const networkId = await getChainId(hre); | ||
const abi = (await hre.artifacts.readArtifact(contractName)).abi; | ||
const abiString = JSON.stringify(abi); | ||
|
||
const request: VerifyContractABIRequest = { | ||
networkId: networkId.toString(), | ||
address: address, | ||
contractName: contractName, | ||
abi: abiString, | ||
} | ||
|
||
const username = hre.config.tenderly.username; | ||
const project = hre.config.tenderly.project; | ||
|
||
return await this.tenderlyService.verifyContractABI( | ||
username, | ||
project, | ||
request, | ||
) | ||
} | ||
} |