Skip to main content

Contract Verification

Verify the Shield contract source code on BaseScan for transparency.

Why Verify?

  • ✅ Users can verify contract logic
  • ✅ Tools can read contract ABI
  • ✅ Required for some integrations
  • ✅ Builds trust

Hardhat Verification

Install Plugin

cd contracts
npm install --save-dev @nomicfoundation/hardhat-verify

Configure

// hardhat.config.ts
import '@nomicfoundation/hardhat-verify';

export default {
  // ... other config
  etherscan: {
    apiKey: {
      baseSepolia: process.env.BASESCAN_API_KEY,
      baseMainnet: process.env.BASESCAN_API_KEY,
    },
  },
};

Get API Key

  1. Go to BaseScan
  2. Register account
  3. Go to API Keys
  4. Create new key

Verify

# Testnet
npx hardhat verify --network baseSepolia CONTRACT_ADDRESS

# Mainnet
npx hardhat verify --network baseMainnet CONTRACT_ADDRESS

Manual Verification

If Hardhat verification fails, verify manually:
  1. Go to BaseScan
  2. Search for contract address
  3. Click “Verify and Publish”
  4. Select:
    • Compiler Type: Solidity (Single file)
    • Compiler Version: 0.8.24
    • License: MIT
  5. Paste source code
  6. Click “Verify”

Flattened Source

If using imports, flatten first:
npx hardhat flatten contracts/Shield.sol > Shield_flat.sol
Then verify with Shield_flat.sol.

Verification Status

Check verification status:
curl "https://api.basescan.org/api?module=contract&action=getabi&address=CONTRACT_ADDRESS"
Success response:
{
  "status": "1",
  "message": "OK",
  "result": "[{\"constant\":true,\"inputs\":[]..."
}