Access wallet balances and smart contract balances using the Pulsar SDK.

Usage Costs:

Wallet balances request cost 1 credit per wallet.

Overview

This page provides information on how to use the Pulsar SDK to access wallet balances and fetch comprehensive smart contract balances. The Pulsar SDK simplifies these processes, making it easier for developers to integrate with the Pulsar API.

Wallet Balances

To access the balances of a wallet, we offer WebSocket endpoints that you can interact with using your API keys. These endpoints provide a secure and efficient way to retrieve comprehensive information about the wallet's balances, including token amounts and other related details.

Input Typing

{
  "method": string,
  "command": {
    "key": string,
    "data": {
      "address": string,
      "chain": string,
      "hide_tokens": Array<string>,
      "hide_integrations": Array<string>,
      "hide_nfts": Array<string>
    }
  },
}

Data Example

{
   "method":"COMMAND",
   "command":{
      "key":"WALLET_BALANCES",
      "data":{
         "address":"terra1r7dke7zyzk3njkyquanscq70359d5tgmc2zn2e",
         "chain":"TERRA2",
         "hide_tokens":[],
         "hide_integrations":[],
         "hide_nfts":[]
      }
   },
   "request_id":"31966556-19b9-449f-b6b6-c08caf3db5fc"
}

Using the Pulsar SDK for Wallet Balances

Our SDK provides a convenient function called getWalletBalances designed specifically for developers. By simply providing the wallet address and chain as arguments, you can effortlessly retrieve the wallet balances you need.

import PulsarSDK, { ChainKeys } from 'pulsar_sdk_js'

const chain = ChainKeys.ETHEREUM
const responses_list: any[] = []
const wallet_addr = 'YOUR WALLET ADDR'
const API_KEY = 'YOUR API KEY'
const sdk = new PulsarSDK(API_KEY)

async function getWalletBalances() {
    const balances = sdk.balances.getWalletBalances(wallet_addr, chain)
    for await (const balance of balances) {
        responses_list.push(balance)
    }
}

getWalletBalances().then(() => {
    console.log(responses_list)
})
import asyncio
from pulsar_sdk_py import PulsarSDK
from pulsar_sdk_py.enums import ChainKeys

sdk = PulsarSDK(API_KEY)
responses_list = []

async def main():
    global responses_list
    async for response in sdk.balances.get_wallet_balances(wallet_addr="your_wallet_addr", chain=ChainKeys.TERRA2):
        responses_list.append(response)

if __name__ == "__main__":
    asyncio.run(main())

Smart Contract Balances

Smart Contract Balances are represented by WalletIntegrations, which provide detailed information about the wallet's smart contract positions, including successful and failed retrievals.

Using the Pulsar SDK for Smart Contract Balances

The WalletIntegration object contains fields like balances, where you can find information on balance amounts, USD values, balance types, and unlock timestamps for each token.

export class WalletIntegration {
  wallet: BaseWallet;
  integration: BaseIntegration;
  balances: Array<IntegrationTokenStats>;
  nft_balances: Array<IntegrationNFTStats>;
  wallet_stats: WalletIntegrationStats | undefined;
}
@dataclass
class WalletIntegration:
    wallet: Wallet
    integration: BaseIntegration
    balances: list[IntegrationTokenStats]
    wallet_stats: WalletIntegrationStats = None

In the case of errors, you'll receive a list of RecipeError objects to help identify any issues with missing balances.

export class RecipeError {
  recipe: Recipe;
  chain: ChainKeys;
}
@dataclass
class RecipeError:
    recipe: Recipe
    chain: ChainKeys

📘

Get more Information out of a Smart Contract

Use our get_protocol function to retrieve additional information from any integration you receive a position for.

import PulsarSDK from "pulsar_sdk_js";

const sdk = new PulsarSDK(API_KEY);
let wallet_positions: WalletIntegration;
sdk.protocols.get_protocol(wallet_positions.integration.platform).then((protocol) => {
  console.log(protocol);
});
from pulsar_sdk_py import PulsarSDK
from pulsar_sdk_py.dataclasses.schemas import WalletIntegration

sdk = PulsarSDK(api_key=API_KEY)
wallet_integrations: WalletIntegration
protocol = wallet_integrations.integration.platform
sdk.protocols.get_protocol(protocol_key=protocol)