Skip to content

Commit

Permalink
chore: add etherscan support for verify plugin (#252)
Browse files Browse the repository at this point in the history
<!--

Thank you for contributing to the ZKsync Docs!

Before submitting the PR, please make sure you do the following:

- Update your PR title to follow [Conventional
Commits](https://www.conventionalcommits.org/en/v1.0.0/)
- Read the [Contributing
Guide](https://github.com/matter-labs/zksync-docs/blob/main/CONTRIBUTING.md).
- Understand our [Code of
Conduct](https://github.com/matter-labs/zksync-docs/blob/main/CODE_OF_CONDUCT.md)
- Please delete any unused parts of the template when submitting your PR

-->

# Description

Add Etherscan as an interface option for the verification process.

---------

Co-authored-by: Marko Arambasic <[email protected]>
  • Loading branch information
kiriyaga-txfusion and kiriyaga authored Jan 15, 2025
1 parent 1138afa commit f0f93cd
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,6 @@ Import the plugin in the `hardhat.config.ts` file:
import "@matterlabs/hardhat-zksync-verify";
```

Add the `verifyURL` property to the ZKsync Era network in the `hardhat.config.ts` file as shown below:

```typescript
networks: {
sepolia: {
Expand All @@ -77,11 +75,33 @@ networks: {
url: "%%zk_testnet_rpc_url%%", // The testnet RPC URL of ZKsync Era network.
ethNetwork: "%%zk_testnet_identifier%%", // The Ethereum Web3 RPC URL, or the identifier of the network (e.g. `mainnet` or `sepolia`)
zksync: true,
// Verification endpoint for Sepolia
verifyURL: '%%zk_testnet_contract_verification_url%%'
}
},
// defaultNetwork: "zkTestnet", // optional (if not set, use '--network zkTestnet')
```

#### Updates introduced in plugin version 1.7.0
Etherscan verification is supported. To enable it, configure the etherscan property in the Hardhat configuration:

```typescript
etherscan: {
apiKey: 'APIKEY'
}
```

If the etherscan property is configured and enabled, verification will run on Etherscan.
Otherwise, the plugin will default to verifying on the ZKsync block explorer.
For more information on how to create api keys, please [visit the documentation](https://docs.zksync.network/getting-started/viewing-api-usage-statistics).
For more information on how to configure etherscan for multiple api keys, please [visit the documentation](https://hardhat.org/hardhat-runner/plugins/nomicfoundation-hardhat-verify#multiple-api-keys-and-alternative-block-explorers)
The plugin provides pre-configured chain settings `zksyncsepolia` and `zksyncmainnet`, so users don't need to create custom chains.

```typescript
etherscan: {
apiKey: {
......
zksyncsepolia: 'APIKEY',
zksyncmainnet: 'APIKEY'
}
}
```

Additional network properties:
Expand All @@ -97,24 +117,19 @@ or the default `ethers` provider for the network if the configuration is not pro
- `zksync` is a flag that indicates a ZKsync Era network configuration. This field is set to `true` for all ZKsync Era networks.
If you want to run a `hardhat-verify` verification, this field needs to be set to `false`.
If set to `true`, the verification process will try to run the verification process on the ZKsync Era network.
- `verifyURL` is a field that points to the verification endpoint for the specific ZKsync network.
This parameter is optional, and its default value is the testnet verification url.
- Testnet: `%%zk_testnet_contract_verification_url%%`
- Mainnet: `%%zk_mainnet_contract_verification_url%%`

If you want to verify a smart contract on the Ethereum in the same project,
it is important to add `etherscan` field and API key in the `hardhat.config.ts` file:

```typescript
- `verifyURL` is a field that specifies the verification endpoint for the connected ZKsync network.
From version 1.7.0, the plugin automatically resolves this endpoint based on the network configuration.
If you are using a custom chain with an API compatible with the zksync block explorer, you can manually set the URL here.
- `browserVerifyURL` - Introduced in version 1.7.0 of the plugin, this field automatically resolves the browser URL based on the network configuration.
If you're using a custom chain, you can manually specify the URL here.
- `enableVerifyURL` - Introduced in version 1.7.0 of the plugin, this flag forces verification on the ZKsync block explorer.
It allows you to verify the same contract on both Etherscan and the ZKsync block explorer.

networks: {
...
},
etherscan: {
apiKey: //<Your API key for Etherscan>,
},

```
::callout{icon="i-heroicons-exclamation-triangle" color="amber"}
**verifyURL, browserVerifyURL and enableVerifyURL usage**
These properties are only for ZKsync block explorer verifications and do not affect Etherscan verifications,
as all Etherscan configurations are handled through the etherscan object.
::

### Commands

Expand Down Expand Up @@ -179,13 +194,6 @@ The verification process consists of two steps:
- A verification request is sent to confirm if the given parameters for your contract are correct.
- Then, we check the verification status of that request.
Both steps run when you run the `verify` task, but you will be able to see your specific verification request ID.
You can then use this ID to check the status of your verification request without running the whole process from the beginning.

The following command checks the status of the verification request for the specific verification ID:

```sh
yarn hardhat verify-status --verification-id <your verification id>
```

### Verify smart contract programmatically

Expand Down
2 changes: 2 additions & 0 deletions cspell-config/cspell-zksync.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,5 @@ ERAVM
foundryup-zksync
foundryup
zkvm
zksyncsepolia
zksyncmainnet

0 comments on commit f0f93cd

Please sign in to comment.