From c0ce0fb9a8a600596eb75fe01c1b41152c9e3770 Mon Sep 17 00:00:00 2001 From: Krzysztof Kaczor Date: Tue, 30 Sep 2025 09:21:19 +0200 Subject: [PATCH 1/2] Fix etherscan urls --- packages/ethereum-viewer/src/explorer/fetchFiles.test.ts | 2 +- packages/ethereum-viewer/src/explorer/fetchFiles.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/ethereum-viewer/src/explorer/fetchFiles.test.ts b/packages/ethereum-viewer/src/explorer/fetchFiles.test.ts index 950c572..d8bb6b7 100644 --- a/packages/ethereum-viewer/src/explorer/fetchFiles.test.ts +++ b/packages/ethereum-viewer/src/explorer/fetchFiles.test.ts @@ -36,7 +36,7 @@ describe(fetchFiles.name, () => { await fetchFiles("optimistic.etherscan", "0x0", { fetch: f }); const expectedPrefix = - "https://api-optimistic.etherscan.io/api?module=contract&action=getsourcecode&address=0x0&apikey="; + "https://api-optimistic.etherscan.io/api?&module=contract&action=getsourcecode&address=0x0&apikey="; assert( url?.startsWith(expectedPrefix), diff --git a/packages/ethereum-viewer/src/explorer/fetchFiles.ts b/packages/ethereum-viewer/src/explorer/fetchFiles.ts index cc27921..fe1d462 100644 --- a/packages/ethereum-viewer/src/explorer/fetchFiles.ts +++ b/packages/ethereum-viewer/src/explorer/fetchFiles.ts @@ -44,7 +44,7 @@ export async function fetchFiles( const apiUrl = explorerApiUrls[apiName]; const url = apiUrl + - "?module=contract" + + "&module=contract" + "&action=getsourcecode" + `&address=${contractAddress}` + `&apikey=${explorerApiKeys[apiName]}`; From de8e905944bcb681bb1dc687c84929666d9ef5a8 Mon Sep 17 00:00:00 2001 From: Krzysztof Kaczor Date: Tue, 30 Sep 2025 09:24:42 +0200 Subject: [PATCH 2/2] Fix --- .../src/explorer/fetchFiles.test.ts | 2 +- .../src/explorer/fetchFiles.ts | 22 ++++++++++++++----- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/packages/ethereum-viewer/src/explorer/fetchFiles.test.ts b/packages/ethereum-viewer/src/explorer/fetchFiles.test.ts index d8bb6b7..950c572 100644 --- a/packages/ethereum-viewer/src/explorer/fetchFiles.test.ts +++ b/packages/ethereum-viewer/src/explorer/fetchFiles.test.ts @@ -36,7 +36,7 @@ describe(fetchFiles.name, () => { await fetchFiles("optimistic.etherscan", "0x0", { fetch: f }); const expectedPrefix = - "https://api-optimistic.etherscan.io/api?&module=contract&action=getsourcecode&address=0x0&apikey="; + "https://api-optimistic.etherscan.io/api?module=contract&action=getsourcecode&address=0x0&apikey="; assert( url?.startsWith(expectedPrefix), diff --git a/packages/ethereum-viewer/src/explorer/fetchFiles.ts b/packages/ethereum-viewer/src/explorer/fetchFiles.ts index fe1d462..ed12e82 100644 --- a/packages/ethereum-viewer/src/explorer/fetchFiles.ts +++ b/packages/ethereum-viewer/src/explorer/fetchFiles.ts @@ -42,12 +42,22 @@ export async function fetchFiles( }: FetchFilesOptions = {} ): Promise { const apiUrl = explorerApiUrls[apiName]; - const url = - apiUrl + - "&module=contract" + - "&action=getsourcecode" + - `&address=${contractAddress}` + - `&apikey=${explorerApiKeys[apiName]}`; + let url; + if (apiUrl.includes("chainid=")) { + url = + apiUrl + + "&module=contract" + + "&action=getsourcecode" + + `&address=${contractAddress}` + + `&apikey=${explorerApiKeys[apiName]}`; + } else { + url = + apiUrl + + "?module=contract" + + "&action=getsourcecode" + + `&address=${contractAddress}` + + `&apikey=${explorerApiKeys[apiName]}`; + } const response = (await fetch(url)) as types.ContractSourceResponse;