@@ -257,16 +257,24 @@ const loadAbiFromBlockScout = async (network, address) =>
257
257
} ,
258
258
)
259
259
260
+ const getEtherscanLikeAPIUrl = ( network ) => {
261
+ switch ( network ) {
262
+ case "mainnet" : return `https://api.etherscan.io/api` ;
263
+ case "bsc" : return `https://api.bscscan.com/api` ;
264
+ case "matic" : return `https://api.polygonscan.com/api` ;
265
+ default : return `https://api-${ network } .etherscan.io/api` ;
266
+ }
267
+ }
268
+
260
269
const loadAbiFromEtherscan = async ( network , address ) =>
261
270
await withSpinner (
262
271
`Fetching ABI from Etherscan` ,
263
272
`Failed to fetch ABI from Etherscan` ,
264
273
`Warnings while fetching ABI from Etherscan` ,
265
274
async spinner => {
275
+ const scanApiUrl = getEtherscanLikeAPIUrl ( network ) ;
266
276
let result = await fetch (
267
- `https://${
268
- network === 'mainnet' ? 'api' : `api-${ network } `
269
- } .etherscan.io/api?module=contract&action=getabi&address=${ address } `,
277
+ `${ scanApiUrl } ?module=contract&action=getabi&address=${ address } ` ,
270
278
)
271
279
let json = await result . json ( )
272
280
@@ -279,7 +287,7 @@ const loadAbiFromEtherscan = async (network, address) =>
279
287
throw new Error ( 'ABI not found, try loading it from a local file' )
280
288
}
281
289
} ,
282
- )
290
+ )
283
291
284
292
const loadAbiFromFile = async filename => {
285
293
let exists = await toolbox . filesystem . exists ( filename )
@@ -404,6 +412,10 @@ module.exports = {
404
412
try {
405
413
if ( network === 'poa-core' ) {
406
414
abi = await loadAbiFromBlockScout ( network , fromContract )
415
+ } else if ( network === 'bsc' ) {
416
+ abi = await loadAbiFromBscscan ( network , fromContract )
417
+ } else if ( network === 'matic' ) {
418
+ abi = await loadAbiFromBscscan ( network , fromContract )
407
419
} else {
408
420
abi = await loadAbiFromEtherscan ( network , fromContract )
409
421
}
0 commit comments