Verifying Smart Contracts
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.
Using Developer Tools
Most smart contract tooling has plugins for verifying your contracts easily on Etherscan. Blockscout supports Etherscan’s contract verification APIs, so it’s straightforward to use these tools using the APIs of either of these block explorers.
Network | Scroll | Scroll Sepolia |
---|---|---|
Scrollscan | https://api.scrollscan.com/api | https://api-sepolia.scrollscan.com/api |
Blockscout | https://blockscout.scroll.io/api | https://sepolia-blockscout.scroll.io/api |
Hardhat
Modify hardhat.config.ts
to point to Scroll’s RPC and block explorer API. For Blockscout, a dummy apiKey
value is required, but anything works for its value. For Scrollscan, use your own API key.
For example, if you are using Scroll Sepolia on Blockscout, your config will look like this:
...
const config: HardhatUserConfig = {
...
networks: {
scrollSepolia: {
url: 'https://sepolia-rpc.scroll.io' || '',
accounts:
process.env.PRIVATE_KEY !== undefined ? [process.env.PRIVATE_KEY] : [],
},
},
etherscan: {
apiKey: {
scrollSepolia: 'abc',
},
customChains: [
{
network: 'scrollSepolia',
chainId: 534351,
urls: {
apiURL: 'https://sepolia-blockscout.scroll.io/api',
browserURL: 'https://sepolia-blockscout.scroll.io/',
},
},
],
},
}
...
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
Foundry
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.
Scrollscan
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>
Blockscout
Specify the verification provider as blockscout
.
Scroll
forge verify-contract <contract address> <contract name> \
--verifier-url https://blockscout.scroll.io/api\? \
--verifier blockscout \
--constructor-args <your constructor arguments>
Scroll Sepolia
forge verify-contract <contract address> <contract name> \
--verifier-url https://sepolia-blockscout.scroll.io/api\? \
--verifier blockscout \
--constructor-args <your constructor arguments>