- 
          
- 
                Notifications
    You must be signed in to change notification settings 
- Fork 252
feat(assets-controllers): add searchTokens function #7004
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
| decimals: 6, | ||
| name: 'Tether USD', | ||
| occurrences: 11, | ||
| aggregators: [ | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need to send this over? Could we minimize the data we return to the UI?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I meant aggregators
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is required since it’s also part of the tokenList state. However, it’s not actually used in the UI , I just wanted to keep it consistent with the existing tokenList state structure.
Explanation
What is the current state of things and why does it need to change?
Currently, the assets-controllers package provides functionality to fetch token lists and metadata for individual networks, but lacks the ability to search for tokens across multiple blockchain networks simultaneously. Users and applications need to search for tokens by name, symbol, or address across different chains (Ethereum, Polygon, Solana, etc.) in a unified way, which requires multiple separate API calls with the existing implementation.
What is the solution your changes offer and how does it work?
This PR introduces a new
searchTokensfunction that enables cross-chain token search functionality using CAIP (Chain Agnostic Improvement Proposal) format chain IDs. The solution includes:searchTokensfunction: Accepts an array of CAIP chain IDs (e.g.,['eip155:1', 'eip155:137', 'solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp']) and a search query stringgetTokenSearchURLfunction that properly encodes chain IDs and query parameters{ count: number, data: unknown[] }format for consistent API responsesThe function makes a single API call to the
/tokens/searchendpoint, making it more efficient than multiple individual network searches.Are there any changes whose purpose might not obvious to those unfamiliar with the domain?
{ count: 0, data: [] }on errors rather than throwing, which prevents search failures from breaking the user experienceReferences
Checklist
Note
Introduces
searchTokensto query tokens across multiple networks using CAIP chain IDs, exports it, and adds comprehensive tests and changelog entry.src/token-service.ts):searchTokens(chainIds: CaipChainId[], query, { limit })using/tokens/searchandhandleFetch; returns{ count, data }with graceful error handling.getTokenSearchURLand CAIP chain ID support; importCaipChainId.searchTokensfromsrc/index.ts.src/token-service.test.ts):limit, query encoding, empty/invalid responses, and network/HTTP errors.searchTokensfor multi-network searches via CAIP IDs.Written by Cursor Bugbot for commit bf6224c. This will update automatically on new commits. Configure here.