API

The De.Fi API is the easiest way to integrate our expansive functionality into any app of your choosing. Whether you are interested in querying our audit or Rekt databases, querying a wallet's balances or details about the many blockchains we've integrated, our API is here for you.

Our API supports all the tokens, protocols and blockchains supported by our app - meaning you'll have access to data from 35+ blockchains, 300+ protocols and countless tokens.

Querying

Queries should be made to the following URL:

https://public-api.de.fi/graphql

You can test out your queries before setting them up in your app through our handy GraphQL playground.

Before being able to perform queries, make sure you have properly authenticated them!

Available Endpoints

General endpoints

  • credits - Credit information with regards to your API key.

  • chains - Includes information about the many blockchains we have integrated into our dashboard. Please use chain_id values from the response for other calls listed below

  • assets - Paginated data about the many assets we have integrated into our dashboard.

Please be aware that the values of chain_id properties across the platform (in the response and the query params ) DON'T correspond with the absolute values (56 is for BSC, 137 is for Polygon, etc.) - the platform operates values like 1 is for Ethereum, 2 is for BNB, 3 for Polygon, etc. Please see all the values by calling chains endpoint.

Portfolio endpoints

  • assetBalances - ERC20 balances for any given wallet address

  • assetBalancesAdvanced (BETA) - ERC20 balances for any given wallet address. Allows fetching data for multiple addresses and chains through a single request

  • protocols - Includes information about the many dapps we have integrated into our dashboard (list here).

  • protocolBalanceV2 (BETA) - protocol balances for any given wallet address. Allows fetching data for multiple addresses and chains through a single request

  • protocolBalance - protocol balances for any given wallet address

Security endpoints

  • rekts - Paginated data about all hacks and exploits in our Rekt Database.

  • shields (DEPRECATED) - Safety information from De.Fi Shield regarding any given wallet address(es).

  • shieldAdvanced - Safety information from De.Fi Shield regarding any given wallet address(es).

  • shieldApprovals - The list of ERC20 approvals regarding any given wallet address(es).

  • shieldApprovalsNft - The list of ERC721 and ERC1155 approvals regarding any given wallet address(es).

  • scannerLiquidityAnalysis - The global liquidity distribution, top 10 LP holders and top 10 liquidity pairs regarding any given token address.

  • scannerHolderAnalysis - Info on the top 10 holders for any given token address.

  • scannerProject - The list of all issues found (both static and dynamic), security score, similar contracts and onchain governance info for any given smart contract address.

Opportunities endpoints

  • opportunities - Information regarding any DeFi yield opportunities available based on your preferred search terms.

  • opportunityFarms - List of DeFi yield opportunities.

Potential Use Cases

Need some ideas on how to use our API endpoints to build something cool? Check below:

Portfolio Dashboard

  • Make a call to the chains endpoint to get all the chains supported by De.Fi

query {
  chains  {
    id
    name
  }
}
  • Make calls to the assetBalancesAdvanced endpoint to get ERC20 balances (in case of EVM chains) and assetBalances for non-EVM chains (please see the details here https://public-api.de.fi/graphql )

query {
  assetBalancesAdvanced(
    chainIds: [1, 2]
    walletAddresses: ["...wallet #1...", "...wallet #2..."]) {
    total
    wallet
    chains {
      chain {
        id
      }
    }
  }
}
  • Make a call to protocols with version = V2 for TOP EVM and version = V1 for the rest of the platforms supported by De.Fi, including non-EVM chains

The list of platforms supported by the V2 endpoint is constantly expanding! Please reach out to the team if you have any questions or suggestions!

 query {
  protocols (version: V2) {
    name
    slug
    features {
      list 
    }
  }
}
  • Make calls to the protocolBalanceV2 endpoint to get user positions and balances for the TOP platforms supported by De.Fi

query {
  protocolBalanceV2 (
    chainIds: [1,2]
    walletAddresses:["...wallet #1...", "...wallet #2..."]
  ){
    errors
    balances {
      protocol {
        slug 
      }
      address
      total
    }

  }
}
  • Make calls to the protocolBalance endpoint for each of the chain-wallet-protocol combinations to get user positions and balances for the rest of the platforms supported by De.Fi, including non-EVM chains

query {
  protocolBalance ( balances: {
    chainIds: [1]
    walletAddress: "...wallet..."
    protocolName: "Arrakis"
  }
  ){
    protocol {
      slug
    }
    total
    chains {
      total
    }
  }
}

Opportunities Dashboard

  • Make a call to the opportunityFarms endpoint to get all platforms and features supported by De.Fi's Explore Yield feature

  • Make a call to the opportunities endpoint to get all the yield opportunities available. It's possible to filter by platform, feature, chain, etc.

Security Dashboard

  • Make a call to the shieldApprovals endpoint to get all approvals given out by a wallet address

  • Make a call to the assetBalances endpoint with the token addresses returned by the previous call. It will return the list of tokens that are still in the wallet (helps filter out approvals for zero-balance tokens)

  • Make a call to the shieldAdvanced endpoint with the smart contract addresses received prior for more info

Scanner Dashboard

  • Make calls to the scannerProject endpoint with the smart contract addresses received from similar calls to the "Security Dashboard" idea. This will return advanced security analysis for each relevant smart contract

  • Make a call to the scannerHolderAnalysis endpoint with the tokens addresses received prior for more holder information for each contract

  • Make a call to the scannerLiquidityAnalysis endpoint with the tokens addresses received prior for more liquidity information for each contract

Authentication

In order to use our API, you must first get a valid API key. Get one by sending a request to info@de.fi.

You will have to use a X-Api-Key header with your key on every request. For example, on our GraphQL playground, you should test your key as follows:

Pricing & Rate Limits

In order to make queries with your API key, you must purchase credits. The more complex your queries, the more credits may be used up when requesting data from our API.

SDK

We also provide an SDK to facilitate our API's usage if you plan on utilizing it in a Node.js environment. Install it as follows:

npm i @de-fi/sdk

The SDK's documentation can be found here.

Last updated