Web3

DeFi Protocol Data – Exploring the Easiest Way to Get a Wallet’s DeFi Positions

Are you wanting to entry decentralized finance (DeFi) protocol knowledge simply? If that’s the case, you’re in the proper place. This information introduces Moralis’ DeFi API – your go-to resolution for querying DeFi knowledge. With the DeFi API, you possibly can effortlessly fetch protocol knowledge for any pockets with simply a single API name. Keen to get going? Right here’s how to rapidly retrieve a abstract of the DeFi protocols a pockets interacts with:

import fetch from 'node-fetch';

const choices = {
 methodology: 'GET',
 headers: {
   settle for: 'software/json',
   'X-API-Key': 'YOUR_API_KEY'
 },
};

fetch(' choices)
 .then(response => response.json())
 .then(response => console.log(response))
 .catch(err => console.error(err));

Operating the code above offers a abstract of all DeFi protocols linked to a pockets, together with the variety of positions, whole USD worth, unclaimed rewards, protocol names, logos, and extra. Right here’s an instance 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: '
      protocol_logo: '
      total_usd_value: 433.6700616074799,
      total_unclaimed_usd_value: 26.31655680118138,
      positions: 3
    },
    //...
  ]
}

That’s it! Fetching DeFi protocol knowledge is simple with Moralis. For a detailed breakdown, take a look at the official DeFi API documentation or observe this information to be taught extra.

Prepared to begin querying DeFi protocol knowledge? Join a free Moralis account to entry our industry-leading improvement instruments immediately!

Overview

Pockets holders typically have important parts of their portfolios locked in DeFi protocols to, for example, earn yield. Nonetheless, monitoring these positions could be difficult, complicating the improvement of instruments like portfolio trackers, wallets, and tax platforms. That’s why we launched our DeFi Positions function.

With Moralis’ DeFi Positions, you possibly can question DeFi protocol knowledge with simply a few traces of code. Are you interested in the way it works? If that’s the case, be part of us on this information, and we’ll present you. Let’s dive in!

What’s DeFi Protocol Data?

DeFi protocol knowledge encompasses detailed details about a pockets’s positions throughout numerous DeFi platforms, resembling Uniswap and Aave. This knowledge contains liquidity positions, yield farming actions and different interactions inside the DeFi ecosystem. Provided that many pockets holders lock belongings in DeFi protocols, this knowledge is essential for constructing portfolio trackers, crypto tax platforms, and different Web3 initiatives, together with making certain total correct monetary reporting.

DeFi protocol data.

Historically, retrieving DeFi protocol knowledge has been advanced and time-consuming. Nonetheless, Moralis’ DeFi API simplifies this course of, providing a streamlined method to entry complete DeFi protocol knowledge.

So, what precisely is Moralis’ DeFi API, and the way does it work? Let’s discover its options and advantages!

Moralis’ DeFi API – The Easiest Way to Get DeFi Protocol Data

Moralis’ DeFi API is the easiest and strongest method to entry DeFi protocol knowledge. This main API offers a unified interface to question liquidity pairs, ERC-20 allowances, liquidity supplier tokens, DeFi positions, and extra – multi functional place.

Moralis' DeFi API.

With sturdy cross-chain help, Moralis’ DeFi API allows you to retrieve knowledge throughout main blockchain networks and protocols, together with Ethereum, Polygon, BNB Sensible Chain (BSC), and others.

As such, whether or not you’re creating lending platforms, portfolio trackers, or comparable purposes, Moralis’ DeFi API equips you with the crucial instruments.

So, how are you going to use Moralis’ DeFi API to get protocol knowledge? That is the place our DeFi Positions function comes into play!

Introducing Moralis’ DeFi Positions

One in all the DeFi API’s most outstanding options is DeFi Positions, which offers complete perception into any pockets’s DeFi actions. However what does this really entail? Our DeFi Positions function contains three key endpoints:

Abstract DeFi Protocols by Pockets

Retrieve a complete abstract of all DeFi protocols related to a particular pockets handle. Beneath is an instance of the endpoint in motion:

import fetch from 'node-fetch';

const choices = {
 methodology: 'GET',
 headers: {
   settle for: 'software/json',
   'X-API-Key': 'YOUR_API_KEY'
 },
};

fetch(' choices)
 .then(response => response.json())
 .then(response => console.log(response))
 .catch(err => console.error(err));

If you name this endpoint, you’ll obtain a detailed abstract of the DeFi protocols the pockets interacts with, together with the whole USD worth of all positions, unclaimed rewards, protocol names, and extra related knowledge. Right here’s an instance 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: '
      protocol_logo: '
      total_usd_value: 433.6700616074799,
      total_unclaimed_usd_value: 26.31655680118138,
      positions: 3
    },
    //...
  ]
}

Abstract DeFi Positions by Pockets

Fetch a abstract of all DeFi positions related to a pockets, together with unclaimed rewards for every place. Down beneath, you’ll discover an instance of what it would appear to be when calling this endpoint: 

import fetch from 'node-fetch';

const choices = {
  methodology: 'GET',
  headers: {
    settle for: 'software/json',
    'X-API-Key': 'YOUR_API_KEY'
  },
};

fetch(' choices)
  .then(response => response.json())
  .then(response => console.log(response))
  .catch(err => console.error(err));

Operating the code above returns a detailed abstract of all DeFi positions for a pockets. This contains place labels, related tokens, USD values for every place, and different related particulars. Right here’s an instance output:

[
  {
    "protocol_name": "Uniswap v2",
    "protocol_id": "uniswap-v2",
    "protocol_url": "
    "protocol_logo": "
    "position": {
      "label": "liquidity",
      "tokens": [
        {
          "token_type": "supplied",
          "name": "USD Coin",
          "symbol": "USDC",
          "contract_address": "0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48",
          "decimals": "6",
          "logo": "
          "thumbnail": "
          "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 Pockets & Protocol

Question detailed knowledge on positions for a particular pockets and protocol. Right here’s an instance of what it would appear to be:

import fetch from 'node-fetch';

const choices = {
 methodology: 'GET',
 headers: {
   settle for: 'software/json',
   'X-API-Key': 'YOUR_API_KEY'
 },
};

fetch(' choices)
 .then(response => response.json())
 .then(response => console.log(response))
 .catch(err => console.error(err));

Operating the code returns complete DeFi positions for the specified pockets and protocol, together with place labels, tokens, USD values for every place, unclaimed rewards, and extra. See an instance response beneath:

{
  "protocol_name": "Uniswap v3",
  "protocol_id": "uniswap-v3",
  "protocol_url": "
  "protocol_logo": "
  "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": "
          "thumbnail": "
          "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": "
          "thumbnail": "
          "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": {
        "nft_metadata": {
          "name": "Uniswap - 0.05% - cbETH/WETH - 0.95028<>0.95218",
          "description": "This NFT represents a liquidity position in a Uniswap V3 cbETH-WETH pool.//...",
          "image": "//..."
        },
        //...
    },
  ]
  //...
}

With these three endpoints, you possibly can achieve unparalleled perception into the DeFi positions of any pockets – all with a single API name!

Supported Protocols

The DeFi Positions function at the moment helps 13 main protocols, together with:

  • Uniswap-v3
  • Uniswap-v2
  • Pancakeswap-v3
  • Pancakeswap-v2
  • Quickswap-v2
  • Sushiswap-v2
  • Aave-v3
  • Aave-v2
  • Fraxswap-v2
  • Fraxswap-v1
  • Lido
  • Makerdao
  • Eigenlayer

That is simply the starting – our workforce at Moralis is repeatedly increasing help by including new protocols often!

Tutorial: How to Get DeFi Protocol Data in 3 Steps

On this tutorial, we’ll information you thru the strategy of retrieving DeFi protocol knowledge utilizing our DeFi API. And thanks to our user-friendly interface, you possibly can obtain this in simply three easy steps:

  1. Get a Moralis API Key
  2. Write a Script Calling the getDefiSummary() Endpoint
  3. Run the Code

However earlier than you get going, you want to cope with a few conditions! 

Conditions

For those who haven’t already, ensure you have the following prepared earlier than persevering with: 

Step 1: Get a Moralis API Key

To get your key, first enroll with Moralis by clicking the ”Begin for Free” button at the prime proper:

Subsequent, log in, and also you’ll discover your key immediately underneath the ”House” tab:

Red arrow pointing at Moralis API Key.

Copy and hold the key for now, as you’ll want it throughout the second step.

Step 2: Write a Script Calling the getDefiSummary() Endpoint

Open your most popular built-in improvement setting (IDE), arrange a folder, and initialize a new undertaking with the following terminal command:

npm init

Subsequent, run the command beneath to set up the required dependencies:

npm set up node-fetch --save
npm set up moralis @moralisweb3/common-evm-utils

Then, open your ”package deal.json” file and add "type": "module" to the listing:

Adding type: module to package.json file.

Create a new ”index.js” file and add the following script:

import fetch from 'node-fetch';

const choices = {
 methodology: 'GET',
 headers: {
   settle for: 'software/json',
   'X-API-Key': 'YOUR_API_KEY'
 },
};

fetch(' choices)
 .then(response => response.json())
 .then(response => console.log(response))
 .catch(err => console.error(err));

Now, you want to configure the code. Begin by changing YOUR_API_KEY with the key you copied throughout the first step. Then, configure the handle parameter to suit your question:

Red arrows pointing at "YOUR_API_KEY" and address parameter.

That’s it! All that is still is to execute the script.

Step 3: Run the Code

To execute the script, open a new terminal, navigate to your undertaking’s root folder, and run the following command:

node index.js

In return, you’ll obtain a abstract of the pockets’s DeFi positions. The response will embrace the whole USD worth of all positions, unclaimed rewards, protocol names, and extra. Right here’s an instance of what it would appear to be:

{
  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: '
      protocol_logo: '
      total_usd_value: 433.6700616074799,
      total_unclaimed_usd_value: 26.31655680118138,
      positions: 3
    },
    //...
  ]
}

Congratulations! You now know the way to seamlessly retrieve protocol knowledge utilizing the Moralis DeFi API. You’ll be able to observe the identical steps to name any of our different endpoints!

Advantages & Use Circumstances for DeFi Protocol Data

Moralis’ DeFi Positions function presents versatile purposes throughout numerous sectors. Listed below are 4 key examples:

  • Enhanced Portfolio Administration: Builders can elevate portfolio administration by integrating detailed DeFi exercise insights, driving larger person engagement and retention.
  • Complete Pockets Perception: Portfolio trackers can ship deeper visibility into customers’ DeFi actions, offering a extra full monetary overview.
  • Exact Tax Reporting: Crypto tax firms can enhance reporting accuracy by leveraging complete DeFi protocol knowledge.
  • Knowledgeable Funding Choices: DeFi-centric buyers and analysts could make smarter buying and selling selections with granular DeFi protocol and place knowledge.
DeFi protocol use cases.

In conclusion, our top-tier DeFi Positions function can turn out to be useful when constructing a wide selection of dapps throughout a number of industries! 

Past DeFi Positions – Exploring Moralis Additional

Moralis is the {industry}’s main Web3 knowledge supplier, consolidating all crypto knowledge in a single place. With our sturdy Web3 APIs and premium RPC nodes, accessing the knowledge you want requires simply a few traces of code. As such, whether or not you’re constructing a portfolio tracker, crypto tax device, or every other platform, Moralis has you lined.

Moralis Logo.

What units our improvement instruments aside?

  • Complete: Designed for effectivity, Moralis’ instruments provide you with extra knowledge with much less effort, permitting you to construct Web3 initiatives sooner and extra successfully.
  • Cross-Chain Compatibility: Our Web3 APIs provide full function parity throughout 30+ blockchain networks, so you possibly can depend on a single supplier for all of your knowledge wants.
  • Enterprise-Grade Safety: As SOC 2 Sort 2 compliant, Moralis ensures enterprise-level knowledge safety throughout all our merchandise.

Now that you’ve an outline of Moralis, let’s dive into the specifics of our improvement instruments beneath!

Web3 APIs

The Moralis Web3 API suite presents a complete set of instruments designed to streamline your developer expertise with seamless entry to blockchain knowledge. Listed below are 5 key APIs:

Moralis logo.
  • Pockets API: Simplify pockets knowledge integration with the Pockets API. Retrieve a pockets’s historical past, token balances, web price, profitability, and extra with simply a few traces of code.
  • Token API: Get ERC-20 token knowledge effortlessly with the Moralis Token API. This interface offers seamless entry to token balances, metadata, costs, transactions, and extra, making it best for integrating ERC-20 knowledge into wallets, portfolio trackers, and comparable platforms.
  • NFT API: The NFT API is your go-to resolution for all issues NFT. Whether or not you want NFT balances, costs, or up-to-date metadata, this API delivers. It’s excellent for constructing NFT marketplaces, Web3 video games, and different NFT-centric purposes.
  • Value API: Fetch real-time and historic worth knowledge with Moralis’ Value API. This highly effective device helps ERC-20 tokens and NFTs, making it straightforward to combine correct worth knowledge into your dapps.
  • Streams API: Keep forward with the Streams API, the industry-leading resolution for real-time blockchain knowledge. Our intuitive point-and-click interface enables you to arrange Web3 knowledge pipelines effortlessly, so you possibly can stream on-chain occasions immediately into your dapp as they occur.

Uncover extra about our cutting-edge APIs on the Moralis Web3 API web page.

RPC Nodes

Moralis’ node resolution permits you to arrange RPC nodes for 30+ chains seamlessly with simply a few clicks. Supported chains embrace Ethereum, BSC, Base, Optimism, Polygon, and lots of extra. So, in the event you want nodes, ensure to take a look at Moralis’ RPC nodes!

Text: "Ultimate PRC Nodes for Web3"

Listed below are three key causes to select our nodes:

  • Dependable: Our nodes boast a powerful 99.9% uptime, making certain you get the knowledge you want even when your dapp experiences downtime.
  • Quick: Moralis’ nodes set the benchmark for velocity with response occasions as little as 70 ms.
  • Prolonged RPC Strategies: With our Prolonged RPC Strategies, you possibly can question decoded knowledge immediately out of your nodes – fetch ERC-20 token balances, metadata, native transactions, and rather more with single requests.

To be taught extra about how this works, please go to our RPC nodes web page!

Abstract: DeFi Protocol Data – Exploring the Easiest Way to Get a Wallet’s DeFi Positions

Cryptocurrency pockets holders typically lock up massive quantities of their belongings in DeFi protocols to earn yield. This makes monitoring DeFi positions essential for the monetary accuracy of crypto tax platforms, portfolio trackers, and comparable companies. Nonetheless, fetching a pockets’s DeFi positions has historically been a cumbersome process. Fortuitously, that is the place Moralis’ DeFi API comes into play!

DeFi protocol data.

The DeFi API is your go-to device for DeFi knowledge. This premier interface presents a DeFi Positions function, permitting you to effortlessly question DeFi protocol knowledge for any pockets. However what precisely does this entail? The DeFi Positions function offers three major endpoints:

  • Abstract of DeFi Protocols by Pockets: Get a abstract of all DeFi protocols a pockets interacts with, together with the whole USD worth locked throughout protocols, the variety of DeFi positions, and different protocol-specific particulars.
  • Abstract of DeFi Positions by Pockets: Get a abstract of all DeFi positions of a pockets, together with place labels, token sorts, the worth of every place, unclaimed rewards, and extra.
  • Detailed DeFi Positions by Pockets & Protocol: Fetch detailed place knowledge for a given pockets and protocol, together with place labels, token sorts, costs, unclaimed rewards, and so on.

For those who discovered this text on DeFi protocol knowledge useful, take a look at extra content material on the Moralis weblog. As an illustration, discover our information on the finest Alchemy Customized Webhooks different or find out how to use our Crypto PnL API.

Prepared to dive into DeFi protocol knowledge? Join with Moralis without cost and get on the spot entry to our APIs and RPC nodes!

DailyBlockchain.News Admin

Our Mission is to bridge the knowledge gap and foster an informed blockchain community by presenting clear, concise, and reliable information every single day. Join us on this exciting journey into the future of finance, technology, and beyond. Whether you’re a blockchain novice or an enthusiast, DailyBlockchain.news is here for you.
Back to top button