diff --git a/apps/etherscan/src/app/RemixPlugin.tsx b/apps/etherscan/src/app/RemixPlugin.tsx index 601e523920..13d5bdfe73 100644 --- a/apps/etherscan/src/app/RemixPlugin.tsx +++ b/apps/etherscan/src/app/RemixPlugin.tsx @@ -16,11 +16,11 @@ export class RemixClient extends PluginClient { async receiptStatus (receiptGuid: string, apiKey: string) { try { - const network = await getNetworkName(this) + const { network, networkId } = await getNetworkName(this) if (network === "vm") { throw new Error("Cannot check the receipt status in the selected network") } - const etherscanApi = getEtherScanApi(network) + const etherscanApi = getEtherScanApi(network, networkId) const receiptStatus = await getReceiptStatus(receiptGuid, apiKey, etherscanApi) return { message: receiptStatus.result, diff --git a/apps/etherscan/src/app/app.tsx b/apps/etherscan/src/app/app.tsx index d8cb50d90b..e7978f403a 100644 --- a/apps/etherscan/src/app/app.tsx +++ b/apps/etherscan/src/app/app.tsx @@ -94,14 +94,14 @@ const App = () => { if (!clientInstanceRef.current) { return {} } - const network = await getNetworkName(clientInstanceRef.current) + const { network, networkId } = await getNetworkName(clientInstanceRef.current) if (network === "vm") { return {} } const status = await getReceiptStatus( item.guid, apiKey, - getEtherScanApi(network) + getEtherScanApi(network, networkId) ) if (status.result === "Pass - Verified" || status.result === "Already Verified") { const newReceipts = receipts.map((currentReceipt: Receipt) => { diff --git a/apps/etherscan/src/app/routes.tsx b/apps/etherscan/src/app/routes.tsx index 7470d91bf0..406d57421e 100644 --- a/apps/etherscan/src/app/routes.tsx +++ b/apps/etherscan/src/app/routes.tsx @@ -43,7 +43,7 @@ export const DisplayRoutes = () => ( } /> + element={ } /> diff --git a/apps/etherscan/src/app/utils/networks.ts b/apps/etherscan/src/app/utils/networks.ts new file mode 100644 index 0000000000..ca077e9c87 --- /dev/null +++ b/apps/etherscan/src/app/utils/networks.ts @@ -0,0 +1,33 @@ +export const scanAPIurls = { + // all mainnet + 56: "https://api.bscscan.com/api", + 137: "https://api.polygonscan.com/api", + 250: "https://api.ftmscan.com/api", + 42161: "https://api.arbiscan.io/api", + 43114: "https://api.snowtrace.io/api", + 1285: "https://api-moonriver.moonscan.io/api", + 1284: "https://api-moonbeam.moonscan.io/api", + 25: "https://api.cronoscan.com/api", + 199: "https://api.bttcscan.com/api", + 10: "https://api-optimistic.etherscan.io/api", + 42220: "https://api.celoscan.io/api", + 288: "https://api.bobascan.com/api", + 100: "https://api.gnosisscan.io/api", + 1101: "https://api-zkevm.polygonscan.com/api", + + // all testnet + 97: "https://api-testnet.bscscan.com/api", + 80001: "https://api-testnet.polygonscan.com/api", + 4002: "https://api-testnet.ftmscan.com/api", + 421611: "https://api-testnet.arbiscan.io/api", + 42170: "https://api-nova.arbiscan.io/api", + 43113: "https://api-testnet.snowtrace.io/api", + 1287: "https://api-moonbase.moonscan.io/api", + 338: "https://api-testnet.cronoscan.com/api", + 1028: "https://api-testnet.bttcscan.com/api", + 420: "https://api-goerli-optimistic.etherscan.io/api", + 44787: "https://api-alfajores.celoscan.io/api", + 2888: "https://api-testnet.bobascan.com/api", + 84531: "https://api-goerli.basescan.org/api", + 1442: "https://api-testnet-zkevm.polygonscan.com/api" +} \ No newline at end of file diff --git a/apps/etherscan/src/app/utils/utilities.ts b/apps/etherscan/src/app/utils/utilities.ts index b7db856364..500872e2d1 100644 --- a/apps/etherscan/src/app/utils/utilities.ts +++ b/apps/etherscan/src/app/utils/utilities.ts @@ -1,5 +1,6 @@ import { PluginClient } from "@remixproject/plugin" import axios from 'axios' +import { scanAPIurls } from "./networks" type RemixClient = PluginClient /* @@ -13,18 +14,29 @@ export type receiptStatus = { status: string } -export const getEtherScanApi = (network: string) => { - return network === "main" - ? `https://api.etherscan.io/api` - : `https://api-${network}.etherscan.io/api` +export const getEtherScanApi = (network: string, networkId: any) => { + let apiUrl + + if (network === "main") { + apiUrl = "https://api.etherscan.io/api" + } else if (network === "custom") { + if (!(networkId in scanAPIurls)) { + throw new Error("no known network to verify against") + } + apiUrl = (scanAPIurls as any)[networkId] + } else { + apiUrl = `https://api-${network}.etherscan.io/api` + } + + return apiUrl } export const getNetworkName = async (client: RemixClient) => { const network = await client.call("network", "detectNetwork") if (!network) { throw new Error("no known network to verify against") - } - return network.name!.toLowerCase() + } + return { network: network.name!.toLowerCase(), networkId: network.id } } export const getReceiptStatus = async ( diff --git a/apps/etherscan/src/app/utils/verify.ts b/apps/etherscan/src/app/utils/verify.ts index e454df5961..1b2040ad0b 100644 --- a/apps/etherscan/src/app/utils/verify.ts +++ b/apps/etherscan/src/app/utils/verify.ts @@ -25,14 +25,14 @@ export const verify = async ( onVerifiedContract: (value: EtherScanReturn) => void, setResults: (value: string) => void ) => { - const network = await getNetworkName(client) + const { network, networkId } = await getNetworkName(client) if (network === "vm") { return { succeed: false, message: "Cannot verify in the selected network" } } - const etherscanApi = getEtherScanApi(network) + const etherscanApi = getEtherScanApi(network, networkId) try { const contractMetadata = getContractMetadata( diff --git a/apps/etherscan/src/app/views/ReceiptsView.tsx b/apps/etherscan/src/app/views/ReceiptsView.tsx index 4eae34b120..51615b5985 100644 --- a/apps/etherscan/src/app/views/ReceiptsView.tsx +++ b/apps/etherscan/src/app/views/ReceiptsView.tsx @@ -19,7 +19,7 @@ export const ReceiptsView: React.FC = () => { apiKey: string ) => { try { - const network = await getNetworkName(clientInstance) + const { network, networkId } = await getNetworkName(clientInstance) if (network === "vm") { setResults({ succeed: false, @@ -27,7 +27,7 @@ export const ReceiptsView: React.FC = () => { }) return } - const etherscanApi = getEtherScanApi(network) + const etherscanApi = getEtherScanApi(network, networkId) const result = await getReceiptStatus( values.receiptGuid, apiKey, diff --git a/apps/etherscan/src/app/views/VerifyView.tsx b/apps/etherscan/src/app/views/VerifyView.tsx index e28fd0e4b7..20730222ca 100644 --- a/apps/etherscan/src/app/views/VerifyView.tsx +++ b/apps/etherscan/src/app/views/VerifyView.tsx @@ -38,7 +38,7 @@ export const VerifyView: React.FC = ({ useEffect(() => { if (client && client.on) { client.on("blockchain" as any, 'networkStatus', (result) => { - setNetworkName(result.network.name) + setNetworkName(`${result.network.name} (Chain id: ${result.network.id})`) }) } return () => { diff --git a/apps/etherscan/src/profile.json b/apps/etherscan/src/profile.json index a15f25009d..2fc62888c3 100644 --- a/apps/etherscan/src/profile.json +++ b/apps/etherscan/src/profile.json @@ -1,7 +1,7 @@ { "name": "etherscan", - "displayName": "Etherscan - Contract verification", - "description": "Verify Solidity contract code using Etherscan API", + "displayName": "Contract verification - Etherscan", + "description": "Verify Solidity contract code using Etherscan, BscScan, PolygonScan etc. APIs", "version": "0.1.0", "events": [], "methods": ["verify", "receiptStatus"],