Skip to content

feat: support custom Etherscan-compatible API URLs#2738

Closed
kuzdogan wants to merge 1 commit intostagingfrom
feat/custom-etherscan-api-url
Closed

feat: support custom Etherscan-compatible API URLs#2738
kuzdogan wants to merge 1 commit intostagingfrom
feat/custom-etherscan-api-url

Conversation

@kuzdogan
Copy link
Copy Markdown
Member

@kuzdogan kuzdogan commented Apr 8, 2026

Summary

Adds an optional url field to the etherscanApi chain configuration, enabling chains with their own Etherscan-compatible block explorers to use a custom base URL instead of the hardcoded https://api.etherscan.io/v2/api.

Kept separate from #2709 (remote chain config refactor) as that PR is already very large.

Changes

  • SourcifyChainTypes.ts and SourcifyChain.ts (packages/lib-sourcify): Add url?: string to etherscanApi
  • etherscan-util.ts (packages/lib-sourcify): fetchFromEtherscan accepts optional customBaseUrl. When provided, uses ${customBaseUrl}/api?module=contract&action=getsourcecode&... instead of the default Etherscan v2 URL
  • etherscan-util.ts (server): Passes sourcifyChain.etherscanApi?.url through to lib-sourcify
  • contract-creation-util.ts (server): getEtherscanApiContractCreatorFetcher accepts optional customBaseUrl. When provided, uses ${customBaseUrl}/api?module=contract&action=getcontractcreation&... instead of the hardcoded ETHERSCAN_API constant

Example usage (BattleChain Testnet)

Chain definition (extra-chains.json):

{
  "name": "BattleChain Testnet",
  "chain": "ETH",
  "rpc": ["https://testnet.battlechain.com"],
  "faucets": [],
  "nativeCurrency": { "name": "Ether", "symbol": "ETH", "decimals": 18 },
  "infoURL": "https://battlechain.com",
  "shortName": "battlechain-testnet",
  "chainId": 627,
  "networkId": 627,
  "slip44": 1,
  "explorers": [
    { "name": "BattleChain Explorer", "url": "https://explorer.testnet.battlechain.com", "standard": "EIP3091" }
  ]
}

Sourcify extension (sourcify-chains-default.json):

"627": {
  "sourcifyName": "BattleChain Testnet",
  "supported": true,
  "etherscanApi": {
    "supported": true,
    "url": "https://block-explorer-api.testnet.battlechain.com"
  },
  "fetchContractCreationTxUsing": {
    "etherscanApi": true
  },
  "rpc": ["https://testnet.battlechain.com"]
}

With url set, both the Etherscan source import (getsourcecode) and the contract creation tx lookup (getcontractcreation) will hit https://block-explorer-api.testnet.battlechain.com/api?... instead of api.etherscan.io.

Test plan

  • npx lerna run build passes
  • packages/lib-sourcify tests pass (158 passing)
  • services/server unit tests pass (69 passing)

🤖 Generated with Claude Code

Add optional `url` field to `etherscanApi` chain config so chains with
their own Etherscan-compatible block explorers can use a custom base URL
instead of the default api.etherscan.io/v2. Both the contract creation
tx fetcher and the source code import path respect this override.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@marcocastignoli marcocastignoli moved this from Triage to Sprint - Up Next in Sourcify Public Apr 13, 2026
@kuzdogan kuzdogan marked this pull request as ready for review April 14, 2026 06:07
Copy link
Copy Markdown
Member

@marcocastignoli marcocastignoli left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm. we can close this since it was already merged by mistake in #2732

@github-project-automation github-project-automation bot moved this from Sprint - Up Next to Sprint - Done in Sourcify Public Apr 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Sprint - Done

Development

Successfully merging this pull request may close these issues.

2 participants