Skip to content

Commit 71fcdc5

Browse files
AlexeyAlexey
authored andcommitted
add api urls for bsc and polygon to load ABI from scanners for this networks
1 parent de77189 commit 71fcdc5

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

src/commands/init.js

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -257,16 +257,24 @@ const loadAbiFromBlockScout = async (network, address) =>
257257
},
258258
)
259259

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+
260269
const loadAbiFromEtherscan = async (network, address) =>
261270
await withSpinner(
262271
`Fetching ABI from Etherscan`,
263272
`Failed to fetch ABI from Etherscan`,
264273
`Warnings while fetching ABI from Etherscan`,
265274
async spinner => {
275+
const scanApiUrl = getEtherscanLikeAPIUrl(network);
266276
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}`,
270278
)
271279
let json = await result.json()
272280

@@ -279,7 +287,7 @@ const loadAbiFromEtherscan = async (network, address) =>
279287
throw new Error('ABI not found, try loading it from a local file')
280288
}
281289
},
282-
)
290+
)
283291

284292
const loadAbiFromFile = async filename => {
285293
let exists = await toolbox.filesystem.exists(filename)
@@ -404,6 +412,10 @@ module.exports = {
404412
try {
405413
if (network === 'poa-core') {
406414
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)
407419
} else {
408420
abi = await loadAbiFromEtherscan(network, fromContract)
409421
}

0 commit comments

Comments
 (0)