Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
---
sidebar_label: Verify a Smart Contract using the Rootstock Explorer
sidebar_position: 107
title: Verify a Smart Contract using the Rootstock Explorer
description: "How to Verify a Smart Contract on the Rootstock Explore"
tags: [Explorer, tutorial, developers, quick starts, rsk, rootstock]
---

Contract verification is essential in the Rootstock ecosystem. It allows Rootstock Explorer users to inspect and validate the source code of deployed smart contracts.

The Rootstock Explorer provides a transparent view of the Rootstock blockchain, showing transactions, blocks, and deployed contracts. This transparency, enabled by verification, builds trust and understanding in decentralized applications.

## What does verification do?:
- Provides a `Verified` badge on the contract page, indicating that the source code corresponds to the deployed bytecode.
- Allows readable reading and writing of contract functions.
- Allows downloading the contract's Application Binary Interface (ABI).

## Prerequisites

- Address of the deployed contract on Rootstock.
- Complete source code of the contract.
- Compiler details:
- Solc (Solidity Compiler) version.
- Number of optimization runs.
- Constructor parameters (if applicable).
- Library addresses (if used).


> In summary, this guide will help you verify your smart contract, allowing you to leverage these benefits and contribute to a more transparent and trustworthy decentralized environment on Rootstock.

## Visit the Rootstock Explorer

- To start the verification process go to the Rootstock Explorer [Testnet](https://explorer.testnet.rootstock.io/) or [Mainnet](https://explorer.rootstock.io/), find your contract using the search field.

![init](/img/developers/smart-contracts/rsk-explorer/init.png)

- Once you reach your contract's address view, navigate to the "Contract" tab and click the "Verify Contract" button.

![verify](/img/developers/smart-contracts/rsk-explorer/verify-btn.png)

# Choosing Verification Method

Rootstock Explorer offers two main methods for contract verification:

- **Single File (Flattened)**: For simple contracts contained in a single file, where all imports have been "flattened" into a single file.
- **Multiple Files / Standard JSON** (Hardhat/Foundry/Truffle): For more complex projects with multiple files or those generated by development frameworks like Hardhat, Foundry.

![verify](/img/developers/smart-contracts/rsk-explorer/methods.png)

| **Verification Method** | **When to Prefer** | **Pros** | **Cons** |
|---------------------------|--------------------|-----------|-----------|
| **Single File (Flattened)** | Small contracts, without complex imports or libraries. | Simple and fast for straightforward contracts. | Can be tedious to flatten large contracts or those with many dependencies. |
| **Multiple Files / Standard JSON** | Large projects, with dependencies, libraries, or generated by development frameworks. | Automatically handles imports and dependencies. | Requires exporting the Standard JSON file from your development environment. |


## Compiler Configuration

It is crucial that the compiler configuration in the explorer exactly matches that used during the compilation of your contract.

- **Select Solc version**: Choose the Solc version you used to compile your contract.

![solc](/img/developers/smart-contracts/rsk-explorer/solc-version.png)

- **Optimization**:
- If you used optimization run when compiling/deploying, enable it during verification and set the same runs (default 200).
- If you didn’t use optimization, leave it disabled and don’t enter any runs.

![runs](/img/developers/smart-contracts/rsk-explorer/runs.png)

- **EVM Version**: Choose the appropriate EVM version.

![evm](/img/developers/smart-contracts/rsk-explorer/evm.png)

## Source Code Input

Provide your contract's source code.

- **Contract Name**:
- Enter the exact name of the contract you deployed. This is required so the verifier can match the correct bytecode.
![name](/img/developers/smart-contracts/rsk-explorer/contract-name.png)

- **Paste/Upload source code**:
- Single File: upload the .sol file.
![sol](/img/developers/smart-contracts/rsk-explorer/sol.png)
- Standard JSON: Upload the standard-json file generated by your development framework.
![json](/img/developers/smart-contracts/rsk-explorer/json.png)

- **Constructor Arguments**: You must enter constructor arguments separate by comma if you have more than one.
![args](/img/developers/smart-contracts/rsk-explorer/args.png)

- **Libraries**:
- If your contract uses libraries, provide their names and deployed addresses.
![lib](/img/developers/smart-contracts/rsk-explorer/lib.png)

## Submit and Validate
Once you have entered all the details, click "Verify Contract".

- **Expected statuses**: The verification status will change from "Pending" to "Success" or "Failure".
- **In case of success**:

a. You will see the `Verified` badge on the contract page.
![verified](/img/developers/smart-contracts/rsk-explorer/verified.png)

b. Source code tabs will be visible.
![tabs](/img/developers/smart-contracts/rsk-explorer/tabs.png)

c. You will be able to download the contract ABI.
![abi](/img/developers/smart-contracts/rsk-explorer/abi.png)

d. Contract read and write panels will be available.
- **Read Methods**:
![contract-interaction](/img/developers/smart-contracts/rsk-explorer/contract-interaction.png)
- **Write Methods**:
![write](/img/developers/smart-contracts/rsk-explorer/write.png)


## Troubleshooting

Here are some common problems and their solutions:

- **Compiler version mismatch**:
- Confirm the exact **Solc version** used to compile your contract.
- Retrieve the version from your compilation artifacts.

- **Invalid constructor arguments**:
- Verify the precise **encoding**, **order**, and **types** of your constructor arguments.

- **Library not found / address mismatch**:
- Ensure **library names** match bytecode placeholders.
- Add the correct **deployed addresses** for each library.

- **Optimization runs differ**:
- Align the number of **optimization runs** with your compilation settings.

- **Flattening / import issues**:
- Consider using the **Standard JSON** verification method to avoid path or flattening issues.

- **Proxy and Implementation**:
- Verify the **implementation contract**.
- Note any **proxy-aware UI** (if available) and how to link it.

> 💡 **Tip:** If verification keeps failing, try matching the compiler settings directly from your Hardhat or Foundry build artifacts.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.