feat(public-api): add chains endpoint#11737
Conversation
Add GET /v1/chains and GET /v1/chains/count endpoints to return all supported blockchain networks with metadata including chain type, native asset info, and explorer links. Chains are sorted alphabetically by name.
📝 WalkthroughWalkthroughAdds two new public endpoints, Changes
Sequence Diagram(s)sequenceDiagram
actor Client
participant API as API Server
participant Cache as In-Memory Cache
participant ChainDB as KnownChainIds
participant AssetDB as getBaseAsset
Client->>API: GET /v1/chains
API->>Cache: getChainList()
alt Cache Hit
Cache-->>API: return cached chains
else Cache Miss
API->>ChainDB: iterate KnownChainIds
loop for each chainId
ChainDB-->>API: chainId
API->>AssetDB: getBaseAsset(chainId)
AssetDB-->>API: asset metadata
API->>API: construct Chain object (name, symbol, icons, explorer, nativeAssetId)
end
API->>Cache: store built chains
Cache-->>API: chains stored
end
API-->>Client: { chains: Chain[], timestamp }
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
Warning Review ran into problems🔥 ProblemsErrors were encountered while retrieving linked issues. Errors (1)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Fix all issues with AI agents
In `@packages/public-api/src/types.ts`:
- Around line 136-149: Change the Chain type so the optional icon uses idiomatic
TS syntax and nativeAssetId is strongly typed: replace "icon: string |
undefined" with "icon?: string" and change "nativeAssetId: string" to
"nativeAssetId: AssetId"; import the AssetId type at the top of the file and
update any callers that rely on string-only typing to satisfy the AssetId type
if necessary (look for usages around baseAsset.assetId and the chains list).
🧹 Nitpick comments (1)
packages/public-api/src/types.ts (1)
125-134: Consider a string enum forChainTypeto align with TS conventions.This is a fixed set of constants; a string enum improves discoverability and avoids typo-prone string literals. If adopted, update any assignments to use enum members (e.g.,
ChainType.Evm).As per coding guidelines, please prefer string enums for constant sets.♻️ Proposed refactor
-export type ChainType = - | 'evm' - | 'utxo' - | 'cosmos' - | 'solana' - | 'tron' - | 'sui' - | 'near' - | 'starknet' - | 'ton' +export enum ChainType { + Evm = 'evm', + Utxo = 'utxo', + Cosmos = 'cosmos', + Solana = 'solana', + Tron = 'tron', + Sui = 'sui', + Near = 'near', + Starknet = 'starknet', + Ton = 'ton', +}
- Change `icon: string | undefined` to `icon?: string` - Change `nativeAssetId: string` to `nativeAssetId: AssetId` for stronger typing Co-Authored-By: Claude <[email protected]>
|
As this is isolated to the |
Description
Add chains endpoints to the public API:
GET /v1/chains- List all supported blockchain networks with metadataGET /v1/chains/count- Return the total count of supported chainsThe chains endpoint provides metadata about all supported blockchain networks including chain ID (CAIP-2 format), chain type (evm, utxo, cosmos, solana, etc.), native asset information, and explorer links. Chains are sorted alphabetically by name.
Issue (if applicable)
Closes #11699
Risk
Low Risk - This is a new read-only endpoint in the public-api package. No existing functionality is modified. No on-chain transactions involved.
None. This is a new informational endpoint that returns static chain metadata.
Testing
Engineering
Build and run the public-api locally:
Test the new endpoints:
Run smoke tests:
Verify OpenAPI docs include the new endpoints at
/docsOperations
This is a backend-only API endpoint with no user-facing UI changes.
Screenshots (if applicable)
N/A - Backend API changes only
Summary by CodeRabbit
New Features
Documentation
Tests
✏️ Tip: You can customize this high-level summary in your review settings.