Viem-compatible abstraction library to simplify the interaction with multiple blockchains via user-friendly high level APIs.
- Support all chains listed in Viem library.
- Customizable plugins and adapters.
- Core plugins to query onchain portfolio, token metadata, token prices...
- Chain configuration with modifiable RPC URL settings.
- Plug-n-play different adapters to plugins depend on the use cases.
Install the dependency
npm install chainsmith-sdk
| Name | Chain | Interfaces |
|---|---|---|
| CoinMarketcapAdapter | Multichain | IMarketDataAdapter |
| ShadowExchangeAdapter | Sonic | IMarketDataAdapter, IOnchainTokenAdapter |
| ShadowExchangeAdapter | Sonic | IMarketDataAdapter, IOnchainTokenAdapter |
| ShadowExchangeApiAdapter | Sonic | IMarketDataAdapter |
| UniswapSdkAdapter | EVM chains | IMarketDataAdapter |
| AlchemyAdapter | Multichain | IOnchainTokenAdapter |
| ReservoirAdapter | Multichain | IOnchainNftAdapter |
| PaintSwapAdapter | Sonic | IOnchainNftAdapter |
| BeetsApiAdapter | Sonic | IYieldAdapter |
| MetropolisApiAdapter | Sonic | IYieldAdapter |
| OriginApiAdapter | Sonic | IYieldAdapter |
| SiloV2ApiAdapter | Sonic | IYieldAdapter |
| EvmscanAdapter | EVM chains | IOnchainActivityAdapter |
The following example demonstrates how to initialize the SDK using Alchemy as the primary RPC provider for all registered chains.
import { initChainsmithSdk } from 'chainsmith-sdk';
import { alchemy } from 'chainsmith-sdk/rpc';
import { buildEvmChains } from 'chainsmith-sdk/utils';
const ALCHEMY_API_KEY = process.env.ALCHEMY_API_KEY || '';
// Helper method to build all EVM chains with Alchemy as the RPC provider.
export function buildDefaultChains(chainNames: TChainName[]) {
return buildEvmChains(chainNames, alchemy(ALCHEMY_API_KEY))
}
// Build Base, Mainnet, and Optimism chains.
const chains = buildDefaultChains(['sonic', 'mainnet', 'base', 'optimism']);
// Initialize the Chainsmith SDK.
const sdk = initChainsmithSdk(chains);The alchemy function is a built-in RPC endpoint provider in the SDK. If you need to customize the method, refer to the alchemy example in the SDK source code.
If you want to use a custom RPC provider for a specific chain (e.g., Sonic chain), use buildChainsWithCustomRpcUrls to map TChainName to a custom RPC URL:
const chains = buildChainsWithCustomRpcUrls({ sonic: 'https://rpc.soniclabs.com' }, 'evm');The example below fetches a multichain token portfolio using CoinMarketcap as the market data source and Alchemy for on-chain token activities.
const portfolio = await sdk.portfolio.getMultichainTokenPortfolio([
AdapterRegistry.CoinMarketcap,
AdapterRegistry.Alchemy,
])(Wallets.ETH_MAINNET_WALLET_JESSE);The order of the adapters in the plugin API must match the required interface order:
getMultichainTokenPortfolio: WithManyAdapters<
[IMarketDataAdapter, IOnchainTokenAdapter],
IGetMultichainTokenPortfolio
>;In cases where multiple data sources are required for fallback, the SDK provides extended adapters for advanced use cases.
The multiple function allows using two different market data adapters as fallback providers. The first adapter is prioritized, and if it fails to fetch the required data, the second adapter is used.
In the example below, ShadowExchange is prioritized for fetching token price data. If no data is found, CoinMarketcap is used as a fallback.
const portfolio = await sdk.portfolio.getChainTokenPortfolio([
multiple([AdapterRegistry.ShadowExchange, AdapterRegistry.CoinMarketcap]),
AdapterRegistry.ShadowExchange,
])(Wallets.SONIC_WALLET_BEETS_TREASURY);This approach ensures better reliability by using decentralized exchange (DEX) price data first and falling back to centralized market data if needed.