@@ -97,7 +97,7 @@ pub struct Client {
97
97
api_key : Option < String > ,
98
98
/// Etherscan API version
99
99
etherscan_api_version : EtherscanApiVersion ,
100
- /// Etherscan API endpoint like <https://api(-chain) .etherscan.io/api>
100
+ /// Etherscan API endpoint like <https://api.etherscan.io/v2/ api?chainid=(chain_id) >
101
101
etherscan_api_url : Url ,
102
102
/// Etherscan base endpoint like <https://etherscan.io>
103
103
etherscan_url : Url ,
@@ -262,12 +262,14 @@ impl Client {
262
262
async fn post < F : Serialize > ( & self , form : & F ) -> Result < String > {
263
263
trace ! ( target: "etherscan" , "POST {}" , self . etherscan_api_url) ;
264
264
265
- let post_query = match self . chain_id {
266
- Some ( chain_id) if self . etherscan_api_version == EtherscanApiVersion :: V2 => {
267
- HashMap :: from ( [ ( "chainid" , chain_id) ] )
268
- }
269
- _ => HashMap :: new ( ) ,
270
- } ;
265
+ let mut post_query = HashMap :: new ( ) ;
266
+
267
+ if self . etherscan_api_version == EtherscanApiVersion :: V2
268
+ && self . chain_id . is_some ( )
269
+ && !self . url_contains_chainid ( )
270
+ {
271
+ post_query. insert ( "chainid" , self . chain_id . unwrap ( ) ) ;
272
+ }
271
273
272
274
let response = self
273
275
. client
@@ -278,6 +280,7 @@ impl Client {
278
280
. await ?
279
281
. text ( )
280
282
. await ?;
283
+
281
284
Ok ( response)
282
285
}
283
286
@@ -322,10 +325,14 @@ impl Client {
322
325
apikey : self . api_key . as_deref ( ) . map ( Cow :: Borrowed ) ,
323
326
module : Cow :: Borrowed ( module) ,
324
327
action : Cow :: Borrowed ( action) ,
325
- chain_id : self . chain_id ,
328
+ chain_id : if self . url_contains_chainid ( ) { None } else { self . chain_id } ,
326
329
other,
327
330
}
328
331
}
332
+
333
+ fn url_contains_chainid ( & self ) -> bool {
334
+ self . etherscan_api_url . query_pairs ( ) . any ( |( key, _) | key. eq_ignore_ascii_case ( "chainid" ) )
335
+ }
329
336
}
330
337
331
338
#[ derive( Clone , Debug , Default ) ]
@@ -334,7 +341,7 @@ pub struct ClientBuilder {
334
341
client : Option < reqwest:: Client > ,
335
342
/// Etherscan API key
336
343
api_key : Option < String > ,
337
- /// Etherscan API endpoint like <https://api(-chain) .etherscan.io/api>
344
+ /// Etherscan API endpoint like <https://api.etherscan.io/v2/ api?chainid=(chain_id) >
338
345
etherscan_api_url : Option < Url > ,
339
346
/// Etherscan API version (v2 is new verifier version, v1 is the default)
340
347
etherscan_api_version : EtherscanApiVersion ,
0 commit comments