diff --git a/docs/02-developers/05-smart-contracts/04-verify-smart-contracts/rootstock-explorer.md b/docs/02-developers/05-smart-contracts/04-verify-smart-contracts/rootstock-explorer.md index 8cd5ade5..f69429df 100644 --- a/docs/02-developers/05-smart-contracts/04-verify-smart-contracts/rootstock-explorer.md +++ b/docs/02-developers/05-smart-contracts/04-verify-smart-contracts/rootstock-explorer.md @@ -8,7 +8,7 @@ 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. +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. :::tip[Tip] See [Rootstock Explorer guides](/dev-tools/explorers/rootstock-explorer/) to navigate the explorer and submit dApps. @@ -18,7 +18,7 @@ See [Rootstock Explorer guides](/dev-tools/explorers/rootstock-explorer/) to nav - **Builds trust**: - Verification allows anyone to see the source code of a deployed smart contract, which fosters trust with users and the community. -- **Increases transparency**: +- **Increases transparency**: - Users can audit the code to confirm it performs the actions it claims to, providing confidence in the contract's operations. - **Aids in security**: - By making the code public, it can be reviewed for vulnerabilities, though users should still conduct their own security assessments. @@ -28,12 +28,13 @@ See [Rootstock Explorer guides](/dev-tools/explorers/rootstock-explorer/) to nav - Verification allows users to interact with the contract on the Rootstock Explorer. - **Confirms code integrity**: - The verification process proves that the bytecode on the blockchain was generated from a specific, known source code, ensuring the contract hasn't been tampered with. -- **Helps with compliance**: +- **Helps with compliance**: - Verification is essential for meeting certain compliance and regulatory requirements. -## What does verification do?: +## What does verification do? + - Adds a Verified badge to the contract page, confirming that the published source code matches the deployed bytecode. -- Enables human-readable interaction with the contract — allowing users to view and call its functions directly. +- Enables human-readable interaction with the contract. It allows users to view and call its functions directly. - Allows downloading the contract's Application Binary Interface (ABI). ## Prerequisites @@ -46,9 +47,6 @@ See [Rootstock Explorer guides](/dev-tools/explorers/rootstock-explorer/) to nav - 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. - ## Getting Started - To start the verification process, visit the [Rootstock Explorer Testnet](https://explorer.testnet.rootstock.io/) or [Rootstock Explorer Mainnet](https://explorer.rootstock.io/), and find your contract using the search field. @@ -63,88 +61,107 @@ See [Rootstock Explorer guides](/dev-tools/explorers/rootstock-explorer/) to nav Rootstock Explorer offers 5 main methods for contract verification: -### 1. **Single File** +### 1. Single File + The Solidity (**Single File**) method is intended for verifying contracts that exist entirely within a single `.sol` file, or where the developer has already flattened all imports into one file. This method recompiles the provided contract and compares the resulting bytecode to the deployed contract on Rootstock. Follow the steps below to successfully complete the verification process. - Select Solidity **(Single File)** Method: -![single](/img/developers/smart-contracts/rsk-explorer/single.png) + ![single](/img/developers/smart-contracts/rsk-explorer/single.png) - **Solc Version**: Choose the Solc version you used to compile your contract. -![version](/img/developers/smart-contracts/rsk-explorer/solc-version.png) + ![version](/img/developers/smart-contracts/rsk-explorer/solc-version.png) - **EVM Version**: Choose the appropriate EVM version. -![evm](/img/developers/smart-contracts/rsk-explorer/evm.png) + ![evm](/img/developers/smart-contracts/rsk-explorer/evm.png) - **Optimization**: `Runs` tells the Solidity optimizer how many times your contract will be executed. You must use the same runs value in verification that you used when compiling. - 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. + - If you didn't use optimization, leave it disabled and don't enter any runs. ![runs](/img/developers/smart-contracts/rsk-explorer/runs.png) - **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) + ![name](/img/developers/smart-contracts/rsk-explorer/contract-name.png) - **Paste/Upload source code**: Provide the full Solidity source file. You may choose between: - - **Paste code**: Paste the raw contract source code into the field. This must be the exact source used during deployment. -![code](/img/developers/smart-contracts/rsk-explorer/code.png) + ![code](/img/developers/smart-contracts/rsk-explorer/code.png) - **Upload file**: Upload a `.sol` file directly from your computer. -![sol](/img/developers/smart-contracts/rsk-explorer/sol.png) + ![sol](/img/developers/smart-contracts/rsk-explorer/sol.png) -- **Constructor Arguments**: You must enter constructor arguments separate by comma if you have more than one. +- **Constructor Arguments**: You must enter constructor arguments separated by commas if you have more than one. + - Suppose your Solidity constructor looks like this: - - Suppose your Solidity constructor looks like this: - ```bash + ```solidity constructor(address owner, uint256 maxSupply) ``` + - To verify the contract, enter the arguments like this: - ```bash + + ```text 0xACa52b1Ab7dA04532127d22D47Dc3d34CFe0Cd5e,1000 ``` + Example: ![args](/img/developers/smart-contracts/rsk-explorer/args.png) - - - If you already have them in ABI-encoded format, enable the “ABI encoded” checkbox and paste the encoded string instead. + - If you already have them in ABI-encoded format, enable the "ABI encoded" checkbox and paste the encoded string instead. ![encoded](/img/developers/smart-contracts/rsk-explorer/encoded.png) - How to encode arguments: - - ABI-ENCODING with Ethers.js - ```bash + + ```ts import { AbiCoder } from "ethers"; const coder = AbiCoder.defaultAbiCoder(); const encoded = coder.encode( ["address", "uint256"], - ["0xaca52b1ab7da04532127d22d47dc3d34cfe0cd5e","1000"] + ["0xaca52b1ab7da04532127d22d47dc3d34cfe0cd5e", "1000"], ); - console.log(encoded); + console.log(encoded); ``` Result: - ```bash + + ```text 0x000000000000000000000000aca52b1ab7da04532127d22d47dc3d34cfe0cd5e00000000000000000000000000000000000000000000000000000000000003e8 ``` + - ABI-ENCODING from Remix: - - Open remix - Console - - Paste + - Open the Remix console + - Paste the following into the console: - ```bash + ```js web3.eth.abi.encodeParameters( ["address", "uint256"], - ["0xaca52b1ab7da04532127d22d47dc3d34cfe0cd5e", "1000"] - ) + ["0xaca52b1ab7da04532127d22d47dc3d34cfe0cd5e", "1000"], + ); ``` + Result: + + ```text + 0x000000000000000000000000aca52b1ab7da04532127d22d47dc3d34cfe0cd5e00000000000000000000000000000000000000000000000000000000000003e8 + ``` + + - ABI-ENCODING with Foundry (cast): + ```bash + cast abi-encode "constructor(address,uint256)" \ + 0xaca52b1ab7da04532127d22d47dc3d34cfe0cd5e 1000 + ``` + + Result: + + ```text 0x000000000000000000000000aca52b1ab7da04532127d22d47dc3d34cfe0cd5e00000000000000000000000000000000000000000000000000000000000003e8 ``` @@ -158,66 +175,69 @@ Follow the steps below to successfully complete the verification process. ![lib](/img/developers/smart-contracts/rsk-explorer/lib.png) -### **2. Multiple Files** +### 2. Multiple Files + The Solidity (**Multiple Files**) method is designed for more complex contracts that use imports, have multiple `.sol` files, or cannot be flattened safely. This method allows you to upload all your Solidity source files exactly as they exist in your project. Only the parts that differ from **Single File** are described below. -- **Sources Files**: Upload all Solidity files required to compile your contract, preserving the original folder structure. +- **Source Files**: Upload all Solidity files required to compile your contract, preserving the original folder structure. You can: - - Drag and drop multiple .sol files. - - Upload an entire folder containing your contracts. - - Combine both approaches if needed. + +- Drag and drop multiple .sol files. +- Upload an entire folder containing your contracts. +- Combine both approaches if needed. Important rules: - - Every imported file must be included. - - Filenames must match exactly (case-sensitive). - - Folder structure should reflect your project layout. - - Do not flatten the files — this method expects multi-file compilation. + +- Every imported file must be included. +- Filenames must match exactly (case-sensitive). +- Folder structure should reflect your project layout. +- Do not flatten the files. This method expects multi-file compilation. During verification, the explorer will reconstruct the compilation environment using the files you provide. ![multiple](/img/developers/smart-contracts/rsk-explorer/multiple.png) - **Other Settings**: -All other fields (compiler version, EVM version, optimization, contract name, constructor arguments, libraries.) work exactly the same as described in the **Single File** Verification section. + All other fields (compiler version, EVM version, optimization, contract name, constructor arguments, libraries) work exactly the same as described in the **Single File** section. + +### 3. Standard JSON -### 3. **JSON Standard** -The **Standard JSON** Input method is the most reliable and exact verification approach. It reproduces the full Solidity compiler configuration used during deployment by providing a complete standard-json object, exactly as consumed by solc --standard-json. +The **Standard JSON** Input method is the most reliable and exact verification approach. It reproduces the full Solidity compiler configuration used during deployment by providing a complete standard-json object, exactly as consumed by `solc --standard-json`. This method is strongly recommended for: - - Projects compiled with Hardhat, Foundry, Truffle, or custom build scripts. - - Contracts with complex dependency structures. - - Projects where preserving metadata (AST, settings, compiler options) is essential. - - Ensuring a byte-for-byte deterministic match with the deployed bytecode. -The Solidity (**Multiple Files**) method is designed for more complex contracts that use imports, have multiple `.sol` files, or cannot be flattened safely. This method allows you to upload all your Solidity source files exactly as they exist in your project. +- Projects compiled with Hardhat, Foundry, Truffle, or custom build scripts. +- Contracts with complex dependency structures. +- Projects where preserving metadata (AST, settings, compiler options) is essential. +- Ensuring a byte-for-byte deterministic match with the deployed bytecode. + +![json](/img/developers/smart-contracts/rsk-explorer/json.png) + +- **Other Settings**: All other fields (compiler version, optimization, contract name, constructor arguments, libraries) work exactly the same as described in the **Single File** section. -How to Generate Standard JSON Input: +**How to Generate Standard JSON Input** **Hardhat**: + ``` npx hardhat compile --show-stack-traces ``` -> Then locate the standard-json file inside Hardhat’s internal `artifacts/build-info/*.json`. -**Foundry**: -``` -forge build --extra-output-files solc-input -``` -> Foundry will export solc-input.json into `out/`. +Then locate the Hardhat build-info file under `artifacts/build-info/*.json`; this file contains the Standard JSON compiler input in its `input` field. - How to Extract the Standard JSON Input: - After generating the file (from Hardhat or Foundry): - - Open the JSON file that was produced. - - Inside it, locate the field named "input". - - Copy everything inside the input object — this is the actual Standard JSON Input expected by the verifier. - - Paste it into a new file, and save it using the contract's name. - - Your file should look similar to the following structure: + After generating the file from Hardhat: + - Open the JSON file that was produced. + - Inside it, locate the field named "input". + - Copy everything inside the input object. This is the actual Standard JSON Input expected by the verifier. + - Paste it into a new file, and save it using the contract's name. + - Your file should look similar to the following structure: -```bash +```json { "language": "Solidity", "sources": { @@ -238,9 +258,7 @@ forge build --extra-output-files solc-input }, "outputSelection": { "*": { - "": [ - "ast" - ], + "": ["ast"], "*": [ "abi", "metadata", @@ -262,38 +280,42 @@ forge build --extra-output-files solc-input } ``` -**Standard JSON Input File (*.json)** +**Foundry**: -Upload a single .json file containing the full Standard JSON Input object used to compile your contract. +``` +forge verify-contract \ + --chain-id 31 \ + --watch \ + --compiler-version \ + --show-standard-json-input \ + \ + : \ + > .json +``` -This file typically includes: - - language - - sources (all .sol files embedded with their contents) - - settings such as: - - optimizer configuration - - remappings - - metadata settings - - output selection - - evmVersion - - libraries (if linked during compilation) +Replace: -![json](/img/developers/smart-contracts/rsk-explorer/json.png) +- `` → the deployed contract address. +- `` → path to the Solidity file inside your project. +- `` → name of the contract inside that file. +- `` → the Solidity compiler version used to compile and deploy the contract (for example, `v0.8.28`). -- **Other Settings**: All other fields (compiler version, optimization, contract name, constructor arguments, libraries.) work exactly the same as described in the **Single File** Verification section. +> The `> .json` at the end of the command redirects the Standard JSON input output into a file in the current directory, which can then be uploaded as-is to the Rootstock Explorer verification tool. -### 4. **Hardhat Verification** +### 4. Hardhat Verification -Select Hardhat as your verification method to verify contracts directly from your Hardhat project. This method does not require uploading files through the interface — instead, verification is performed using the Hardhat CLI. +Select Hardhat as your verification method to verify contracts directly from your Hardhat project. This method does not require uploading files through the interface. Instead, verification is performed using the Hardhat CLI. ![hardhat](/img/developers/smart-contracts/rsk-explorer/hardhat.png) Copy the configuration snippet into your `hardhat.config.ts` file. This snippet includes: - - The Hardhat Verify plugin - - Rootstock Testnet/Mainnet RPC URLs - - Chain IDs - - Account setup for signing requests + +- The Hardhat Verify plugin +- Rootstock Testnet/Mainnet RPC URLs +- Chain IDs +- Account setup for signing requests Make sure your `PRIVATE_KEY` is defined in your `.env` file. @@ -305,19 +327,21 @@ npx hardhat verify \ \ [constructor-args] ``` + Replace: - - `` with your deployed contract address - - `[constructor-args]` with constructor parameters (if any) + +- `` with your deployed contract address +- `[constructor-args]` with constructor parameters (if any) > Once it completes successfully, your contract will be verified on the Rootstock Explorer. -To see a detailed explanation on how to verify contracts using Hardhat, visit [here](https://dev.rootstock.io/developers/smart-contracts/verify-smart-contracts/hardhat-verify-plugin/) +For a detailed walkthrough, see [Verify Smart Contracts using the Hardhat Verify Plugin](/developers/smart-contracts/verify-smart-contracts/hardhat-verify-plugin/). +### 5. Foundry Verification -### 5. **Foundry Verification** Select **Foundry** as your verification method to verify contracts using the forge verify-contract command. -This method integrates Foundry directly with the Rootstock Explorer’s verification API, allowing you to verify a deployed contract from your local environment. +This method integrates Foundry directly with the Rootstock Explorer's verification API, allowing you to verify a deployed contract from your local environment. Run the verification command in the terminal: @@ -325,22 +349,25 @@ Run the verification command in the terminal: forge verify-contract \ --chain-id 31 \ --watch \ - --compiler-version v0.8.24 \ + --compiler-version v0.8.28 \ --verifier custom \ - --verifier-url https://explorer-testnet-api-v3.plattie-qa.iovlabs.net/api/v3/etherscan \ + --verifier-url https://be.explorer.testnet.rootstock.io/api/v3/etherscan \ \ : ``` + Replace: - - `` → the deployed contract address. - - `` → path to the Solidity file inside your project. - - `` → name of the contract inside that file. - + +- `` → the deployed contract address. +- `` → path to the Solidity file inside your project. +- `` → name of the contract inside that file. + Once the command finishes, your contract will appear as Verified on the Rootstock Explorer. -To see a detailed explanation on how to verify contracts using Foundry, visit [here](https://dev.rootstock.io/developers/smart-contracts/foundry/verify-smart-contracts/) +For a detailed walkthrough, see [Verify Smart Contracts using Foundry](/developers/smart-contracts/foundry/verify-smart-contracts/). ## 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". @@ -357,10 +384,9 @@ Once you have entered all the details, click "Verify Contract". d. Contract read and write panels will be available. - **Read Methods**: - ![contract-interaction](/img/developers/smart-contracts/rsk-explorer/contract-interaction.png) + ![contract-interaction](/img/developers/smart-contracts/rsk-explorer/contract-interaction.png) - **Write Methods**: - ![write](/img/developers/smart-contracts/rsk-explorer/write.png) - + ![write](/img/developers/smart-contracts/rsk-explorer/write.png) ## Troubleshooting @@ -408,7 +434,10 @@ Once you have entered all the details, click "Verify Contract". -> 💡 **Tip:** If verification keeps failing, try matching the compiler settings directly from your Hardhat or Foundry build artifacts. +:::tip[Tip] +If verification keeps failing, try matching the compiler settings directly from your Hardhat or Foundry build artifacts. +::: ## Resources + - Verify smart contracts using [Blockscout](foundry-blockscout.md) or [Hardhat Plugin](hardhat-verify-plugin.md)