Skip to content

Commit a1a91e6

Browse files
committed
refactor: use etherscan api v2 (#266)
1 parent bd2f57e commit a1a91e6

File tree

3 files changed

+16
-53
lines changed

3 files changed

+16
-53
lines changed

.env.example

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
11
ETHERSCAN_API_KEY=
2-
ARBISCAN_API_KEY=
3-
ARBISCAN_NOVA_API_KEY=
4-
BASESCAN_API_KEY=
52

63
NITRO_TESTNODE_DEPLOYER_PRIVATE_KEY=0xb6b15c8cb491557369f3c7d2c287b053eb229daa9c22138887752191c9520659
74

patches/@wagmi+cli+1.5.2.patch

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ index 04a78d1..0eb6430 100644
1313
97: string;
1414
128: string;
1515
diff --git a/node_modules/@wagmi/cli/dist/plugins/index.js b/node_modules/@wagmi/cli/dist/plugins/index.js
16-
index 8e23da2..e075435 100644
16+
index 8e23da2..02b7c49 100644
1717
--- a/node_modules/@wagmi/cli/dist/plugins/index.js
1818
+++ b/node_modules/@wagmi/cli/dist/plugins/index.js
1919
@@ -386,12 +386,12 @@ function blockExplorer({
@@ -41,8 +41,14 @@ index 8e23da2..e075435 100644
4141
[56]: "https://api.bscscan.com/api",
4242
[97]: "https://api-testnet.bscscan.com/api",
4343
[128]: "https://api.hecoinfo.com/api",
44-
@@ -1413,12 +1415,12 @@ function etherscan({
45-
baseUrl: apiUrls[chainId],
44+
@@ -1409,16 +1411,16 @@ function etherscan({
45+
address: typeof x.address === "string" ? { [chainId]: x.address } : x.address
46+
}));
47+
return blockExplorer({
48+
- apiKey,
49+
- baseUrl: apiUrls[chainId],
50+
+ apiKey: `${apiKey}&chainid=${chainId}`,
51+
+ baseUrl: `https://api.etherscan.io/v2/api`,
4652
cacheDuration,
4753
contracts,
4854
- getAddress({ address }) {

wagmi.config.ts

Lines changed: 7 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -44,52 +44,9 @@ sepolia.rpcUrls.default.http[0] = 'https://sepolia.gateway.tenderly.co';
4444
// @ts-ignore
4545
sepolia.rpcUrls.public.http[0] = 'https://sepolia.gateway.tenderly.co';
4646

47-
const arbiscanApiKey = loadApiKey('ARBISCAN_API_KEY');
48-
const arbiscanNovaApiKey = loadApiKey('ARBISCAN_NOVA_API_KEY');
49-
const etherscanApiKey = loadApiKey('ETHERSCAN_API_KEY');
50-
const basescanApikey = loadApiKey('BASESCAN_API_KEY');
51-
52-
const blockExplorerApiUrls: Record<ParentChainId, { url: string; apiKey: string }> = {
53-
// mainnet L1
54-
[mainnet.id]: {
55-
url: 'https://api.etherscan.io/api',
56-
apiKey: etherscanApiKey,
57-
},
58-
// mainnet L2
59-
[arbitrumOne.id]: {
60-
url: 'https://api.arbiscan.io/api',
61-
apiKey: arbiscanApiKey,
62-
},
63-
[arbitrumNova.id]: {
64-
url: 'https://api-nova.arbiscan.io/api',
65-
apiKey: arbiscanNovaApiKey,
66-
},
67-
[base.id]: {
68-
url: 'https://api.basescan.org/api',
69-
apiKey: basescanApikey,
70-
},
71-
// testnet L1
72-
[sepolia.id]: {
73-
url: 'https://api-sepolia.etherscan.io/api',
74-
apiKey: etherscanApiKey,
75-
},
76-
// testnet L2
77-
[arbitrumSepolia.id]: {
78-
url: 'https://api-sepolia.arbiscan.io/api',
79-
apiKey: arbiscanApiKey,
80-
},
81-
[baseSepolia.id]: {
82-
url: 'https://api-sepolia.basescan.org/api',
83-
apiKey: basescanApikey,
84-
},
85-
// local nitro-testnode / fine to omit these as we skip abi fetch
86-
[nitroTestnodeL1.id]: { url: '', apiKey: '' },
87-
[nitroTestnodeL2.id]: { url: '', apiKey: '' },
88-
};
47+
const apiKey = loadApiKey('ETHERSCAN_API_KEY');
8948

9049
export async function fetchAbi(chainId: ParentChainId, address: `0x${string}`) {
91-
const { url, apiKey } = blockExplorerApiUrls[chainId];
92-
9350
const client = createPublicClient({
9451
chain: chains.find((chain) => chain.id === chainId),
9552
transport: http(),
@@ -104,7 +61,7 @@ export async function fetchAbi(chainId: ParentChainId, address: `0x${string}`) {
10461

10562
const responseJson = await (
10663
await fetch(
107-
`${url}?module=contract&action=getabi&format=raw&address=${address}&apikey=${apiKey}`,
64+
`https://api.etherscan.io/v2/api?chainid=${chainId}&module=contract&action=getabi&format=raw&address=${address}&apikey=${apiKey}`,
10865
)
10966
).json();
11067

@@ -226,7 +183,10 @@ export async function assertContractAbisMatch(contract: ContractConfig) {
226183
);
227184
})
228185
// fetch abis for all chains and hash them
229-
.map(async ([chainId, address]) => {
186+
.map(async ([chainId, address], index) => {
187+
// sleep to avoid rate limiting
188+
await sleep(index * 500);
189+
230190
const abi = await fetchAbi(Number(chainId) as ParentChainId, address);
231191
const abiHash = hashMessage(JSON.stringify(abi));
232192

@@ -287,7 +247,7 @@ export default async function () {
287247
plugins: [
288248
etherscan({
289249
chainId: arbitrumSepolia.id,
290-
apiKey: arbiscanApiKey,
250+
apiKey,
291251
// todo: fix viem type issue
292252
contracts: [contract],
293253
cacheDuration: 0,

0 commit comments

Comments
 (0)