Access wallet balances and smart contract balances using the Pulsar SDK.
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.
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.ETHEREUM):
responses_list.append(response)
if __name__ == "__main__":
asyncio.run(main())
Using the Pulsar SDK for Smart Contract Balances
When querying for the current balance of an address, the response can be one of three objects:
export class WalletIntegrations {
stats: WalletIntegration[];
errors: RecipeError[];
}
export class WalletTokens {
stats: WalletToken[];
errors: TokenError[];
}
export class WalletNFTs {
errors: WalletNFTError[];
items?: NFTItem[];
}
@dataclass
class WalletIntegration:
wallet: Wallet
integration: BaseIntegration
balances: list[IntegrationTokenStats]
nft_balances: list[IntegrationNFTStats]
wallet_stats: WalletIntegrationStats | None = None
@dataclass
class WalletTokens:
stats: list[WalletToken]
errors: list[TokenError]
@dataclass
class WalletNFTs:
items: list[NFTItem] | None
errors: list[WalletNFTError]
If you'd like to see the full list of schemas associated with the balances response, you can find them in the Balance Schemas section.
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
Input Typing
{
"method": string,
"command": {
"key": string,
"data": {
"address": string,
"chain": string,
"hide_tokens": Array<string>,
"hide_recipes": Array<string>,
"hide_integrations": Array<string>,
"hide_nfts": Array<string>
}
},
}
{
"method": "COMMAND",
"command": {
"key": "WALLET_BALANCES",
"data": {
"address": "0x2b78d022af87d411ba84474ffbc7eef8b4addb45",
"chain": "ETHEREUM",
"hide_tokens": [],
"hide_recipes": [],
"hide_integrations": [],
"hide_nfts": []
}
},
"request_id": "31966556-19b9-449f-b6b6-c08caf3db5fc"
}
Response Example
For wallet balances, responses come in various messages (websocket).
This is an example of how a response might look directly from our websocket endpoint when returning tokens. Using our SDK's you would instead iterate through a list of objects to access the data.
{
"data": {
"stats": [
{
"token": {
"name": "Ethereum",
"denom": "ETH",
"id": "633b4fc9e38a3c8fdc037532",
"display_id": "633b4fc9e38a3c8fdc037532",
"image": "https://pulsar-images.s3.eu-west-1.amazonaws.com/tokens/Ethereum.png",
"latest_price": "3326.8546766494533",
"price_24h_change": "-20.857640584768887",
"chain_properties": {
"chain": "ETHEREUM",
"id": {
"type": "native_token",
"value": "ETH"
},
"decimals": 18
}
},
"wallet": {
"address": "0x2b78d022af87d411ba84474ffbc7eef8b4addb45",
"chain": "ETHEREUM"
},
"usd_value": "18.800642618271706",
"balance": "0.005651176394998484"
}
],
"errors": []
}
}
If instead you received an integration object, the data would contain much more information. Here's another example of a websocket message you might receive, but returning an integration object.
{
"data":{
"stats":[
{
"integration":{
"recipe_id":"BITLAYER_PELL_NETWORK_RESTAKING",
"integration_id":"BITLAYER_PELL_NETWORK_RESTAKING__0x6b5A0AFeDA7710dC9821855E7efd3d435cE21487",
"chain":"BITLAYER",
"position_id":null,
"stats":{
"apy":null,
"tvl":{
"tokens":[
{
"token":{
"name":"Bitlayer STBTC Token",
"denom":"STBTC",
"id":"66d1a2ab4e7c87fd68958f03",
"display_id":"66d1a2ab4e7c87fd68958f03",
"image":"https://static.macaron.xyz/tokens/STBTC.png",
"latest_price":"96031.16437597651",
"price_24h_change":null,
"chain_properties":{
"chain":"BITLAYER",
"id":{
"type":"address",
"value":"0xf6718b2701d4a6498ef77d7c152b2137ab28b8a3"
},
"decimals":18
}
},
"amount":"9.312082986157463",
"usd_value":"874336.6595682233"
}
],
"usd_value":"874336.6595682233"
},
"breakdown":[
{
"name":"Bitlayer STBTC Token",
"denom":"STBTC",
"id":"66d1a2ab4e7c87fd68958f03",
"display_id":"66d1a2ab4e7c87fd68958f03",
"image":"https://static.macaron.xyz/tokens/STBTC.png",
"latest_price":"96031.16437597651",
"price_24h_change":null,
"chain_properties":{
"chain":"BITLAYER",
"id":{
"type":"address",
"value":"0xf6718b2701d4a6498ef77d7c152b2137ab28b8a3"
},
"decimals":18
}
}
],
"nft_breakdown":[],
"borrow_stats":null,
"airdrop_stats":null,
"staking_stats":{
"staking_type":"DEPOSIT",
"validator":{
"name":null,
"status":null,
"address":null,
"commission_percentage":null
}
},
"multiplier_stats":{
"total_apy":null,
"base_apy":null,
"rewards_apr":null,
"reward_apr_per_token":[],
"sample_count":null,
"variance_coefficient":null,
"multiplier_deviation":null
},
"impermanent_loss_stats":{
"percentage":null,
"value":null,
"time_ago":null
},
"risk_score_stats":{
"leverage_score":"10",
"impermanent_loss_score":null,
"yield_outlook_score":null,
"reward_token_score":null,
"tvl_score":"5",
"global_score":"6"
}
},
"name":"Restaking",
"platform":"PELL_NETWORK",
"type":"STAKING",
"address":null
},
"wallet":{
"address":"0x7bfee91193d9df2ac0bfe90191d40f23c773c060",
"chain":"BITLAYER"
}
}
],
"errors":[]
}
}
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)