Verifying Smart Contracts On This Page After deploying your smart contracts, it’s important to verify your code on a block explorer. This can be done in an automated way using your developer tooling or the Web UI.
Most smart contract tooling has plugins for verifying your contracts easily on Etherscan.
Using the Scrollscan API
When using Scrollscan, you will need to register an account and create an API key. The same key can be used for both Scroll Sepolia and mainnet. After creating your API key, please wait a few minutes before it comes into effect.
Modify hardhat.config.ts
to point to Scroll’s RPC and block explorer API.
For example, the config for Scroll Sepolia will look like this:
const config : HardhatUserConfig = {
url: 'https://sepolia-rpc.scroll.io' || '' ,
process . env . PRIVATE_KEY !== undefined ? [ process . env . PRIVATE_KEY ] : [],
scrollSepolia: < YOUR API KEY > ,
network : 'scrollSepolia' ,
apiURL: 'https://api-sepolia.scrollscan.com/api' ,
browserURL: 'https://sepolia.scrollscan.com/' ,
Now you can verify the smart contract by running the following command.
npx hardhat verify --network scrollSepolia < contract address > <space separated constructor parameters>
For example, this is how a smart contract that receives two uint parameters in the constructor should look:
npx hardhat verify --network scrollSepolia 0xD9880690bd717189cC3Fbe7B9020F27fae7Ac76F 123 456
Warning
You may receive an error stating etherscan.apiKey.trim is not a function
. If so, you need to update
@nomiclabs/hardhat-etherscan
to be able to support custom chains. Try running npm update @nomiclabs/hardhat-etherscan
When using Foundry, the verify-contract
command helps automate the process of verifying contracts. If your contract has constructor arguments, you can specify these in ABI-encoded form with the --constructor-args
option. For example, if your constructor takes two uint256
variables:
--constructor-args $( cast abi-encode "constructor(uint256,uint256)" 0 7 )
Refer to the Foundry documentation for further options you can specify.
forge verify-contract <contract address> <contract name> \
--verifier-url https://api-sepolia.scrollscan.com/api \
--etherscan-api-key <your Scrollscan API key> \
--constructor-args <your constructor arguments>
Caution
Do not specify the chain ID.
More