Skip to content

Commit 214a8c7

Browse files
committed
fallback to original etherscan api if apikey is provided
1 parent b216747 commit 214a8c7

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

evm/evm-typegen/src/main.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { OutDir } from '@subsquid/util-internal-code-printer'
1010

1111
const LOG = createLogger('sqd:evm-typegen')
1212
const PROXY_ETHERSCAN = 'https://cloud.sqd.dev/chains/api/v1/evm/abi'
13+
const ORIGIN_ETHERSCAN = 'https://api.etherscan.io/v2/api'
1314

1415
runProgram(
1516
async function () {
@@ -131,11 +132,11 @@ async function fetchFromEtherscan(
131132
config: EtherscanAPIConfig,
132133
): Promise<any> {
133134
let api: string
134-
if (config.api === PROXY_ETHERSCAN ) {
135-
api = config.api
135+
if (config.api === PROXY_ETHERSCAN && config.apiKey) {
136+
api = ORIGIN_ETHERSCAN
136137
}
137138
else {
138-
api = config.api + (config.api.endsWith('/') ? '' : '/') + 'api'
139+
api = config.api
139140
}
140141
let url = new URL(api)
141142

@@ -175,7 +176,7 @@ async function fetchFromEtherscan(
175176
return JSON.parse(response.result)
176177
} else {
177178
throw new Error(
178-
`Failed to fetch contract ABI from ${config.api}: ${response.result}`,
179+
`Failed to fetch contract ABI from ${api}: ${response.result}`,
179180
)
180181
}
181182
}

0 commit comments

Comments
 (0)