Verify a Smart Contract
Verify your smart contract on Gravity Alpha Mainnet
There are four major ways to verify contracts on OKLink:
1. Explorer Interface
You can verify a deployed contract directly through the OKLink interface.
2. Contract Verification APIs
OKLink provides a set of contract verification APIs.
3. Verify Using Foundry
Prerequisite: Get an OKLink API Key
Apply for an API key: https://www.oklink.com/account/my-api
Run forge verify-contract
To verify a contract, you need to provide:
The deployed contract address
The contract path and name (e.g.,
src/MyToken.sol:MyToken)The OKLink
verify-urlfor your target chainYour OKLink API key
Command format:
Check Verification Status
It is recommended to use the --watch flag to continuously poll for verification status.
If you didn’t use --watch, you can manually check the result using:
4. Verify Using Hardhat
Method 1 (Recommended): Using @okxweb3/hardhat-explorer-verify Plugin
@okxweb3/hardhat-explorer-verify PluginThis method uses an official Hardhat plugin provided by OKX. It provides a CLI command (npx hardhat okverify) to automate contract verification.
1. Install the Plugin
2. Configure hardhat.config.ts
Here is a sample configuration for Gravity Chain:
3. Verify the Contract
After deployment, verify with:
4. Verifying Proxy Contracts
For contracts deployed via TransparentUpgradeableProxy, use:
If you're using the 897 proxy standard, omit --proxy and just run the command as normal
Method 2: Manually Configuring etherscan.customChains for OKLink
etherscan.customChains for OKLinkYou can also verify contracts using Hardhat's native Etherscan integration by overriding the default verification endpoint.
Configuration Example:
This enables Hardhat’s built-in verify task to interact with OKLink:
⚠️ You’ll still need to ensure your contract metadata matches what OKLink expects (e.g., compiler version, optimization settings, source flattening if needed).
For hardhat users, you will need to change your hardhat.config.ts to something like the following example:
For foundry users, we recommend you to use scripts to deploy your contracts. You will need to configure the foundry.toml file as the following:
Then you when you run your scripts, you can verify contracts deployed with --verify option.
NOTE: If contracts were deployed successfully but verification failed, DO NOT delete the broadcast/ directory. You can resume the verification process by removing the --broadcast option and providing the deployment transaction sender's key like below: (or you can configure it in cast):
Last updated
Was this helpful?

