Skip to content

Commit 042457c

Browse files
committed
Configure verification APIs using default-apis.json
1 parent 17ddb3c commit 042457c

File tree

4 files changed

+58
-48
lines changed

4 files changed

+58
-48
lines changed

apps/contract-verification/src/app/ContractVerificationPluginClient.ts

Lines changed: 26 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export class ContractVerificationPluginClient extends PluginClient {
1212

1313
constructor() {
1414
super()
15-
this.methods = ['lookupAndSave', 'verifyOnDeploy']
15+
this.methods = ['lookupAndSave', 'verifyOnDeploy', 'isVerificationSupportedForChain']
1616
this.internalEvents = new EventManager()
1717
createClient(this)
1818
this.onload()
@@ -120,24 +120,15 @@ export class ContractVerificationPluginClient extends PluginClient {
120120
const chainSettings = mergeChainSettingsWithDefaults(chainId, userSettings)
121121

122122
const verificationPromises = []
123+
const verifiers: VerifierIdentifier[] = ['Sourcify', 'Etherscan', 'Blockscout', 'Routescan']
123124

124-
if (validConfiguration(chainSettings, 'Sourcify')) {
125-
verificationPromises.push(this._verifyWithProvider('Sourcify', submittedContract, compilerAbstract, chainId, chainSettings))
126-
}
127-
128-
if (currentChain.explorers && currentChain.explorers.some(explorer => explorer.name.toLowerCase().includes('routescan'))) {
129-
verificationPromises.push(this._verifyWithProvider('Routescan', submittedContract, compilerAbstract, chainId, chainSettings))
130-
}
131-
132-
if (currentChain.explorers && currentChain.explorers.some(explorer => explorer.url.includes('blockscout'))) {
133-
verificationPromises.push(this._verifyWithProvider('Blockscout', submittedContract, compilerAbstract, chainId, chainSettings))
134-
}
135-
136-
if (currentChain.explorers && currentChain.explorers.some(explorer => explorer.name.includes('etherscan'))) {
137-
if (etherscanApiKey) {
138-
verificationPromises.push(this._verifyWithProvider('Etherscan', submittedContract, compilerAbstract, chainId, chainSettings))
139-
} else {
140-
await this.call('terminal', 'log', { type: 'warn', value: 'Etherscan verification skipped: API key not found in global Settings.' })
125+
for (const verifier of verifiers) {
126+
if (validConfiguration(chainSettings, verifier)) {
127+
if (verifier === 'Etherscan' && !etherscanApiKey) {
128+
this.call('terminal', 'log', { type: 'warn', value: 'Etherscan verification skipped: API key not provided for auto-verification.' })
129+
continue
130+
}
131+
verificationPromises.push(this._verifyWithProvider(verifier, submittedContract, compilerAbstract, chainId, chainSettings))
141132
}
142133
}
143134

@@ -152,6 +143,23 @@ export class ContractVerificationPluginClient extends PluginClient {
152143
}
153144
}
154145

146+
async isVerificationSupportedForChain(chainId: string): Promise<boolean> {
147+
try {
148+
const userSettings = this.getUserSettingsFromLocalStorage()
149+
const chainSettings = mergeChainSettingsWithDefaults(chainId, userSettings)
150+
151+
for (const verifierId of VERIFIERS) {
152+
if (validConfiguration(chainSettings, verifierId as VerifierIdentifier)) {
153+
return true
154+
}
155+
}
156+
return false
157+
} catch (e) {
158+
console.error(e)
159+
return false
160+
}
161+
}
162+
155163
private _verifyWithProvider = async (
156164
providerName: VerifierIdentifier,
157165
submittedContract: SubmittedContract,

apps/contract-verification/src/app/utils/default-apis.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@
5151
"1101": {
5252
"explorerUrl": "https://zkevm.polygonscan.com"
5353
},
54+
"59141": {
55+
"explorerUrl": "https://sepolia.lineascan.build"
56+
},
5457
"59144": {
5558
"explorerUrl": "https://lineascan.build"
5659
},

libs/remix-ui/run-tab/src/lib/actions/deploy.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ export const createInstance = async (
191191
const currentChain = allChains.find(chain => chain.chainId === currentChainId)
192192

193193
if (!currentChain) {
194-
const errorMsg = `The current network (Chain ID: ${currentChainId}) is not supported for verification via this plugin. Please switch to a supported network like Sepolia or Mainnet.`
194+
const errorMsg = `Could not find chain data for Chain ID: ${currentChainId}. Verification cannot proceed.`
195195
const errorLog = logBuilder(errorMsg)
196196
terminalLogger(plugin, errorLog)
197197
return

libs/remix-ui/run-tab/src/lib/components/contractDropdownUI.tsx

Lines changed: 28 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -49,21 +49,37 @@ export function ContractDropdownUI(props: ContractDropdownProps) {
4949

5050
useEffect(() => {
5151
const checkSupport = async () => {
52-
if (props.plugin) {
53-
const supportedChain = await getSupportedChain(props.plugin)
54-
const isSupported = !!supportedChain
55-
setNetworkSupported(isSupported)
56-
57-
if (isSupported) {
58-
const saved = window.localStorage.getItem('deploy-verify-contract-checked')
59-
setVerifyChecked(saved !== null ? JSON.parse(saved) : true)
60-
} else {
61-
setVerifyChecked(false)
52+
if (props.plugin && props.networkName) {
53+
try {
54+
const status = props.plugin.blockchain.getCurrentNetworkStatus()
55+
if (status.error || !status.network) {
56+
setNetworkSupported(false)
57+
return
58+
}
59+
const currentChainId = status.network.id.toString()
60+
61+
const isSupported = await props.plugin.call(
62+
'contract-verification',
63+
'isVerificationSupportedForChain',
64+
currentChainId
65+
)
66+
67+
setNetworkSupported(isSupported)
68+
69+
if (isSupported) {
70+
const saved = window.localStorage.getItem('deploy-verify-contract-checked')
71+
setVerifyChecked(saved !== null ? JSON.parse(saved) : true)
72+
} else {
73+
setVerifyChecked(false)
74+
}
75+
} catch (e) {
76+
console.error("Failed to check verification support:", e)
77+
setNetworkSupported(false)
6278
}
6379
}
64-
};
80+
}
6581
checkSupport()
66-
}, [props.networkName])
82+
}, [props.networkName, props.plugin])
6783

6884
useEffect(() => {
6985
enableContractNames(Object.keys(props.contracts.contractList).length > 0)
@@ -337,23 +353,6 @@ export function ContractDropdownUI(props: ContractDropdownProps) {
337353
return props.isValidProxyUpgrade(proxyAddress, loadedContractData.contractName || loadedContractData.name, loadedContractData.compiler.source, loadedContractData.compiler.data, solcVersion)
338354
}
339355

340-
const getSupportedChain = async (plugin: any): Promise<any> => {
341-
try {
342-
const response = await fetch('https://chainid.network/chains.json')
343-
if (!response.ok) return null
344-
const allChains = await response.json()
345-
346-
const status = plugin.blockchain.getCurrentNetworkStatus()
347-
if (status.error || !status.network) return null
348-
349-
const currentChainId = parseInt(status.network.id)
350-
return allChains.find(chain => chain.chainId === currentChainId) || null
351-
} catch (e) {
352-
console.error(e)
353-
return null
354-
}
355-
}
356-
357356
const checkSumWarning = () => {
358357
return (
359358
<span className="text-start">

0 commit comments

Comments
 (0)