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 interfacearrow-up-right.

2. Contract Verification APIs

OKLink provides a set of contract verification APIsarrow-up-right.

3. Verify Using Foundry

Prerequisite: Get an OKLink API Key

Apply for an API key: https://www.oklink.com/account/my-apiarrow-up-right

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-url for your target chain

  • Your 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

This 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

You 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).


circle-info

Blockscout uses the global blockscout verifier (so that similar contracts get automatically verified), it can sometimes be flaky. Please try again a bit later.

For contracts deployed by create2, you may ran into Fail - Unable to verify. You will have to visit the contract address page after deployment first. Then blockscout will fetch it from the RPC and see that it is a contract, then verification should work. Contract address page: https://explorer.gravity.xyz/address/***

For hardhatarrow-up-right users, you will need to change your hardhat.config.ts to something like the following example:

For foundryarrow-up-right users, we recommend you to use scriptsarrow-up-right 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?