# Blockscout Contract Verification Guide - ChainID 138

**Date**: $(date)  
**Purpose**: Guide for verifying smart contracts on ChainID 138 using Blockscout  
**Block Explorer**: `https://explorer.d-bis.org`

---

## Overview

ChainID 138 uses **Blockscout** (self-hosted) as its block explorer. This guide covers how to verify smart contracts deployed on ChainID 138 using Foundry's verification tools.

---

## Prerequisites

1. **Foundry** installed and configured
2. **Deployed contracts** on ChainID 138
3. **Access to contract source code** and constructor arguments
4. **Blockscout instance** accessible at `https://explorer.d-bis.org`

---

## Blockscout Configuration

### Block Explorer Information

- **URL**: `https://explorer.d-bis.org`
- **API Endpoint**: `https://explorer.d-bis.org/api`
- **Type**: Self-hosted Blockscout
- **Chain ID**: 138
- **API Key**: Not required (self-hosted instance)

---

## Verification Methods

### Method 1: Using Foundry Script with Verification

When deploying contracts with Foundry, add Blockscout verification flags:

```bash
forge script script/YourDeploymentScript.s.sol:YourScript \
  --rpc-url https://rpc-core.d-bis.org \
  --private-key $PRIVATE_KEY \
  --broadcast \
  --verify \
  --verifier blockscout \
  --verifier-url https://explorer.d-bis.org/api \
  -vvvv
```

### Method 2: Manual Verification with `forge verify-contract`

After deployment, verify contracts manually:

```bash
forge verify-contract \
  <CONTRACT_ADDRESS> \
  <CONTRACT_NAME> \
  --chain-id 138 \
  --rpc-url https://rpc-core.d-bis.org \
  --verifier blockscout \
  --verifier-url https://explorer.d-bis.org/api \
  --constructor-args $(cast abi-encode "constructor(<ARGS>)" <ARG1> <ARG2> ...) \
  --compiler-version <VERSION>
```

### Method 3: Using Foundry.toml Configuration

Add Blockscout configuration to `foundry.toml`:

```toml
[etherscan]
chain138 = { 
  url = "https://explorer.d-bis.org/api",
  verifier = "blockscout"
}
```

Then use:

```bash
forge verify-contract \
  <CONTRACT_ADDRESS> \
  <CONTRACT_NAME> \
  --chain chain138 \
  --rpc-url https://rpc-core.d-bis.org
```

---

## Verification Examples

### Example 1: Simple Contract (No Constructor Arguments)

```bash
forge verify-contract \
  0x1234567890123456789012345678901234567890 \
  SimpleContract \
  --chain-id 138 \
  --rpc-url https://rpc-core.d-bis.org \
  --verifier blockscout \
  --verifier-url https://explorer.d-bis.org/api \
  --compiler-version 0.8.20
```

### Example 2: Contract with Constructor Arguments

```bash
# First, encode constructor arguments
CONSTRUCTOR_ARGS=$(cast abi-encode "constructor(address,uint256)" \
  0x1111111111111111111111111111111111111111 \
  1000000000000000000)

# Then verify
forge verify-contract \
  0x1234567890123456789012345678901234567890 \
  ComplexContract \
  --chain-id 138 \
  --rpc-url https://rpc-core.d-bis.org \
  --verifier blockscout \
  --verifier-url https://explorer.d-bis.org/api \
  --constructor-args "$CONSTRUCTOR_ARGS" \
  --compiler-version 0.8.20
```

### Example 3: Verify with Libraries

If your contract uses libraries, specify them:

```bash
forge verify-contract \
  <CONTRACT_ADDRESS> \
  <CONTRACT_NAME> \
  --chain-id 138 \
  --rpc-url https://rpc-core.d-bis.org \
  --verifier blockscout \
  --verifier-url https://explorer.d-bis.org/api \
  --libraries <LIBRARY_NAME>:<LIBRARY_ADDRESS> \
  --compiler-version <VERSION>
```

---

## Troubleshooting

### Issue: Verification Fails with "Contract Not Found"

**Solution**: 
- Ensure the contract is deployed and confirmed on ChainID 138
- Verify the contract address is correct
- Check that the RPC endpoint is accessible

### Issue: "Invalid Source Code"

**Solution**:
- Ensure compiler version matches the deployment compiler version
- Verify all source files are accessible
- Check that constructor arguments are correctly encoded

### Issue: "Already Verified"

**Solution**:
- The contract is already verified on Blockscout
- Check the contract on the explorer: `https://explorer.d-bis.org/address/<CONTRACT_ADDRESS>`

### Issue: Blockscout API Timeout

**Solution**:
- Check if Blockscout instance is running and accessible
- Verify network connectivity to `https://explorer.d-bis.org`
- Try again after a few moments (Blockscout may be indexing)

---

## Manual Verification via Blockscout UI

If automated verification fails, you can verify contracts manually through the Blockscout web interface:

1. Navigate to the contract address: `https://explorer.d-bis.org/address/<CONTRACT_ADDRESS>`
2. Click on **"Verify & Publish"** tab
3. Select verification method:
   - **Via Standard JSON Input** (recommended)
   - **Via Sourcify**
   - **Via Multi-file**
4. Upload contract source code and metadata
5. Provide constructor arguments (if any)
6. Submit for verification

---

## Verification Best Practices

1. **Verify Immediately After Deployment**: Verify contracts right after deployment while deployment details are fresh
2. **Use Standard JSON Input**: Most reliable method for complex contracts
3. **Document Constructor Arguments**: Keep a record of constructor arguments used during deployment
4. **Test Verification Locally**: Test your verification command before deploying to production
5. **Keep Source Code Organized**: Maintain clean source code structure for easier verification

---

## Related Documentation

- **Block Explorer**: `https://explorer.d-bis.org`
- **RPC Endpoint**: `https://rpc-core.d-bis.org`
- **API Keys Documentation**: See `docs/CROSS_CHAIN_BRIDGE_ADDRESSES.md`
- **Contract Deployment Guide**: See `docs/CONTRACT_DEPLOYMENT_GUIDE.md`

---

## Quick Reference

### Blockscout API Endpoints

- **API Base URL**: `https://explorer.d-bis.org/api`
- **Contract Verification**: `POST /api/v2/smart-contracts/<ADDRESS>/verification`
- **Contract Info**: `GET /api/v2/smart-contracts/<ADDRESS>`

### Common Verification Flags

```bash
--verifier blockscout                    # Use Blockscout verifier
--verifier-url https://explorer.d-bis.org/api  # Blockscout API URL
--chain-id 138                           # Chain ID 138
--compiler-version 0.8.20                # Solidity compiler version
--constructor-args <ENCODED_ARGS>        # Encoded constructor arguments
--libraries <LIB>:<ADDR>                 # Library addresses
```

---

**Last Updated**: $(date)  
**Status**: ✅ Ready for use with ChainID 138

