Skip to content

Commit b5ab0cb

Browse files
authored
Fix snowtrace sourcecode verify api (#2085)
* Fix snowtrace sourcecode verify api * Update blockroute snowtrace API * Blockroute API compatibility
1 parent 694e51f commit b5ab0cb

File tree

2 files changed

+11
-7
lines changed

2 files changed

+11
-7
lines changed

lib/maps.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ export const apiKeyMap: Record<number, string> = {
66
80001: process.env.POLYGONSCAN_KEY as string,
77
250: process.env.FANTOMSCAN_KEY as string,
88
4002: process.env.FANTOMSCAN_KEY as string,
9-
43114: process.env.SNOWTRACE_KEY as string,
10-
43113: process.env.SNOWTRACE_KEY as string,
9+
43114: "",
10+
43113: "",
1111
42161: process.env.ARBITRUMSCAN_KEY as string,
1212
421613: process.env.ARBITRUMSCAN_KEY as string,
1313
10: process.env.OPTIMISMSCAN_KEY as string,
@@ -42,8 +42,8 @@ export const apiMap: Record<number, string> = {
4242
11155111: "https://api-sepolia.etherscan.io/api",
4343
4002: "https://api-testnet.ftmscan.com/api",
4444
42161: "https://api.arbiscan.io/api",
45-
43113: "https://api-testnet.snowtrace.io/api",
46-
43114: "https://api.snowtrace.io/api",
45+
43113: "https://api.routescan.io/v2/network/testnet/evm/43113/etherscan/api",
46+
43114: "https://api.routescan.io/v2/network/mainnet/evm/43114/etherscan/api",
4747
421613: "https://api-goerli.arbiscan.io/api",
4848
80001: "https://api-testnet.polygonscan.com/api",
4949
1313161554: "https://api.aurorascan.dev/api",

pages/api/etherscan-fetch.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ const handler = async (req: NextApiRequest, res: NextApiResponse) => {
3434
return res.status(400).json({ error: "invalid chainId" });
3535
}
3636

37-
const endpoint = `${apiMap[chainId]}?module=contract&action=getsourcecode&address=${contractAddress}&apikey=${apiKeyMap[chainId]}"`;
37+
const endpoint = `${apiMap[chainId]}?module=contract&action=getsourcecode&address=${contractAddress}&apikey=${apiKeyMap[chainId]}`;
3838

3939
try {
4040
const result = await fetch(endpoint, {
@@ -46,8 +46,12 @@ const handler = async (req: NextApiRequest, res: NextApiResponse) => {
4646
});
4747

4848
const data = await result.json();
49-
const etherscanResult = data.result[0] as EtherscanResult;
50-
if (etherscanResult.ABI === "Contract source code not verified") {
49+
const etherscanResult = Array.isArray(data.result)
50+
? data.result[0]
51+
: data.result;
52+
// Blockroute and etherscan return different output schema
53+
const etherscanResultMessage = etherscanResult.ABI || etherscanResult;
54+
if (etherscanResultMessage === "Contract source code not verified") {
5155
return res
5256
.status(404)
5357
.json({ error: "Contract source code not verified on etherscan" });

0 commit comments

Comments
 (0)