Use Explorer to Verify Smart Contracts
There are multiple methods of verification available via Mantle Explorer.
Via Flattened Source Code
Get flattened source code
- Flatten Using Remix
- Flatten Using Hardhat
- Flatten Using Foundry
-
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.
If you're using Hardhat to flatten your contract, you can use the following command:
npx hardhat flatten contracts/Lock.sol > asLockFlatten.sol
You can copy the flattened contract code from the newly generated file.
If you're using Foundry to flatten your contract, you can use the following command:
forge flatten --output src/Storage.flattened.sol src/Storage.sol
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 compiler for your contract, the proper EVM version and the optimization number.
Via Standard Input JSON
Get JSON file
- Compiled Using Remix
- Compiled Using Hardhat
- Compiled Using Foundry
-
The file can be found under the "Solidity Compiler" tab that can be accessed by clicking on the left navigate bar.
-
Click on the Compilation Details button to bring up a menu from where you can copy the
COMPILERINPUT
code, as shown below.
-
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.
-
With Foundry, you'll need to run the following command to obtain the input and output information for your contract code.
forge build --build-info
Note:
If you get this response, please run
forge clean
and then rerun the command.[⠒] Compiling...No files changed, compilation skipped
[⠑] Compiling... -
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 into 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.