Are you looking to access decentralized finance (DeFi) protocol data easily? If so, you’re in the right place. This guide introduces Moralis’ DeFi API – your go-to solution for querying DeFi data. With the DeFi API, you can effortlessly fetch protocol data for any wallet with just a single API call. Eager to get going? Here’s how to quickly retrieve a summary of the DeFi protocols a wallet interacts with:
import fetch from ‘node-fetch’;
const options = {
method: 'GET',
headers: {
accept: 'application/json',
'X-API-Key': 'YOUR_API_KEY'
},
};
fetch('https://deep-index.moralis.io/api/v2.2/wallets/0xcB1C1FdE09f811B294172696404e88E658659905/defi/summary?chain=eth', options)
.then(response => response.json())
.then(response => console.log(response))
.catch(err => console.error(err));
Running the code above provides a summary of all DeFi protocols linked to a wallet, including the number of positions, total USD value, unclaimed rewards, protocol names, logos, and more. Here’s an example of the output:
{
active_protocols: 8,
total_positions: 12,
total_usd_value: 871.6550972487607,
total_unclaimed_usd_value: 26.31655680118138,
protocols: [
{
protocol_name: 'Uniswap v3',
protocol_id: 'uniswap-v3',
protocol_url: 'https://app.uniswap.org',
protocol_logo: 'https://cdn.moralis.io/defi/uniswap.png',
total_usd_value: 433.6700616074799,
total_unclaimed_usd_value: 26.31655680118138,
positions: 3
},
//...
]
}
That’s it! Fetching DeFi protocol data is easy with Moralis. For a detailed breakdown, check out the official DeFi API documentation or follow this guide to learn more.
Ready to start querying DeFi protocol data? Sign up for a free Moralis account to access our industry-leading development tools instantly!
Overview
Wallet holders often have significant portions of their portfolios locked in DeFi protocols to, for instance, earn yield. However, tracking these positions can be challenging, complicating the development of tools like portfolio trackers, wallets, and tax platforms. That’s why we introduced our DeFi Positions feature.
With Moralis’ DeFi Positions, you can query DeFi protocol data with just a few lines of code. Are you curious about how it works? If so, join us in this guide, and we’ll show you. Let’s dive in!
What is DeFi Protocol Data?
DeFi protocol data encompasses detailed information about a wallet’s positions across various DeFi platforms, such as Uniswap and Aave. This data includes liquidity positions, yield farming activities and other interactions within the DeFi ecosystem. Given that many wallet holders lock assets in DeFi protocols, this data is crucial for building portfolio trackers, crypto tax platforms, and other Web3 projects, along with ensuring overall accurate financial reporting.

Traditionally, retrieving DeFi protocol data has been complex and time-consuming. However, Moralis’ DeFi API simplifies this process, offering a streamlined way to access comprehensive DeFi protocol data.
So, what exactly is Moralis’ DeFi API, and how does it work? Let’s explore its features and benefits!
Moralis’ DeFi API – The Easiest Way to Get DeFi Protocol Data
Moralis’ DeFi API is the simplest and most powerful way to access DeFi protocol data. This leading API provides a unified interface to query liquidity pairs, ERC-20 allowances, liquidity provider tokens, DeFi positions, and more – all in one place.

With robust cross-chain support, Moralis’ DeFi API enables you to retrieve data across major blockchain networks and protocols, including Ethereum, Polygon, BNB Smart Chain (BSC), and others.
As such, whether you’re developing lending platforms, portfolio trackers, or similar applications, Moralis’ DeFi API equips you with the necessary tools.
So, how can you use Moralis’ DeFi API to get protocol data? This is where our DeFi Positions feature comes into play!
Introducing Moralis’ DeFi Positions
One of the DeFi API’s most prominent features is DeFi Positions, which provides comprehensive insight into any wallet’s DeFi activities. But what does this actually entail? Our DeFi Positions feature comprises three key endpoints:
Summary DeFi Protocols by Wallet
Retrieve a comprehensive summary of all DeFi protocols associated with a specific wallet address. Below is an example of the endpoint in action:
import fetch from 'node-fetch';
const options = {
method: 'GET',
headers: {
accept: 'application/json',
'X-API-Key': 'YOUR_API_KEY'
},
};
fetch('https://deep-index.moralis.io/api/v2.2/wallets/0xcB1C1FdE09f811B294172696404e88E658659905/defi/summary?chain=eth', options)
.then(response => response.json())
.then(response => console.log(response))
.catch(err => console.error(err));
When you call this endpoint, you’ll receive a detailed summary of the DeFi protocols the wallet interacts with, including the total USD value of all positions, unclaimed rewards, protocol names, and additional relevant data. Here’s an example of the response:
{
active_protocols: 8,
total_positions: 12,
total_usd_value: 871.6550972487607,
total_unclaimed_usd_value: 26.31655680118138,
protocols: [
{
protocol_name: 'Uniswap v3',
protocol_id: 'uniswap-v3',
protocol_url: 'https://app.uniswap.org',
protocol_logo: 'https://cdn.moralis.io/defi/uniswap.png',
total_usd_value: 433.6700616074799,
total_unclaimed_usd_value: 26.31655680118138,
positions: 3
},
//...
]
}
Summary DeFi Positions by Wallet
Fetch a summary of all DeFi positions associated with a wallet, including unclaimed rewards for each position. Down below, you’ll find an example of what it might look like when calling this endpoint:
import fetch from 'node-fetch';
const options = {
method: 'GET',
headers: {
accept: 'application/json',
'X-API-Key': 'YOUR_API_KEY'
},
};
fetch('https://deep-index.moralis.io/api/v2.2/wallets/0xcB1C1FdE09f811B294172696404e88E658659905/defi/positions?chain=eth', options)
.then(response => response.json())
.then(response => console.log(response))
.catch(err => console.error(err));
Running the code above returns a detailed summary of all DeFi positions for a wallet. This includes position labels, associated tokens, USD values for each position, and other relevant details. Here’s an example output:
[
{
"protocol_name": "Uniswap v2",
"protocol_id": "uniswap-v2",
"protocol_url": "https://app.uniswap.org/pools/v2",
"protocol_logo": "https://cdn.moralis.io/defi/uniswap.png",
"position": {
"label": "liquidity",
"tokens": [
{
"token_type": "supplied",
"name": "USD Coin",
"symbol": "USDC",
"contract_address": "0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48",
"decimals": "6",
"logo": "https://logo.moralis.io/0x1_0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48_ac01a87aaf98ddb0f349ee4ebe97f0d8",
"thumbnail": "https://logo.moralis.io/0x1_0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48_ac01a87aaf98ddb0f349ee4ebe97f0d8",
"balance": "9762775.56142477145245169357",
"balance_formatted": "9.76277556142477145245169357",
"usd_price": 0.9999274263552301,
"usd_value": 9.76206704121921
},
//...
],
"address": "0xb4e16d0168e52d35cacd2c6185b44281ec28c9dc",
"balance_usd": 19.509109037404016,
"total_unclaimed_usd_value": 5.127740503730312,
"position_details": {
"reserve0": "9.76277556142477145245169357",
"reserve1": "0.00356975548622332765688138345279600856",
"factory": "0x5c69bee701ef814a2b6a3edd4b1652cb9cc5aa6f",
"pair": "0xb4e16d0168e52d35cacd2c6185b44281ec28c9dc",
"share_of_pool": 0.000021077221080781
}
}
},
//...
]
Detailed DeFi Positions by Wallet & Protocol
Query detailed data on positions for a specific wallet and protocol. Here’s an example of what it might look like:
import fetch from 'node-fetch';
const options = {
method: 'GET',
headers: {
accept: 'application/json',
'X-API-Key': 'YOUR_API_KEY'
},
};
fetch('https://deep-index.moralis.io/api/v2.2/wallets/0xcB1C1FdE09f811B294172696404e88E658659905/defi/uniswap-v3/positions?chain=eth', options)
.then(response => response.json())
.then(response => console.log(response))
.catch(err => console.error(err));
Running the code returns comprehensive DeFi positions for the specified wallet and protocol, including position labels, tokens, USD values for each position, unclaimed rewards, and more. See an example response below:
{
"protocol_name": "Uniswap v3",
"protocol_id": "uniswap-v3",
"protocol_url": "https://app.uniswap.org",
"protocol_logo": "https://cdn.moralis.io/defi/uniswap.png",
"total_usd_value": 433.28689509249983,
"total_unclaimed_usd_value": 26.291817301924766,
"positions": [
{
"label": "liquidity",
"tokens": [
{
"token_type": "supplied",
"name": "Coinbase Wrapped Staked ETH",
"symbol": "cbETH",
"contract_address": "0xbe9895146f7af43049ca1c1ae358b0541ea49704",
"decimals": "18",
"logo": "https://logo.moralis.io/0x1_0xbe9895146f7af43049ca1c1ae358b0541ea49704_22de8d667f6e46b09b33c805e7973049",
"thumbnail": "https://logo.moralis.io/0x1_0xbe9895146f7af43049ca1c1ae358b0541ea49704_22de8d667f6e46b09b33c805e7973049",
"balance": "0",
"balance_formatted": "0",
"usd_price": 2937.5037898342443,
"usd_value": 0
},
//...
{
"token_type": "reward",
"name": "Coinbase Wrapped Staked ETH",
"symbol": "cbETH",
"contract_address": "0xbe9895146f7af43049ca1c1ae358b0541ea49704",
"decimals": "18",
"logo": "https://logo.moralis.io/0x1_0xbe9895146f7af43049ca1c1ae358b0541ea49704_22de8d667f6e46b09b33c805e7973049",
"thumbnail": "https://logo.moralis.io/0x1_0xbe9895146f7af43049ca1c1ae358b0541ea49704_22de8d667f6e46b09b33c805e7973049",
"balance": "880092663147703",
"balance_formatted": "0.000880092663147703",
"usd_price": 2937.5037898342443,
"usd_value": 2.5852755334016906
},
//...
],
"address": "0x840deeef2f115cf50da625f7368c24af6fe74410",
"balance_usd": 78.95335940631567,
"total_unclaimed_usd_value": 5.121540153915798,
"position_details": {
Source link