feat: add etherscan 2.0 api - #429
Conversation
There was a problem hiding this comment.
Pull Request Overview
This PR adds support for Etherscan API 2.0, upgrading from the previous implementation to use the new API endpoint structure with chain ID-based URLs.
- Updates EtherscanApi service to use the new v2 API endpoint format
- Adds comprehensive test coverage for multiple blockchain networks
- Includes a custom chain definition for HyperEVM
Reviewed Changes
Copilot reviewed 4 out of 7 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| src/services/etherscanApi.ts | Updates API URL generation to use Etherscan v2 format and removes hardcoded delays |
| test/typescript/etherscanApi.test.ts | Adds comprehensive test suite covering multiple chains and API functionality |
| src/utils/customChains.ts | Defines HyperEVM custom chain configuration |
| package.json | Adds Jest testing dependencies |
Comments suppressed due to low confidence (2)
test/typescript/etherscanApi.test.ts:53
- The test uses '0x' as a fallback address when multicall3 is not defined, which would result in an invalid Ethereum address and likely cause the API call to fail. Consider either ensuring all test chains have multicall3 defined or using a valid fallback address.
etherscanApi.chain.contracts?.multicall3?.address || '0x',
test/typescript/etherscanApi.test.ts:65
- Same issue as above - using '0x' as a fallback address could cause test failures due to invalid address format.
etherscanApi.chain.contracts?.multicall3?.address || '0x',
| // TODO: Validate chain is supported by EtherscanAPI. | ||
| return `https://api.etherscan.io/v2/api?chainid=${this.chain.id}` |
There was a problem hiding this comment.
The TODO comment indicates missing validation for supported chains. This could lead to runtime errors when using unsupported chains. Consider implementing validation against a list of supported chain IDs or adding error handling for unsupported chains.
| // TODO: Validate chain is supported by EtherscanAPI. | |
| return `https://api.etherscan.io/v2/api?chainid=${this.chain.id}` | |
| const supportedChains = [1, 3, 4, 5, 42, 56, 137, 250, 43114]; // Example chain IDs from Etherscan documentation | |
| if (!supportedChains.includes(this.chain.id)) { | |
| throw new Error(`Unsupported chain ID: ${this.chain.id}. Please use a supported chain.`); | |
| } | |
| return `https://api.etherscan.io/v2/api?chainid=${this.chain.id}`; |
| default: { | ||
| name: 'HyperEVM Explorer', | ||
| url: 'https://hyperevmscan.com', | ||
| apiUrl: 'https://api.etherscan.io/v2/api?chainid=999', |
There was a problem hiding this comment.
The apiUrl in the block explorer configuration is inconsistent with the new API URL generation logic in EtherscanApi. Since the service now constructs URLs dynamically, this hardcoded apiUrl may cause confusion or conflicts.
| apiUrl: 'https://api.etherscan.io/v2/api?chainid=999', | |
| apiUrl: generateEtherscanApiUrl(999), |
Also closes: #427 See erc4626 pr: balancer/balancer-v3-erc4626-tests#74