Official TypeScript/JavaScript SDK for the DefiLlama API. Access DeFi protocol data including TVL, prices, yields, volumes, fees, bridges, and more.
npm install @defillama/apiyarn add @defillama/apipnpm add @defillama/apiimport { DefiLlama } from "@defillama/api";
// Free tier
const client = new DefiLlama();
// Pro tier (required for premium endpoints)
const proClient = new DefiLlama({
apiKey: "your-api-key",
});
// Get all protocols
const protocols = await client.tvl.getProtocols();
// Get current token prices
const prices = await client.prices.getCurrentPrices([
"ethereum:0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",
"coingecko:bitcoin",
]);interface DefiLlamaConfig {
apiKey?: string; // Pro API key from https://defillama.com/pro-api
timeout?: number; // Request timeout in ms (default: 30000)
}- TVL - Total Value Locked data
- Prices - Token price data
- Stablecoins - Stablecoin market data
- Yields - Yield farming & lending rates π
- Volumes - DEX & derivatives volume
- Fees - Protocol fees & revenue
- Emissions - Token unlock schedules π
- Bridges - Cross-chain bridge data π
- Ecosystem - Categories, oracles, treasuries π
- ETFs - Bitcoin & Ethereum ETF data π
- DAT - Digital Asset Treasury data π
- Account - API usage management π
π = Requires Pro API key
Total Value Locked data for protocols and chains.
Get all protocols with current TVL.
const protocols = await client.tvl.getProtocols();
// Returns: Protocol[]Get detailed protocol information including historical TVL.
const aave = await client.tvl.getProtocol("aave");
// Returns: ProtocolDetailsGet only current TVL for a protocol.
const tvl = await client.tvl.getTvl("uniswap");
// Returns: numberGet current TVL for all chains.
const chains = await client.tvl.getChains();
// Returns: Chain[]Get historical TVL data.
// All chains combined
const allHistory = await client.tvl.getHistoricalChainTvl();
// Specific chain
const ethHistory = await client.tvl.getHistoricalChainTvl("Ethereum");Get protocols holding a specific token.
const holders = await proClient.tvl.getTokenProtocols("ETH");
// Returns: TokenProtocolHolding[]Get token inflows/outflows between timestamps.
const inflows = await proClient.tvl.getInflows(
"lido",
1704067200, // start timestamp
1704153600, // end timestamp
"ETH,USDC" // optional tokens to exclude
);Get asset breakdown for all chains.
const assets = await proClient.tvl.getChainAssets();
// Returns: ChainAssetsResponseToken price data and historical charts.
Get current prices for multiple tokens.
const prices = await client.prices.getCurrentPrices([
"ethereum:0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48", // USDC
"coingecko:bitcoin",
"solana:So11111111111111111111111111111111111111112", // SOL
]);
// Returns: CoinPricesResponseGet prices at a specific timestamp.
const prices = await client.prices.getHistoricalPrices(1704067200, [
"ethereum:0xdac17f958d2ee523a2206206994597c13d831ec7",
]);Get multiple historical price points in one request.
const prices = await client.prices.getBatchHistoricalPrices({
"ethereum:0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48": [
1704067200, 1704153600, 1704240000,
],
});Get price chart data at regular intervals.
const chart = await client.prices.getChart(["coingecko:ethereum"], {
start: 1704067200,
period: "1d",
span: 30,
});Options:
| Parameter | Type | Description |
|---|---|---|
| start | number | Unix timestamp of earliest data point |
| end | number | Unix timestamp of latest data point |
| span | number | Number of data points to return |
| period | string | Duration between points (e.g., "4h", "1d", "1W") |
| searchWidth | string | Time range to search |
Get percentage price change over a period.
const change = await client.prices.getPercentageChange(["coingecko:bitcoin"], {
period: "24h",
});Get the earliest recorded price for tokens.
const first = await client.prices.getFirstPrices([
"ethereum:0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48",
]);Get the closest block to a given timestamp.
const block = await client.prices.getBlockAtTimestamp("ethereum", 1704067200);
// Returns: { height: number; timestamp: number }Stablecoin market cap and dominance data.
Get all stablecoins with market cap.
const stables = await client.stablecoins.getStablecoins(true); // include prices
// Returns: StablecoinsResponseGet historical market cap for all stablecoins combined.
const charts = await client.stablecoins.getAllCharts();
// Returns: StablecoinChartDataPoint[]Get historical market cap for stablecoins on a specific chain.
const ethCharts = await client.stablecoins.getChartsByChain("Ethereum");Get detailed stablecoin information.
const usdt = await client.stablecoins.getStablecoin("1"); // USDT
const usdc = await client.stablecoins.getStablecoin("2"); // USDCGet current stablecoin market cap for all chains.
const chains = await client.stablecoins.getChains();
// Returns: StablecoinChainMcap[]Get historical prices for all stablecoins.
const prices = await client.stablecoins.getPrices();Get stablecoin dominance data for a chain.
const dominance = await proClient.stablecoins.getDominance("ethereum", 1);Yield farming, lending, staking, and perpetual funding rates. All endpoints require Pro API key.
Get all yield pools with current APY.
const pools = await proClient.yields.getPools();
// Returns: { status: string; data: YieldPool[] }Get legacy yield pools format with additional fields.
const pools = await proClient.yields.getPoolsOld();Get historical APY and TVL for a specific pool.
const chart = await proClient.yields.getPoolChart("pool-uuid-here");Get lending/borrowing pools with supply and borrow rates.
const borrowPools = await proClient.yields.getBorrowPools();Get historical lending and borrowing rates.
const chart = await proClient.yields.getLendBorrowChart("pool-uuid-here");Get perpetual futures funding rates.
const perps = await proClient.yields.getPerps();
// Returns: { status: string; data: PerpPool[] }Get liquid staking derivative exchange rates.
const lsdRates = await proClient.yields.getLsdRates();
// Returns: LsdRate[]DEX, options, and derivatives trading volume data.
Get overview of all DEX volume data.
const overview = await client.volumes.getDexOverview();
// With options
const overview = await client.volumes.getDexOverview({
excludeTotalDataChart: true,
dataType: "dailyVolume",
});Get DEX volume for a specific chain.
const ethVolume = await client.volumes.getDexOverviewByChain("Ethereum");Get summary for a specific DEX protocol.
const uniswap = await client.volumes.getDexSummary("uniswap");Get overview of options volume data.
const options = await client.volumes.getOptionsOverview();Get options volume for a specific chain.
const ethOptions = await client.volumes.getOptionsOverviewByChain("Ethereum");Get summary for a specific options protocol.
const derive = await client.volumes.getOptionsSummary("derive");Get overview of derivatives volume data.
const derivatives = await proClient.volumes.getDerivativesOverview();Get summary for a specific derivatives protocol.
const gmx = await proClient.volumes.getDerivativesSummary("gmx");Protocol fees and revenue data.
import { FeeDataType } from "@defillama/api";
FeeDataType.DAILY_FEES; // "dailyFees"
FeeDataType.DAILY_REVENUE; // "dailyRevenue"
FeeDataType.DAILY_HOLDERS_REVENUE; // "dailyHoldersRevenue"
FeeDataType.DAILY_SUPPLY_SIDE_REVENUE;
FeeDataType.DAILY_BRIBES_REVENUE;
FeeDataType.DAILY_TOKEN_TAXES;
FeeDataType.DAILY_APP_FEES;
FeeDataType.DAILY_APP_REVENUE;
FeeDataType.DAILY_EARNINGS;Get fees overview across all protocols.
const fees = await client.fees.getOverview();
// With data type
const revenue = await client.fees.getOverview({
dataType: FeeDataType.DAILY_REVENUE,
});Get fees overview for a specific chain.
const ethFees = await client.fees.getOverviewByChain("Ethereum");Get fees summary for a specific protocol.
const uniswapFees = await client.fees.getSummary("uniswap");Get historical fees chart.
const chart = await proClient.fees.getChart();
// For specific chain
const ethChart = await proClient.fees.getChartByChain("Ethereum");
// For specific protocol
const protocolChart = await proClient.fees.getChartByProtocol("aave");Get fees breakdown by chain within a protocol.
const breakdown = await proClient.fees.getChartByProtocolChainBreakdown("aave");Get fees breakdown by version within a protocol.
const breakdown = await proClient.fees.getChartByProtocolVersionBreakdown(
"uniswap"
);Get fees breakdown by protocol within a chain.
const breakdown = await proClient.fees.getChartByChainProtocolBreakdown(
"Ethereum"
);Get fees breakdown by chain across all protocols.
const breakdown = await proClient.fees.getChartChainBreakdown();Get fees metrics.
const metrics = await proClient.fees.getMetrics();
const chainMetrics = await proClient.fees.getMetricsByChain("Ethereum");
const protocolMetrics = await proClient.fees.getMetricsByProtocol("aave");Token unlock schedules and vesting data. All endpoints require Pro API key.
Get all tokens with unlock schedules.
const emissions = await proClient.emissions.getAll();
// Returns: EmissionToken[]Each token includes:
- Emission events and schedules
- Circulating supply metrics
- Next unlock event
- Daily unlock rate
- Market cap data
Get detailed vesting schedule for a specific protocol.
const arbitrum = await proClient.emissions.getByProtocol("arbitrum");
// Returns: EmissionDetailResponseResponse includes:
documentedData- Emission timeline with category breakdownmetadata- Sources, events, notessupplyMetrics- Max supply, adjusted supplycategories- Allocation categories and sectionsunlockUsdChart- Historical unlock values in USD
Cross-chain bridge volume and transaction data. All endpoints require Pro API key.
Get all bridges with volume data.
const bridges = await proClient.bridges.getAll();
// Include chain breakdown
const bridges = await proClient.bridges.getAll({ includeChains: true });Get detailed bridge information.
const bridge = await proClient.bridges.getById(1);
// Returns: BridgeDetail with volume breakdown, tx counts, chain breakdownGet bridge volume for a specific chain.
const volume = await proClient.bridges.getVolumeByChain("Ethereum");
// Returns: BridgeVolumeDataPoint[]Get day statistics for bridges on a specific chain.
const stats = await proClient.bridges.getDayStats(1704067200, "Ethereum");
// Returns token and address statisticsGet bridge transactions.
const txs = await proClient.bridges.getTransactions(1, {
limit: 100,
startTimestamp: 1704067200,
endTimestamp: 1704153600,
sourceChain: "Ethereum",
address: "0x...",
});Ecosystem-level data. All endpoints require Pro API key.
Get TVL grouped by protocol category.
const categories = await proClient.ecosystem.getCategories();
// Returns historical chart, category mappings, market share percentagesGet protocol fork relationships and TVL.
const forks = await proClient.ecosystem.getForks();
// Returns forks list with parent protocol mappingsGet oracle usage data across protocols.
const oracles = await proClient.ecosystem.getOracles();
// Returns oracle TVL, protocol counts, dominance metricsGet company/VC/fund treasury and holdings data.
const entities = await proClient.ecosystem.getEntities();
// Returns: Entity[]Get protocol treasury balances.
const treasuries = await proClient.ecosystem.getTreasuries();
// Returns: Treasury[]Get security incidents and exploits database.
const hacks = await proClient.ecosystem.getHacks();
// Returns: Hack[] with date, amount, technique, classificationGet funding rounds database.
const raises = await proClient.ecosystem.getRaises();
// Returns: { raises: Raise[] }Bitcoin and Ethereum ETF data. All endpoints require Pro API key.
Get Bitcoin ETF overview.
const btcEtfs = await proClient.etfs.getOverview();
// Returns: EtfOverviewItem[]Get Ethereum ETF overview.
const ethEtfs = await proClient.etfs.getOverviewEth();Get Bitcoin ETF flow history.
const history = await proClient.etfs.getHistory();
// Returns: EtfHistoryItem[]Get Ethereum ETF flow history.
const history = await proClient.etfs.getHistoryEth();Get FDV performance data.
const perf = await proClient.etfs.getFdvPerformance("30");
// period: "7" | "30" | "ytd" | "365"Digital Asset Treasury data and institutional holdings. All endpoints require Pro API key.
Get comprehensive DAT data for all institutions.
const data = await proClient.dat.getInstitutions();
// Returns metadata, holdings by asset, mNAV dataGet detailed DAT data for a specific institution.
const mstr = await proClient.dat.getInstitution("MSTR");
// Returns holdings, flows, mNAV, stats, OHLCV, transactionsAPI account management. Requires Pro API key.
Get API usage statistics.
const usage = await proClient.account.getUsage();
// Returns: { creditsLeft: number }The SDK provides custom error classes for different scenarios:
import {
DefiLlamaError,
ApiKeyRequiredError,
RateLimitError,
NotFoundError,
ApiError,
} from "@defillama/api";
try {
const data = await client.yields.getPools();
} catch (error) {
if (error instanceof ApiKeyRequiredError) {
console.log("Pro API key required for this endpoint");
} else if (error instanceof RateLimitError) {
console.log(`Rate limited. Retry after ${error.retryAfter} seconds`);
} else if (error instanceof NotFoundError) {
console.log("Resource not found");
} else if (error instanceof ApiError) {
console.log(`API error: ${error.statusCode} - ${error.message}`);
}
}All types are exported from the main package:
import type {
// TVL
Protocol,
ProtocolDetails,
Chain,
TokenProtocolHolding,
// Prices
CoinPrice,
CoinPricesResponse,
ChartOptions,
// Stablecoins
Stablecoin,
StablecoinDetails,
// Yields
YieldPool,
BorrowPool,
PerpPool,
LsdRate,
// Volumes
DexOverviewResponse,
DexSummaryResponse,
// Fees
FeesOverviewResponse,
FeesSummaryResponse,
// Emissions
EmissionToken,
EmissionDetailResponse,
// Bridges
BridgeSummary,
BridgeDetail,
BridgeTransaction,
// Ecosystem
Entity,
Treasury,
Hack,
Raise,
// ETFs
EtfOverviewItem,
EtfHistoryItem,
// DAT
DatInstitutionsResponse,
DatInstitutionResponse,
// Config
DefiLlamaConfig,
} from "@defillama/api";import { AdapterType, FeeDataType, VolumeDataType } from "@defillama/api";
// Adapter Types
AdapterType.DEXS; // "dexs"
AdapterType.FEES; // "fees"
AdapterType.AGGREGATORS; // "aggregators"
AdapterType.DERIVATIVES; // "derivatives"
AdapterType.AGGREGATOR_DERIVATIVES; // "aggregator-derivatives"
AdapterType.OPTIONS; // "options"
AdapterType.BRIDGE_AGGREGATORS; // "bridge-aggregators"
AdapterType.OPEN_INTEREST; // "open-interest"
// Volume Data Types
VolumeDataType.DAILY_VOLUME; // "dailyVolume"
VolumeDataType.TOTAL_VOLUME; // "totalVolume"
VolumeDataType.DAILY_NOTIONAL_VOLUME;
VolumeDataType.DAILY_PREMIUM_VOLUME;
VolumeDataType.DAILY_BRIDGE_VOLUME;
VolumeDataType.OPEN_INTEREST_AT_END;- Node.js >= 18.0.0
- TypeScript 5.x (for TypeScript users)
MIT