# Verify an EVM Contract

Sai Ops recompiles your Solidity build and compares it with the bytecode at the deployed address. Use the same source files, compiler version, optimizer settings, and library addresses as the original build. Keep the build artifacts from your deployment. The verification request runs off-chain and does not need a wallet private key.

[Read this guide as Markdown](/docs/dev/verify-evm-contracts.md)

## Networks and Access

| Network | Verification API |
| --- | --- |
| Sai L1 (`6900`) | `https://ops-api.sai.fun/public/evm/6900/api` |
| Sai L1 Testnet (`6911`) | `https://ops-api.sai.fun/public/evm/6911/api` |

Submissions require a Sai Ops operator key. Set it as the environment variable `SAI_EVM_VERIFY_API_KEY` in the shell running the command. ABI, source, and job status lookups are public. A successful verification publishes the submitted source and compiler settings.

## Verify with Hardhat 2

In your Hardhat 2 project, load the plugin `@nomicfoundation/hardhat-verify`. Merge these entries into your existing Hardhat config, keeping the compiler settings you used for deployment.

```js
networks: {
  sai: {
    url: "https://evm-rpc.nibiru.fi/",
    chainId: 6900,
  },
},
etherscan: {
  apiKey: { sai: process.env.SAI_EVM_VERIFY_API_KEY ?? "" },
  customChains: [{
    network: "sai",
    chainId: 6900,
    urls: {
      apiURL: "https://ops-api.sai.fun/public/evm/6900/api",
      browserURL: "https://ops-api.sai.fun/public/evm/6900",
    },
  }],
},
```

Set `CONTRACT_ADDRESS` to the deployed Sai L1 address and use the source path and contract name from your project.

```bash
npx hardhat verify --network sai --contract contracts/Counter.sol:Counter "$CONTRACT_ADDRESS"
```

Append any constructor arguments after the address, in deployment order. Use the project and build that produced the deployed contract. The command also works with `bunx hardhat`.

## Verify with Foundry

With Foundry 1.7.1, add this entry to your existing `foundry.toml`.

```toml
[etherscan.sai]
chain = 6900
key = "${SAI_EVM_VERIFY_API_KEY}"
url = "https://ops-api.sai.fun/public/evm/6900/api"
browser_url = "https://ops-api.sai.fun/public/evm/6900"
```

Use your Sai L1 deployment address and the source path and contract name from your project.

```bash
forge verify-contract "$CONTRACT_ADDRESS" src/Counter.sol:Counter \
  --chain 6900 --rpc-url https://evm-rpc.nibiru.fi/ \
  --verifier etherscan --verifier-url https://ops-api.sai.fun/public/evm/6900/api \
  --watch
```

If the deployment used constructor arguments, pass their ABI-encoded bytes with `--constructor-args`.

## Query the ABI, Source, or Job Status

Use WNIBI on Sai L1 to try the public lookup.

```bash
api=https://ops-api.sai.fun/public/evm/6900/api
address=0x0CaCF669f8446BeCA826913a3c6B96aCD4b02a97

curl -fsSG "$api" --data module=contract --data action=getabi \
  --data-urlencode "address=$address" | jq -e 'select(.status == "1") | .result | fromjson'

curl -fsSG "$api" --data module=contract --data action=getsourcecode \
  --data-urlencode "address=$address" | jq '.result[0]'
```

For `getabi`, parse the response's `result` string as JSON. An unknown or unverified address returns an empty `SourceCode` field on `getsourcecode`. For an existing job, poll `checkverifystatus` on the same chain's API with `module=contract` and `guid=<job-id>`. The response reports `Pending in queue`, `Pass - Verified`, or `Fail - Unable to verify`. Inspect the response envelope as Etherscan-style errors can use HTTP 200.

For typed match evidence and the ABI together, query Sai Ops GraphQL.

```bash
curl -fsS https://ops-api.sai.fun/public/graphql \
  -H 'Content-Type: application/json' \
  --data '{"query":"{ contractVerification(chainId: \"6900\", address: \"0x0CaCF669f8446BeCA826913a3c6B96aCD4b02a97\") { address runtimeMatch creationMatch compilerVersion abi } }"}'
```

A runtime match covers the code currently at the address. An exact runtime match also matches the Solidity compiler metadata. Creation proof separately checks the deployment bytecode when available, and the GraphQL field `creationMatch` can be null. A proxy proof covers the proxy's bytecode. To check the implementation's source, look up its own address. The public GraphQL field `contract` can return a curated ABI for decoding proxy calls.

## Verify on Sai L1 Testnet

### Hardhat 2

For a testnet deployment, add the `saiTestnet` network and verifier to your Hardhat config. Set `CONTRACT_ADDRESS` to the testnet deployment address.

```js
networks: {
  saiTestnet: {
    url: "https://evm-rpc.testnet-2.nibiru.fi",
    chainId: 6911,
  },
},
etherscan: {
  apiKey: { saiTestnet: process.env.SAI_EVM_VERIFY_API_KEY ?? "" },
  customChains: [{
    network: "saiTestnet",
    chainId: 6911,
    urls: {
      apiURL: "https://ops-api.sai.fun/public/evm/6911/api",
      browserURL: "https://ops-api.sai.fun/public/evm/6911",
    },
  }],
},
```

```bash
npx hardhat verify --network saiTestnet --contract contracts/Counter.sol:Counter "$CONTRACT_ADDRESS"
```

### Foundry

Add the testnet verifier to `foundry.toml` and use the testnet address for `CONTRACT_ADDRESS`.

```toml
[etherscan.sai_testnet]
chain = 6911
key = "${SAI_EVM_VERIFY_API_KEY}"
url = "https://ops-api.sai.fun/public/evm/6911/api"
browser_url = "https://ops-api.sai.fun/public/evm/6911"
```

```bash
forge verify-contract "$CONTRACT_ADDRESS" src/Counter.sol:Counter \
  --chain 6911 --rpc-url https://evm-rpc.testnet-2.nibiru.fi \
  --verifier etherscan --verifier-url https://ops-api.sai.fun/public/evm/6911/api \
  --watch
```
