Supported Assets
The SDK ships with a built-in dataset of all supported assets and chains. Functions in this module let you load the data, look up assets by identifier, filter by chain, and search by name or symbol.
Import
import {
loadAssetsData,
getAllAssets,
getAllAssetsArray,
getAllChains,
getAssetByCaip19,
getAssetsByChain,
getChainByCaip2,
getCommonAssets,
searchAssets,
getChainName,
CHAIN_NAMES,
COMMON_ASSETS,
} from '@silentswap/sdk';Initialization
Call loadAssetsData() once at app startup before using any other asset function. It asynchronously loads the asset dataset and caches it in memory.
import { loadAssetsData } from '@silentswap/sdk';
await loadAssetsData();All other functions in this module are synchronous and will throw if called before loadAssetsData() resolves.
Types
AssetInfo
interface AssetInfo {
caip19: Caip19; // CAIP-19 identifier (e.g. "eip155:1/erc20:0xA0b8...")
coingeckoId: string; // CoinGecko token ID
name: string; // Human-readable name (e.g. "USD Coin")
symbol: string; // Ticker symbol (e.g. "USDC")
decimals: number; // Token decimals (e.g. 6 for USDC)
gradient: [string, string]; // Hex gradient colors for UI
style?: string; // Optional CSS style hint
ext?: string; // Optional icon file extension
precision?: number; // Optional display precision
}ChainInfo
interface ChainInfo {
caip2: Caip2; // CAIP-2 chain identifier (e.g. "eip155:1")
name: string; // Chain name (e.g. "Ethereum")
coingeckoPlatformId?: string;
coingeckoId?: string;
shortName?: string;
native?: {
slip44: number;
decimals: number;
symbol: string;
};
nativeCoinId?: string;
}API Reference
loadAssetsData
Loads the asset dataset. Must be called once before using other functions.
function loadAssetsData(): Promise<AssetsData>Returns AssetsData — an object containing chains and assets records.
getAllAssets
Returns all supported assets as a record keyed by CAIP-19 identifier.
function getAllAssets(): Record<Caip19, AssetInfo>const assets = getAllAssets();
const usdc = assets['eip155:1/erc20:0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48'];
console.log(usdc?.symbol); // "USDC"getAllAssetsArray
Returns all supported assets as a flat array — useful for iteration, mapping, and filtering.
function getAllAssetsArray(): AssetInfo[]const assets = getAllAssetsArray();
console.log(`${assets.length} assets supported`);getAssetByCaip19
O(1) lookup of a single asset by its CAIP-19 identifier.
function getAssetByCaip19(caip19: Caip19): AssetInfo | undefinedimport { getAssetByCaip19 } from '@silentswap/sdk';
const eth = getAssetByCaip19('eip155:1/slip44:60');
console.log(eth?.name); // "Ethereum"getAssetsByChain
Returns all assets on a given EVM chain, filtered by numeric chain ID.
function getAssetsByChain(chainId: string, ingress?: boolean): AssetInfo[]chainId(string): EVM chain ID (e.g.'1'for Ethereum,'137'for Polygon)ingress(boolean, optional): Defaults totrue
import { getAssetsByChain } from '@silentswap/sdk';
const polygonAssets = getAssetsByChain('137');
console.log(`Polygon has ${polygonAssets.length} supported assets`);searchAssets
Full-text search across asset symbol, name, and CAIP-19 identifier. Case-insensitive.
function searchAssets(query: string): AssetInfo[]import { searchAssets } from '@silentswap/sdk';
const results = searchAssets('usdc');
// Returns all USDC variants across chains
results.forEach(a => console.log(`${a.symbol} on ${a.caip19}`));getCommonAssets
Returns a curated list of popular tokens (BTC, ETH, USDC, USDT, etc. across major chains).
function getCommonAssets(): AssetInfo[]import { getCommonAssets } from '@silentswap/sdk';
const popular = getCommonAssets();
popular.forEach(a => console.log(`${a.symbol} — ${a.name}`));COMMON_ASSETS is a read-only array alias for the same data:
import { COMMON_ASSETS } from '@silentswap/sdk';
COMMON_ASSETS.forEach(a => console.log(a.symbol));getAllChains
Returns all supported chains as a record keyed by CAIP-2 identifier.
function getAllChains(): Record<Caip2, ChainInfo>import { getAllChains } from '@silentswap/sdk';
const chains = getAllChains();
Object.values(chains).forEach(c => console.log(c.name));getChainByCaip2
Look up chain metadata by CAIP-2 identifier.
function getChainByCaip2(caip2: Caip2): ChainInfo | undefinedimport { getChainByCaip2 } from '@silentswap/sdk';
const ethereum = getChainByCaip2('eip155:1');
console.log(ethereum?.name); // "Ethereum"
console.log(ethereum?.native?.symbol); // "ETH"getChainName
Returns a human-readable chain name from a numeric chain ID string.
function getChainName(chainId: string): stringimport { getChainName } from '@silentswap/sdk';
console.log(getChainName('1')); // "Ethereum"
console.log(getChainName('137')); // "Polygon"
console.log(getChainName('56')); // "BNB Smart Chain"CHAIN_NAMES is a read-only record mapping chain ID → name:
import { CHAIN_NAMES } from '@silentswap/sdk';
console.log(CHAIN_NAMES['43114']); // "Avalanche"Examples
Build a Token Selector
import { loadAssetsData, getAssetsByChain, searchAssets, getCommonAssets } from '@silentswap/sdk';
await loadAssetsData();
// Show popular tokens initially
const popular = getCommonAssets();
// When user selects a chain, filter to that chain
const ethereumTokens = getAssetsByChain('1');
// When user types in search box
const matches = searchAssets('dai');Display Supported Chains
import { loadAssetsData, getAllChains } from '@silentswap/sdk';
await loadAssetsData();
const chains = getAllChains();
for (const [caip2, chain] of Object.entries(chains)) {
console.log(`${chain.name} (${caip2})`);
if (chain.native) {
console.log(` Native: ${chain.native.symbol} (${chain.native.decimals} decimals)`);
}
}Resolve Asset from User Input
import { loadAssetsData, getAssetByCaip19, searchAssets } from '@silentswap/sdk';
await loadAssetsData();
// Direct lookup when you have a CAIP-19
const asset = getAssetByCaip19('eip155:1/erc20:0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48');
if (asset) {
console.log(`${asset.name} (${asset.symbol}) — ${asset.decimals} decimals`);
}
// Fuzzy lookup when you have user text
const [first] = searchAssets('wrapped bitcoin');
if (first) {
console.log(`Found: ${first.symbol} on ${first.caip19}`);
}Related
- Asset Utilities — chain detection, token type checks, and CAIP-19 helpers for
AssetInfoobjects