Skip to content

About

Node.js example showing how to scrape DeFi data from DefiLlama using Apify

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Latest commit

 

History

3 Commits

Folders and files

Repository files navigation

How to Scrape DefiLlama DeFi Data in Node.js

This example shows how to extract DeFi data from DefiLlama using the DefiLlama Scraper actor on Apify — no browser automation or custom scraping code required.

DefiLlama scraper results showing chains with TVL, fees, and token data

What this example does

  • Calls the piotrv1001/defillama-scraper Apify actor with a simple input
  • Waits for the actor run to finish
  • Fetches results from the Apify dataset
  • Prints each item to the console

The actor handles all data collection across DefiLlama's endpoints: chains, protocols, DEXes, fees, and stablecoins.

Prerequisites

Installation

npm install

Environment setup

Copy .env.example to .env and add your Apify API token:

cp .env.example .env

Then open .env and set your token:

APIFY_TOKEN=your_apify_token_here

Usage

npm start

Code example

import { ApifyClient } from 'apify-client';
import 'dotenv/config';

// Initialize the ApifyClient with your Apify API token
// Set APIFY_TOKEN in your .env file (copy .env.example to get started)
const client = new ApifyClient({
    token: process.env.APIFY_TOKEN,
});

// Prepare Actor input
const input = {};

// Run the Actor and wait for it to finish
const run = await client.actor("piotrv1001/defillama-scraper").call(input);

// Fetch and print Actor results from the run's dataset (if any)
console.log('Results from dataset');
console.log(`💾 Check your data here: https://console.apify.com/storage/datasets/${run.defaultDatasetId}`);
const { items } = await client.dataset(run.defaultDatasetId).listItems();
items.forEach((item) => {
    console.dir(item);
});

// 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/js/docs

Example output

See sample-output.json for a full example. The actor returns items across five data types:

Type Key fields
Chains type, name, tvl, tokenSymbol, chainId, tvlChange1d, tvlChange7d, tvlChange30d, fees24h, fees7d, fees30d
Protocols type, name, slug, symbol, category, chains, tvl, tvlChange1h, tvlChange1d, tvlChange7d, url, description, logo
DEXes type, name, slug, chains, volume24h, volume7d, volume30d, volumeChange1d, volumeChange7d, volumeChange1m
Fees type, name, slug, category, chains, fees24h, fees7d, fees30d, fees1y, feesAllTime, feesChange1d, feesChange7d
Stablecoins type, name, symbol, pegType, pegMechanism, price, circulating, circulatingPrevDay, circulatingPrevWeek, chains

Use cases

  • DeFi market monitoring — track TVL, volume, and fee trends across chains and protocols in real time
  • Portfolio & risk analysis — compare protocol health metrics and stablecoin circulation for investment decisions
  • Research & reporting — pull structured DeFi data into spreadsheets, dashboards, or data pipelines
  • Stablecoin tracking — monitor peg stability and circulating supply changes across chains
  • Competitive intelligence — compare DEX volumes, protocol fees, and chain growth over time

Try the actor on Apify

Open the DefiLlama Scraper on Apify

Related resources

License

MIT

About

Node.js example showing how to scrape DeFi data from DefiLlama using Apify

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages