npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@cfxdevkit/defillama

v0.1.3

Published

A TypeScript library for interacting with Defillama API

Downloads

35

Readme

@cfxdevkit/defillama

A TypeScript library for interacting with the DeFi Llama API, providing easy access to DeFi protocol and chain TVL (Total Value Locked) data with optional analysis features.

npm version Build Status Coverage Status npm bundle size License: MIT TypeScript Node Version PRs Welcome

Features

  • 🚀 Full TypeScript support with comprehensive type definitions
  • 📊 Access to DeFi Llama's protocol and chain TVL data
  • 📈 Optional data analysis and formatting capabilities
  • 🔍 Detailed error handling and logging
  • 📝 Well-documented API methods
  • ⚡ Modern ES6+ syntax

Installation

npm install @cfxdevkit/defillama

Quick Start

import { DeFiLlama } from '@cfxdevkit/defillama';

const defiLlama = new DeFiLlama();

// Get TVL data for a specific protocol
const protocolTVL = await defiLlama.getProtocolTVL('uniswap');

// Get historical TVL data for a chain with analysis
const chainTVL = await defiLlama.getHistoricalChainTVL('ethereum', true);

Examples

Error Handling

The library includes comprehensive error handling for invalid inputs:

const defiLlama = new DeFiLlama();

try {
  // This will throw an error for non-existent protocol
  await defiLlama.getProtocolTVL('non-existent-protocol');
} catch (error) {
  console.error('Error:', error.message);
  // Output: Error: HTTP error! status: 400
}

try {
  // This will throw an error for invalid chain
  await defiLlama.getHistoricalChainTVL('invalid-chain');
} catch (error) {
  console.error('Error:', error.message);
  // Output: Error: HTTP error! status: 400
}

Protocol Methods

Get All Protocols

const protocols = await defiLlama.getProtocols();
// Returns array of protocols with details like:
// [
//   {
//     id: '2269',
//     name: 'Binance CEX',
//     url: 'https://www.binance.com',
//     description: 'Binance is a cryptocurrency exchange...',
//     chain: 'Multi-Chain',
//     tvl: 144318054315.48734,
//     chainTvls: {
//       Ethereum: 40481829144.37302,
//       Bitcoin: 55798161484.458565,
//       // ... other chains
//     }
//   },
//   // ... other protocols
// ]

Get Protocol TVL with Analysis

// Get formatted TVL data with analysis
const swappiTVL = await defiLlama.getProtocolTVL('swappi', true);
// Returns detailed analysis:
// {
//   protocolInfo: {
//     name: 'Swappi',
//     currentChainTvls: { Conflux: '$9.71M' }
//     // ... other protocol info
//   },
//   tvlAnalysis: {
//     overall: {
//       currentTVL: '$9.71M',
//       averageTVL: '$14.39M',
//       totalChange: '-76.15%'
//     },
//     yearlyAnalysis: [
//       {
//         year: 2023,
//         average: '$15.94M',
//         percentageChange: '+348.77%'
//       }
//       // ... other years
//     ]
//   }
// }

Get Current Protocol TVL

const currentTVL = await defiLlama.getCurrentProtocolTVL('abc-pool');
// Returns: 9611050.44

Chain Methods

Get All Chains

const chains = await defiLlama.getChains();
// Returns array of chains with details like:
// [
//   {
//     name: 'Harmony',
//     chainId: 1666600000,
//     tvl: 1790390.10,
//     tokenSymbol: 'ONE'
//   }
//   // ... other chains
// ]

Get Historical Chain TVL with Analysis

const ethereumTVL = await defiLlama.getHistoricalChainTVL('ethereum', true);
// Returns detailed analysis:
// {
//   chainAnalysis: {
//     overall: {
//       currentTVL: '$56.24B',
//       averageTVL: '$29.97B',
//       totalChange: '+13918890.65%'
//     },
//     yearlyAnalysis: [
//       {
//         year: 2023,
//         average: '$20.70B',
//         percentageChange: '+429.86%'
//       }
//       // ... other years
//     ]
//   }
// }

API Reference

Protocols

Get All Protocols

const protocols = await defiLlama.getProtocols();

Get Protocol TVL

// Get raw TVL data
const rawTVL = await defiLlama.getProtocolTVL('protocol-name');

// Get formatted TVL data with analysis
const formattedTVL = await defiLlama.getProtocolTVL('protocol-name', true);

Get Current Protocol TVL

const currentTVL = await defiLlama.getCurrentProtocolTVL('protocol-name');

Chains

Get All Chains

const chains = await defiLlama.getChains();

Get Historical Chain TVL

// Get raw historical TVL data
const rawChainTVL = await defiLlama.getHistoricalChainTVL('chain-name');

// Get formatted historical TVL data with analysis
const formattedChainTVL = await defiLlama.getHistoricalChainTVL('chain-name', true);

Development

Prerequisites

  • Node.js >= 16.0.0
  • npm

Setup

  1. Clone the repository:
git clone https://github.com/cfxdevkit/defillama.git
cd defillama
  1. Install dependencies:
npm install

Available Scripts

  • npm run build - Build the library
  • npm run test - Run tests
  • npm run lint - Lint the code
  • npm run format - Format the code
  • npm run docs - Generate documentation
  • npm run example - Run example usage script

Running Examples

The library includes example usage in the examples directory. To run the examples:

npm run example

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/AmazingFeature)
  3. Commit your changes (git commit -m 'Add some AmazingFeature')
  4. Push to the branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

Links

License

This project is licensed under the MIT License - see the LICENSE file for details.

Acknowledgments