Querying user's balance

Don't forget to initialize DeFi SDK first!

Get account balance locked in a protocol

Python
Go
JavaScript
Python
>>> USER_ADDRESS = '0xa218a8346454c982912cf6d14c714663c2d510d8'
>>> PROTOCOL = 'Aave'
>>> await defi_sdk.get_protocol_balance(USER_ADDRESS, PROTOCOL)
ProtocolBalance(
metadata=ProtocolMetadata(
name='Aave',
description='Decentralized lending & borrowing protocol',
website_url='aave.com',
icon_url='protocol-icons.s3.amazonaws.com/aave.png',
version=0
),
adapter_balances=[
AdapterBalance(
metadata=AdapterMetadata(
address='0x8b62c02091fe06ae3454d3c12921b32611ba5501',
type='Asset'
),
asset_balances=[
AssetBalance(
base_token_balance=TokenBalance(
metadata=TokenMetadata(
address='0xfc1e690f61efd961294b3e1ce3313fbd8aa4f85d',
name='Aave Interest bearing DAI',
symbol='aDAI',
decimals=18
),
balance=Decimal('1.006384746516743708')
),
underlying_token_balances=[
TokenBalance(
metadata=TokenMetadata(
address='0x6b175474e89094c44da98b954eedeac495271d0f',
name='Dai Stablecoin',
symbol='DAI',
decimals=18
),
balance=Decimal('1.006384746516743708')
)
]
)
]
)
]
)
Go
userAddress := "0xa218a8346454c982912cf6d14c714663c2d510d8"
protocol := "Aave"
sdk.GetProtocolBalance(userAddress, protocol)
// [{
// Metadata:{
// Name:Aave
// Description:Decentralized lending & borrowing protocol
// WebsiteURL:aave.com
// IconURL:protocol-icons.s3.amazonaws.com/aave.png
// Version:+0
// }
// AdapterBalances:[{
// Metadata:{
// AdapterAddress:[139 98 192 32 145 254 6 174 52 84 211 193 41 33 179 38 17 186 85 1]
// AdapterType:Asset
// }
// Balances:[{
// Base:{
// Metadata:{
// Token:[252 30 105 15 97 239 217 97 41 75 62 28 227 49 63 189 138 164 248 93]
// Name:Aave Interest bearing DAI
// Symbol:aDAI
// Decimals:18
// }
// Amount:+1008383439792242970
// }
// Underlying:[{
// Metadata:{
// Token:[107 23 84 116 232 144 148 196 77 169 139 149 78 237 234 196 149 39 29 15]
// Name:Dai Stablecoin
// Symbol:DAI
// Decimals:18
// }
// Amount:+1008383439792242970
// }]
// }]
// }]
// }]
JavaScript
const account = "0x42b9dF65B219B3dD36FF330A4dD8f327A6Ada990";
const protocol = "Compound";
defiSdk.getProtocolBalance(
account,
protocol
).then(balance => console.log(balance));
// output:
// ProtocolBalance {
// metadata: ProtocolMetadata {
// name: 'Compound',
// description: 'Decentralized lending & borrowing protocol',
// website: URL {
// href: 'https://compound.finance/',
// origin: 'https://compound.finance',
// protocol: 'https:',
// username: '',
// password: '',
// host: 'compound.finance',
// hostname: 'compound.finance',
// port: '',
// pathname: '/',
// search: '',
// searchParams: URLSearchParams {},
// hash: ''
// },
// logo: URL {
// href: 'https://protocol-icons.s3.amazonaws.com/compound.png',
// origin: 'https://protocol-icons.s3.amazonaws.com',
// protocol: 'https:',
// username: '',
// password: '',
// host: 'protocol-icons.s3.amazonaws.com',
// hostname: 'protocol-icons.s3.amazonaws.com',
// port: '',
// pathname: '/compound.png',
// search: '',
// searchParams: URLSearchParams {},
// hash: ''
// },
// version: 2n
// },
// balances: [
// AdapterBalance { metadata: [AdapterMetadata], balances: [Array] },
// AdapterBalance { metadata: [AdapterMetadata], balances: [Array] }
// ]
// }

Get account balance across all supported protocols

Python
Go
JavaScript
Python
>>> USER_ADDRESS = '0xa218a8346454c982912cf6d14c714663c2d510d8'
>>> await defi_sdk.get_account_balance(USER_ADDRESS)
[
ProtocolBalance(
metadata=ProtocolMetadata(
name='Synthetix',
description='Synthetic assets protocol',
website_url='synthetix.io',
icon_url='protocol-icons.s3.amazonaws.com/synthetix.png',
version=1
),
adapter_balances=[
AdapterBalance(
metadata=AdapterMetadata(
address='0xfd23f77fbd9fc08c4634cc3fdd58054cece3792b',
type='Asset'
),
asset_balances=[
AssetBalance(
base_token_balance=TokenBalance(
metadata=TokenMetadata(
address='0xc011a73ee8576fb46f5e1c5751ca3b9fe0af2a6f',
name='Synthetix Network Token',
symbol='SNX',
decimals=18
),
balance=Decimal('0.010000000000000000')
),
underlying_token_balances=[]
)
]
)
]
),
ProtocolBalance(
metadata=ProtocolMetadata(
name='dYdX',
description='Decentralized trading platform',
website_url='dydx.exchange',
icon_url='protocol-icons.s3.amazonaws.com/dYdX.png',
version=0
),
adapter_balances=[
AdapterBalance(
metadata=AdapterMetadata(
address='0x375c3222bb7d4834b4381abd4ed15dff4d4c0a68',
type='Asset'
),
asset_balances=[
AssetBalance(
base_token_balance=TokenBalance(
metadata=TokenMetadata(
address='0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
name='Wrapped Ether',
symbol='WETH',
decimals=18
),
balance=Decimal('0.185594562946597852')
),
underlying_token_balances=[]
),
AssetBalance(
base_token_balance=TokenBalance(
metadata=TokenMetadata(
address='0x6b175474e89094c44da98b954eedeac495271d0f',
name='Dai Stablecoin',
symbol='DAI',
decimals=18
),
balance=Decimal('185.230336031983831471')
),
underlying_token_balances=[]
)
]
),
AdapterBalance(
metadata=AdapterMetadata(
address='0xbf3fc291876707b2d0c8fc49bcd76fae00219d37',
type='Debt'
),
asset_balances=[
AssetBalance(
base_token_balance=TokenBalance(
metadata=TokenMetadata(
address='0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
name='USD//C',
symbol='USDC',
decimals=6
),
balance=Decimal('50.819863')
),
underlying_token_balances=[]
)
]
)
]
),
ProtocolBalance(
metadata=ProtocolMetadata(
name='Compound',
description='Decentralized lending & borrowing protocol',
website_url='compound.finance',
icon_url='protocol-icons.s3.amazonaws.com/compound.png',
version=0
),
adapter_balances=[
AdapterBalance(
metadata=AdapterMetadata(
address='0xaa74b0f33cab1b291980532bc5e0057e10adb2a3',
type='Asset'
),
asset_balances=[
AssetBalance(
base_token_balance=TokenBalance(
metadata=TokenMetadata(
address='0x4ddc2d193948926d02f9b1fe9e1daa0718270ed5',
name='Compound Ether',
symbol='cETH',
decimals=8
),
balance=Decimal('499.72749958')
),
underlying_token_balances=[
TokenBalance(
metadata=TokenMetadata(
address='0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee',
name='Ether',
symbol='ETH',
decimals=18
),
balance=Decimal('10.000492390829125770')
)
]
),
AssetBalance(
base_token_balance=TokenBalance(
metadata=TokenMetadata(
address='0x39aa39c021dfbae8fac545936693ac917d5e7563',
name='Compound USD Coin',
symbol='cUSDC',
decimals=8
),
balance=Decimal('48.61414113')
),
underlying_token_balances=[
TokenBalance(
metadata=TokenMetadata(
address='0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
name='USD//C',
symbol='USDC',
decimals=6
),
balance=Decimal('1.021851')
)
]
)
]
),
AdapterBalance(
metadata=AdapterMetadata(
address='0xae61b0d0a562e5c1daf9c1ded4a8fd6a770b639a',
type='Debt'
),
asset_balances=[
AssetBalance(
base_token_balance=TokenBalance(
metadata=TokenMetadata(
address='0x0d8775f648430679a709e98d2b0cb6250d2887ef',
name='Basic Attention Token',
symbol='BAT', decimals=18
),
balance=Decimal('0.000117145388391941')
),
underlying_token_balances=[]
),
AssetBalance(
base_token_balance=TokenBalance(
metadata=TokenMetadata(
address='0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
name='USD//C',
symbol='USDC',
decimals=6
),
balance=Decimal('437.598211')
),
underlying_token_balances=[]
)
]
)
]
),
ProtocolBalance(
metadata=ProtocolMetadata(
name='Aave',
description='Decentralized lending & borrowing protocol',
website_url='aave.com',
icon_url='protocol-icons.s3.amazonaws.com/aave.png',
version=0
),
adapter_balances=[
AdapterBalance(
metadata=AdapterMetadata(
address='0x8b62c02091fe06ae3454d3c12921b32611ba5501',
type='Asset'
),
asset_balances=[
AssetBalance(
base_token_balance=TokenBalance(
metadata=TokenMetadata(
address='0xfc1e690f61efd961294b3e1ce3313fbd8aa4f85d',
name='Aave Interest bearing DAI',
symbol='aDAI',
decimals=18
),
balance=Decimal('1.006383863871752377')
),
underlying_token_balances=[
TokenBalance(
metadata=TokenMetadata(
address='0x6b175474e89094c44da98b954eedeac495271d0f',
name='Dai Stablecoin',
symbol='DAI',
decimals=18
),
balance=Decimal('1.006383863871752377')
)
]
)
]
)
]
)
]
Go
userAddress := "0xa218a8346454c982912cf6d14c714663c2d510d8"
sdk.GetBalances(userAddress)
// [{
// Metadata:{
// Name:Synthetix
// Description:Synthetic assets protocol
// WebsiteURL:synthetix.io
// IconURL:protocol-icons.s3.amazonaws.com/synthetix.png
// Version:+4}
// AdapterBalances:[{
// Metadata:{
// AdapterAddress:[149 35 137 74 93 251 252 180 54 206 174 209 204 12 148 33 153 120 177 42]
// AdapterType:Asset
// }
// Balances:[{
// Base:{
// Metadata:{
// Token:[192 17 167 62 232 87 111 180 111 94 28 87 81 202 59 159 224 175 42 111]
// Name:Synthetix Network Token
// Symbol:SNX
// Decimals:18
// }
// Amount:+10000000000000000
// }
// Underlying:[]
// }]
// }]
// }
// {
// Metadata:{
// Name:dYdX
// Description:Decentralized trading platform
// WebsiteURL:dydx.exchange
// IconURL:protocol-icons.s3.amazonaws.com/dYdX.png
// Version:+0}
// AdapterBalances:[{Metadata:{AdapterAddress:[55 92 50 34 187 125 72 52 180 56 26 189 78 209 93 255 77 76 10 104] AdapterType:Asset} Balances:[{Base:{Metadata:{Token:[192 42 170 57 178 35 254 141 10 14 92 79 39 234 217 8 60 117 108 194] Name:Wrapped Ether Symbol:WETH Decimals:18} Amount:+185622250051205449} Underlying:[]} {Base:{Metadata:{Token:[107 23 84 116 232 144 148 196 77 169 139 149 78 237 234 196 149 39 29 15] Name:Dai Stablecoin Symbol:DAI Decimals:18} Amount:+204549799120959286024} Underlying:[]}]}]} {
// Metadata:{
// Name:Compound
// Description:Decentralized lending & borrowing protocol
// WebsiteURL:compound.finance
// IconURL:protocol-icons.s3.amazonaws.com/compound.png
// Version:+2}
// AdapterBalances:[{Metadata:{AdapterAddress:[170 116 176 243 60 171 27 41 25 128 83 43 197 224 5 126 16 173 178 163] AdapterType:Asset} Balances:[{Base:{Metadata:{Token:[245 220 229 114 130 165 132 210 116 111 175 21 147 211 18 31 202 196 68 220] Name:Compound Sai Symbol:cSAI Decimals:8} Amount:+30325980599} Underlying:[{Metadata:{Token:[137 210 74 107 76 203 27 111 170 38 37 254 86 43 221 154 35 38 3 89] Name:Sai Stablecoin v1.0 Symbol:SAI Decimals:18} Amount:+6504328055813863085}]} {Base:{Metadata:{Token:[57 170 57 192 33 223 186 232 250 197 69 147 102 147 172 145 125 94 117 99] Name:Compound USD Coin Symbol:cUSDC Decimals:8} Amount:+4861414113} Underlying:[{Metadata:{Token:[160 184 105 145 198 33 139 54 193 209 157 74 46 158 176 206 54 6 235 72] Name:USD//C Symbol:USDC Decimals:6} Amount:+1022383}]} {Base:{Metadata:{Token:[246 80 195 216 141 18 219 133 91 139 247 209 27 230 197 90 78 7 220 201] Name:Compound USDT Symbol:cUSDT Decimals:8} Amount:+49848045460} Underlying:[{Metadata:{Token:[218 193 127 149 141 46 229 35 162 32 98 6 153 69 151 193 61 131 30 199] Name:Tether USD Symbol:USDT Decimals:6} Amount:+9980539}]}]}]} {
// Metadata:{
// Name:Aave
// Description:Decentralized lending & borrowing protocol
// WebsiteURL:aave.com
// IconURL:protocol-icons.s3.amazonaws.com/aave.png
// Version:+0}
// AdapterBalances:[{Metadata:{AdapterAddress:[139 98 192 32 145 254 6 174 52 84 211 193 41 33 179 38 17 186 85 1] AdapterType:Asset} Balances:[{Base:{Metadata:{Token:[252 30 105 15 97 239 217 97 41 75 62 28 227 49 63 189 138 164 248 93] Name:Aave Interest bearing DAI Symbol:aDAI Decimals:18} Amount:+1008383690047548179} Underlying:[{Metadata:{Token:[107 23 84 116 232 144 148 196 77 169 139 149 78 237 234 196 149 39 29 15] Name:Dai Stablecoin Symbol:DAI Decimals:18} Amount:+1008383690047548179}]}]}]}]
JavaScript
const account = "0x42b9dF65B219B3dD36FF330A4dD8f327A6Ada990";
defiSdk.getAccountBalances(account).then(balances => console.log(balances));
// [ ProtocolBalance {
// metadata:
// ProtocolMetadata {
// name: 'Synthetix',
// description: 'Synthetic assets protocol',
// website: [Object],
// logo: [Object],
// version: 4n },
// balances: [ [AdapterBalance] ] },
// ProtocolBalance {
// metadata:
// ProtocolMetadata {
// name: 'dYdX',
// description: 'Decentralized trading platform',
// website: [Object],
// logo: [Object],
// version: 0n },
// balances: [ [AdapterBalance] ] },
// ProtocolBalance {
// metadata:
// ProtocolMetadata {
// name: 'Compound',
// description: 'Decentralized lending & borrowing protocol',
// website: [Object],
// logo: [Object],
// version: 2n },
// balances: [ [AdapterBalance] ] },
// ProtocolBalance {
// metadata:
// ProtocolMetadata {
// name: 'Aave',
// description: 'Decentralized lending & borrowing protocol',
// website: [Object],
// logo: [Object],
// version: 0n },
// balances: [ [AdapterBalance] ] } ]