Skip to content

Commit 40149b1

Browse files
authored
Merge pull request #767 from masquel/master
Add api links for BSC and Polygon networks to support auto ABI downloading when init subgraph
2 parents 57631e0 + 89ee362 commit 40149b1

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

src/commands/init.js

Lines changed: 11 additions & 3 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

0 commit comments

Comments
 (0)