> For the complete documentation index, see [llms.txt](https://thehemera.gitbook.io/explorer-api/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://thehemera.gitbook.io/explorer-api/verify-smart-contract/verify-smart-contract/verify-through-foundry.md).

# Verify through Foundry

SocialScan supports verifying smart contracts through Foundry, please refer to <https://book.getfoundry.sh/reference/forge/forge-verify-contract> for more information.

You must include the following args

<table data-header-hidden><thead><tr><th width="208">key</th><th>value</th></tr></thead><tbody><tr><td>contract_address</td><td>Your contract address to verify</td></tr><tr><td>contract_name</td><td>Your contract name to verify</td></tr><tr><td>compiler_version</td><td>Compiler version, e.g. v0.8.25+commit.b61c2a91</td></tr><tr><td>chain</td><td>Put your chain id (Not required)</td></tr><tr><td>verifier-url</td><td><p>&#x3C;api_host><a href="http://localhost:8080/v1/explorer/command_api/contract/0x8F72840bE9414436dA8A76fF08a1f6924f0efb83">/v1/explorer/command_api/contract</a></p><p>API Host: <a href="https://api.socialscan.io/story-testnet">https://api.socialscan.io/</a>&#x3C;chain_name>/</p></td></tr><tr><td>verifier</td><td>Use "blockscout" or "etherscan"</td></tr><tr><td>etherscan-api-key</td><td>If you use "etherscan" as a verifier, you need to put a random string here</td></tr></tbody></table>

## Example

```
# Compile your smart contract first
forge build

# Verify a flattened contract 
forge verify-contract <contract_address> <contract_name> \
--compiler-version <compiler_version> \
--flatten \
--verifier-url <api_host>/v1/explorer/command_api/contract \
--verifier blockscout

# Verify a contract with JSON standard input
forge verify-contract \
<contract_address> <contract_name> \
--watch \
--compiler-version <compiler_version> \
--constructor-args $(cast abi-encode "constructor(string,string)" "TEST" "ST2") \
--verifier-url <api_host>/v1/explorer/command_api/contract \
--verifier blockscout

# Verify a contract use "etherscan" verifier
forge verify-contract \
<contract_address> <contract_name> \
--chain <chain_id> \
--watch --etherscan-api-key test \
--verifier-url <api_host>/v1/explorer/command_api/contract \
--verifier etherscan

# Expected output
Start verifying contract `<contract_address>` deployed on <chain_name>

Submitting verification for [<contract_name>] <contract_address>.
Submitted contract for verification:
        Response: `Contract successfully verified`
        GUID: `a40a619266ea0d581e6373c52754e4a4ef6333bc8581b9d2a02d6174b3316f39`
        URL: <explorer_host>/address/<contract_address>
Contract verification status:
Response: `OK`
Details: `Pass - Verified`
Contract successfully verified
```

## Deploying 2048 Game Contract on Monad Testnet with Foundry

This guide walks you through deploying and verifying a 2048 game smart contract on the Monad testnet using Foundry.

### Prerequisites

Before starting, ensure you have:

* [Foundry](https://book.getfoundry.sh/getting-started/installation) installed
* A wallet with Monad testnet coin
* Your private key
* Git installed on your system

### Step 1: Clone the Repository

```bash
git clone https://github.com/monad-developers/2048-contracts.git
cd 2048-contracts
```

### Step 2: Build the Contract

Compile the smart contract using Foundry's forge tool:

```bash
forge build --contracts src/Monad2048.sol
```

Expected output:

```bash
Updating dependencies in /Users/lixiang/2048-contracts/lib
Submodule 'lib/forge-std' (https://github.com/foundry-rs/forge-std) registered for path 'lib/forge-std'
Submodule 'lib/solady' (https://github.com/Vectorized/solady) registered for path 'lib/solady'
Cloning into '/Users/lixiang/2048-contracts/lib/forge-std'...
remote: Enumerating objects: 2126, done.
remote: Counting objects: 100% (1008/1008), done.
remote: Compressing objects: 100% (131/131), done.
remote: Total 2126 (delta 932), reused 879 (delta 877), pack-reused 1118 (from 2)
Receiving objects: 100% (2126/2126), 720.75 KiB | 1.00 MiB/s, done.
Resolving deltas: 100% (1431/1431), done.
Cloning into '/Users/lixiang/2048-contracts/lib/solady'...
remote: Enumerating objects: 10811, done.
remote: Counting objects: 100% (3463/3463), done.
remote: Compressing objects: 100% (685/685), done.
remote: Total 10811 (delta 3107), reused 2793 (delta 2778), pack-reused 7348 (from 4)
Receiving objects: 100% (10811/10811), 7.11 MiB | 1.41 MiB/s, done.
Resolving deltas: 100% (7680/7680), done.
[⠊] Compiling...
[⠔] Compiling 24 files with Solc 0.8.28
[⠒] Solc 0.8.28 finished in 3.62s
```

### Step 3: Deploy the Contract

Deploy the compiled contract to Monad testnet:

```bash
forge script script/Deploy.s.sol:Deploy \
 --rpc-url https://testnet-rpc.monad.xyz \
 --broadcast \
 --private-key ${PRIVATE_KEY}
```

Expected output:

```
[⠊] Compiling...
No files changed, compilation skipped
Script ran successfully.

== Return ==
gameContract: address {address}

## Setting up 1 EVM.

==========================

Chain 10143

Estimated gas price: 100.000000001 gwei

Estimated total gas used for script: 857808

Estimated amount required: 0.085780800000857808 MON

==========================

##### monad-testnet
✅  [Success] Hash: {transaction_hash}
Contract Address: {contract_address}
Block: 22000095
Paid: 0.042890400000857808 MON (857808 gas * 50.000000001 gwei)

✅ Sequence #1 on monad-testnet | Total Paid: 0.042890400000857808 MON (857808 gas * avg 50.000000001 gwei
```

### Step 4: Verify the Contract

Verify your deployed contract on the Monad block explorer:

```bash
forge verify-contract \
{contract_address} \
src/Monad2048.sol:Monad2048 \
--chain 10143 \
--verifier blockscout \
--verifier-url https://api.socialscan.io/monad-testnet/v1/explorer/command_api/contract
```

Command breakdown:

* `forge verify-contract`: Foundry's contract verification command
* `contract_address`:  Your deployed contract address
* `src/Monad2048.sol:Monad2048`: Path to source file and contract name
* `--chain 10143`: Monad testnet chain ID
* `--verifier blockscout`: Use Blockscout as the verification service
* `--verifier-url`: API endpoint for Monad testnet verification

Expected output:

```
Start verifying contract `0x15cd4b493fC9d58C7f3Be47693c99d51C93467B7` deployed on monad-testnet

Submitting verification for [src/Monad2048.sol:Monad2048] 0x15cd4b493fC9d58C7f3Be47693c99d51C93467B7.
Submitted contract for verification:
	Response: `Contract successfully verified`
	GUID: `xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx`
	URL: https://api.socialscan.io/monad-testnet/v1/explorer/command_api/address/0x15cd4b493fc9d58c7f3be47693c99d51c93467b7
```

### **Verification Result**

<https://monad-testnet.socialscan.io/address/0x15cd4b493fc9d58c7f3be47693c99d51c93467b7#contract>

<figure><img src="/files/8rmFvYf7qiKCtMYC3z9w" alt=""><figcaption></figcaption></figure>
