@@ -74,34 +74,28 @@ export class ContractVerificationPluginClient extends PluginClient {
7474 try {
7575 await this . call ( 'terminal' , 'log' , { type : 'log' , value : 'Verification process started...' } )
7676
77- const { chainId, currentChain, contractAddress, contractName, compilationResult, constructorArgs, etherscanApiKey } = data
77+ const { chainId, currentChain, contractAddress, contractName, compilationResult, constructorArgs } = data
78+
79+ const globalEtherscanApiKey = data . etherscanApiKey
7880
7981 if ( ! currentChain ) {
8082 await this . call ( 'terminal' , 'log' , { type : 'error' , value : 'Chain data was not provided for verification.' } )
8183 return
8284 }
8385
8486 const userSettings = this . getUserSettingsFromLocalStorage ( )
87+ const chainSettings = mergeChainSettingsWithDefaults ( chainId , userSettings )
88+ const localEtherscanApiKey = chainSettings . verifiers [ 'Etherscan' ] ?. apiKey
89+ const effectiveApiKey = globalEtherscanApiKey || localEtherscanApiKey
8590
86- if ( etherscanApiKey ) {
87- if ( ! userSettings . chains [ chainId ] ) {
88- userSettings . chains [ chainId ] = { verifiers : { } }
89- }
90-
91- if ( ! userSettings . chains [ chainId ] . verifiers . Etherscan ) {
92- userSettings . chains [ chainId ] . verifiers . Etherscan = { }
93- }
94- userSettings . chains [ chainId ] . verifiers . Etherscan . apiKey = etherscanApiKey
95-
96- if ( ! userSettings . chains [ chainId ] . verifiers . Routescan ) {
97- userSettings . chains [ chainId ] . verifiers . Routescan = { }
98- }
99- if ( ! userSettings . chains [ chainId ] . verifiers . Routescan . apiKey ) {
100- userSettings . chains [ chainId ] . verifiers . Routescan . apiKey = "placeholder"
91+ if ( effectiveApiKey ) {
92+ if ( ! chainSettings . verifiers [ 'Etherscan' ] ) {
93+ chainSettings . verifiers [ 'Etherscan' ] = { }
10194 }
95+ chainSettings . verifiers [ 'Etherscan' ] . apiKey = effectiveApiKey
10296
103- window . localStorage . setItem ( "contract-verification:settings" , JSON . stringify ( userSettings ) )
104-
97+ const source = globalEtherscanApiKey ? "Remix Settings" : "Plugin Settings"
98+ await this . call ( 'terminal' , 'log' , { type : 'info' , value : `Using Etherscan API Key from: ${ source } ` } )
10599 }
106100
107101 const submittedContracts : SubmittedContracts = JSON . parse ( window . localStorage . getItem ( 'contract-verification:submitted-contracts' ) || '{}' )
@@ -123,18 +117,17 @@ export class ContractVerificationPluginClient extends PluginClient {
123117 }
124118
125119 const compilerAbstract : CompilerAbstract = compilationResult
126- const chainSettings = mergeChainSettingsWithDefaults ( chainId , userSettings )
127-
128120 const verificationPromises = [ ]
129121 const verifiers : VerifierIdentifier [ ] = [ 'Sourcify' , 'Etherscan' , 'Blockscout' , 'Routescan' ]
130122
131123 for ( const verifier of verifiers ) {
124+ if ( verifier === 'Etherscan' && ! effectiveApiKey ) {
125+ await this . call ( 'terminal' , 'log' , { type : 'warn' , value : 'Etherscan verification skipped: API key not provided.' } )
126+ await this . call ( 'terminal' , 'log' , { type : 'warn' , value : `Please input the API key in Remix Settings OR Contract Verification Plugin Settings.` } )
127+ continue
128+ }
129+
132130 if ( validConfiguration ( chainSettings , verifier ) ) {
133- if ( verifier === 'Etherscan' && ! etherscanApiKey ) {
134- this . call ( 'terminal' , 'log' , { type : 'warn' , value : 'Etherscan verification skipped: API key not provided for auto-verification.' } )
135- this . call ( 'terminal' , 'log' , { type : 'warn' , value : `Go to contract verification plugin's settings tab & input the API key.` } )
136- continue
137- }
138131 verificationPromises . push ( this . _verifyWithProvider ( verifier , submittedContract , compilerAbstract , chainId , chainSettings ) )
139132 }
140133 }
0 commit comments