isTokenListed
The isTokenListed
method checks if a given token address is available for swaps in the current chain's token list.
Signature
isTokenListed(tokenAddress: string): boolean
Parameters
tokenAddress
: The address of the token to check- Must be a valid Ethereum address starting with "0x"
- Case-insensitive (both uppercase and lowercase addresses work)
Returns
Returns a boolean:
true
: Token is listed and available for swapsfalse
: Token is not listed
Examples
Basic Usage
const symphony = new Symphony();
// Check if USDC is listed
const isUSDCListed = symphony.isTokenListed("0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48");
console.log(isUSDCListed); // true
// Check if an unlisted token is available
const isUnlistedTokenListed = symphony.isTokenListed("0xUnlistedTokenAddress");
console.log(isUnlistedTokenListed); // false
Usage with getRoute
You can use isTokenListed
to verify tokens before attempting to get a route:
const tokenIn = "0x1234..."; // Some token address
const tokenOut = "0x5678..."; // Another token address
// Check if both tokens are listed before getting route
if (symphony.isTokenListed(tokenIn) && symphony.isTokenListed(tokenOut)) {
const route = await symphony.getRoute(tokenIn, tokenOut, "1.0");
// ... proceed with swap
} else {
console.log("One or both tokens are not listed for swapping");
}
If you try to get route using a non-listed address
getRoute
will log an error indicating that the token is not listed and call will fail.
Error Handling
The method will log an error to console if:
- The token address is not a string
- The token address doesn't start with "0x"
However, in these cases, it will still return false
rather than throwing an error.