Verifying Contracts
Different ways to verify your contracts on Mantle Network
Verifying a contract means making its source code public, along with the compiler settings you used, which allows anyone to compile it and compare the generated bytecode with the one that is deployed on-chain.
Using Hardhat
To verify your contracts using Hardhat, you'll need an Etherscan API key and custom network configuration in your hardhat.config.ts
file. Feel free to refer to the configuration from Mantle Hardhat Starter Kit.
You'll need to modify the hardhat.config.ts
configuration to include customChains
before moving forward.
Run the following command to verify the contract located in the "contracts" directory:
Here's a sample request and the command line output it produces:
If you see an error that says "Hardhat found multiple contracts in the project...", see the fix on the troubleshooting page.
Using Foundry
Use the following forge
command to verify the contract you've deployed on Mantle Testnet:
Using Remix IDE
Select the "Injected Provider - MetaMask" environment to connect to Mantle Testnet under the "Deploy and Run Transactions" tab
Obtaining Constructor Parameters
Consider the following sample contract code:
In order to obtain the hex encoded constructor parameters, first you'll need to compile your code. Then, navigate to the "Deploy and Run Transactions" tab, enter the string parameter in the field next to the "Deploy" button, and then bring up the drop-down menu.
Using Explorer
There are multiple methods of verification available via Mantle Explorer.
Let's go over the steps involved in using the most popular methods.
Via Flattened Source Code
You can use Remix, or any other tool, to flatten your contract code.
Flatten Using Remix
In Remix, right click on the contract file and click on "Flatten".
Flattening a contract with imports will generate a new Solidity file with the flattened code that you can copy, as shown below.
Flatten Using Hardhat
If you're using Hardhat to flatten your contract, you can use the following command:
You can copy the flattened contract code from the newly generated file.
Flatten Using Foundry
If you're using Foundry to flatten your contract, you can use the following command:
You can copy the flattened contract code from the newly generated file.
Plugging Flattened Code Into Explorer
Once you have obtained the flattened code, fill in the contract address, contract name, the flattened code, and other fields on Mantle Explorer and proceed with verifying your contract.
Make sure to select the correct EVM version
Via Standard Input JSON
You can obtain the standard input JSON file by compiling your contract using any of the tools we've used so far. Let's see where the input value code can be found in each case.
Compiled Using Remix
You can paste and save the copied JSON code in a separate file that can later be imported to the Explorer.
Compiled Using Hardhat
Once you've successfully compiled your contract code, you'll be able to find a JSON file (with a long name in hexadecimal) in the "../artifacts/build-info" directory, as shown below.
Within this JSON file, you'll need to copy the input
field, as shown below, and then paste the copied code into a new empty JSON file. You can import this file to the Explorer later.
Compiled Using Foundry
With Foundry, you'll need to run the following command to obtain the input and output information for your contract code.
You'll then be able to find a JSON file (with a long name in hexadecimal) in the "../out/build-info" directory, as shown below. Copy the input
field and paste it in a new empty JSON file, which you can then import to the Explorer.
Importing JSON File to Explorer
Once you've obtained the standard input JSON values in a file, you can import it to the Explorer, as shown below.
Last updated