Debank Unofficial Wallet Portfolio Balance API

FREEMIUM
By RainAPI | Updated 한 달 전 | Finance
Popularity

9.5 / 10

Latency

491ms

Service Level

100%

Health Check

N/A

Back to All Tutorials (2)

Node.js Tutorial: Check and Log Wallet Portfolio Balance with Axios

Node.js Tutorial: Check and Log Wallet Portfolio Balance with Axios

This tutorial will guide you through the process of using a Node.js script to retrieve and log the portfolio balance of a cryptocurrency wallet across various EVM chains using the Axios HTTP client.

Prerequisites

Before you start, make sure you have the following:

  npm install axios

Step 1: Setting Up Your Node.js Script

Create a new JavaScript file, e.g., checkPortfolio.js, and open it in your code editor.

Step 2: Import Axios

At the top of your checkPortfolio.js file, import the Axios library:

const axios = require('axios');

Step 3: Configure API Request

Set up the API request options using your RapidAPI key and the desired wallet address:

const options = {
  method: 'GET',
  url: 'https://debank-unofficial-wallet-portfolio-balance-api.p.rapidapi.com/user/total_balance',
  params: { address: '0xYourWalletAddress' }, // Replace with the wallet address
  headers: {
    'X-RapidAPI-Key': 'YourRapidAPIKey', // Replace with your API key
    'X-RapidAPI-Host': 'debank-unofficial-wallet-portfolio-balance-api.p.rapidapi.com'
  }
};

Replace 0xYourWalletAddress with the actual wallet address and YourRapidAPIKey with your RapidAPI key.

Step 4: Sending the Request and Handling the Response

Using an async function, send the request and process the response:

async function getPortfolioBalance() {
  try {
    const response = await axios.request(options);
    console.log('Portfolio Balance:', response.data);
  } catch (error) {
    console.error('Error fetching portfolio balance:', error);
  }
}

getPortfolioBalance();

This function sends a request to the API and logs the response to the console.

Step 5: Run Your Script

Run your script using Node.js:

node checkPortfolio.js

You should see the portfolio balance of the specified wallet address logged to the console, including individual balances for each chain and the total USD worth.

Conclusion

You’ve successfully set up a Node.js script to retrieve and log the portfolio balance of a cryptocurrency wallet using Axios. This script can be expanded or integrated into larger projects to monitor wallet balances across various EVM chains.