|
| 1 | +// SPDX-FileCopyrightText: 2024-2025 IEXEC BLOCKCHAIN TECH <[email protected]> |
| 2 | +// SPDX-License-Identifier: Apache-2.0 |
| 3 | + |
| 4 | +import fs from 'fs'; |
| 5 | +import hre, { deployments } from 'hardhat'; |
| 6 | +import path from 'path'; |
| 7 | + |
| 8 | +(async () => { |
| 9 | + const jsonExtension = '.json'; |
| 10 | + const contractNames = fs |
| 11 | + .readdirSync(path.resolve(__dirname, `../deployments/${hre.network.name}`)) |
| 12 | + .filter((file) => file.endsWith(jsonExtension)) |
| 13 | + .map((filePath) => filePath.replace(jsonExtension, '')); |
| 14 | + |
| 15 | + console.log(`Contracts to verify: ${contractNames}`); |
| 16 | + |
| 17 | + for (const contractName of contractNames) { |
| 18 | + try { |
| 19 | + console.log(`Verifying ${contractName}..`); |
| 20 | + const deployment = await deployments.get(contractName); |
| 21 | + const address = deployment.address; |
| 22 | + const constructorArguments = deployment.args || []; |
| 23 | + await hre.run('verify:verify', { |
| 24 | + address, |
| 25 | + constructorArguments, |
| 26 | + }); |
| 27 | + |
| 28 | + console.log(`${contractName} verified successfully`); |
| 29 | + } catch (error: any) { |
| 30 | + console.error(`Error verifying ${contractName}:`, error.message || error); |
| 31 | + if ( |
| 32 | + typeof error.message === 'string' && |
| 33 | + error.message.includes('has') && |
| 34 | + error.message.includes('parameters but') && |
| 35 | + error.message.includes('arguments were provided') |
| 36 | + ) { |
| 37 | + console.error( |
| 38 | + `${contractName} requires constructor arguments. Please add them to the deployment artifact.`, |
| 39 | + ); |
| 40 | + } |
| 41 | + } |
| 42 | + } |
| 43 | +})(); |
0 commit comments