@@ -144,9 +144,6 @@ export class EtherscanProvider extends AbstractProvider {
144
144
this . #plugin = network . getPlugin < EtherscanPlugin > ( EtherscanPluginId ) ;
145
145
146
146
defineProperties < EtherscanProvider > ( this , { apiKey, network } ) ;
147
-
148
- // Test that the network is supported by Etherscan
149
- this . getBaseUrl ( ) ;
150
147
}
151
148
152
149
/**
@@ -155,6 +152,11 @@ export class EtherscanProvider extends AbstractProvider {
155
152
* If an [[EtherscanPlugin]] is configured on the
156
153
* [[EtherscanBaseProvider_network]], returns the plugin's
157
154
* baseUrl.
155
+ *
156
+ * Deprecated; for Etherscan v2 the base is no longer a simply
157
+ * host, but instead a URL including a chainId parameter. Changing
158
+ * this to return a URL prefix could break some libraries, so it
159
+ * is left intact but will be removed in the future as it is unused.
158
160
*/
159
161
getBaseUrl ( ) : string {
160
162
if ( this . #plugin) { return this . #plugin. baseUrl ; }
@@ -202,22 +204,22 @@ export class EtherscanProvider extends AbstractProvider {
202
204
* Returns the URL for the %%module%% and %%params%%.
203
205
*/
204
206
getUrl ( module : string , params : Record < string , string > ) : string {
205
- const query = Object . keys ( params ) . reduce ( ( accum , key ) => {
207
+ let query = Object . keys ( params ) . reduce ( ( accum , key ) => {
206
208
const value = params [ key ] ;
207
209
if ( value != null ) {
208
210
accum += `&${ key } =${ value } `
209
211
}
210
212
return accum
211
213
} , "" ) ;
212
- const apiKey = ( ( this . apiKey ) ? `&apikey=${ this . apiKey } ` : "" ) ;
213
- return `${ this . getBaseUrl ( ) } /api? module=${ module } ${ query } ${ apiKey } ` ;
214
+ if ( this . apiKey ) { query += `&apikey=${ this . apiKey } ` ; }
215
+ return `https:/\/api.etherscan.io/v2/api?chainid= ${ this . network . chainId } & module=${ module } ${ query } ` ;
214
216
}
215
217
216
218
/**
217
219
* Returns the URL for using POST requests.
218
220
*/
219
221
getPostUrl ( ) : string {
220
- return `${ this . getBaseUrl ( ) } /api ` ;
222
+ return `https:/\/api.etherscan.io/v2/api?chainid= ${ this . network . chainId } ` ;
221
223
}
222
224
223
225
/**
@@ -226,6 +228,7 @@ export class EtherscanProvider extends AbstractProvider {
226
228
getPostData ( module : string , params : Record < string , any > ) : Record < string , any > {
227
229
params . module = module ;
228
230
params . apikey = this . apiKey ;
231
+ params . chainid = this . network . chainId ;
229
232
return params ;
230
233
}
231
234
@@ -367,7 +370,6 @@ export class EtherscanProvider extends AbstractProvider {
367
370
* Throws the normalized Etherscan error.
368
371
*/
369
372
_checkError ( req : PerformActionRequest , error : Error , transaction : any ) : never {
370
-
371
373
// Pull any message out if, possible
372
374
let message = "" ;
373
375
if ( isError ( error , "SERVER_ERROR" ) ) {
0 commit comments