DeFi Llama
Search…
General EVM contract calls

Balance Calls

erc20.balanceOf can be used to get token balances
1
return {
2
[tokenAddress]: (
3
await sdk.api.erc20.balanceOf({
4
tokenAddress,
5
tokenHolderAddress,
6
block,
7
chain
8
})
9
).output,
10
};
Copied!
DefiLlama-Adapters/index.js at main · DefiLlama/DefiLlama-Adapters
GitHub
Example ERC20 Token Balance Adapter
eth.getBalance is for getting gas token balances (can be used on chains that aren't Ethereum)
1
const balance_okt = (
2
await sdk.api.eth.getBalance({
3
target,
4
block,
5
chain: 'okexchain'
6
})
7
).output;
Copied!
DefiLlama-Adapters/typhoon.js at main · DefiLlama/DefiLlama-Adapters
GitHub
Example Gas Token Balance Adapter

Custom Contract Calls

Contract calls are the most common ways of recording TVL.
1
const sdk = require('@defillama/sdk');
2
3
const response = (await sdk.api.abi.call({<params>})).output
Copied!
Often after a single contract call you'll also want to add the balance to your balances object, which can be easily done with sumSingleBalance.
1
await sdk.util.sumSingleBalance(balances, tokenAddress, balanceOfToken);
Copied!
DefiLlama-Adapters/index.js at main · DefiLlama/DefiLlama-Adapters
GitHub
When you have lots of calls to functions with the same ABI, it's easier to use multiCall and sumMultiBalanceOf.
1
const tokensInacBTC = [
2
'0x2260fac5e5542a773aa44fbcfedf7c193bc2c599',
3
'0xEB4C2781e4ebA804CE9a9803C67d0893436bB27D'
4
];
5
6
const acBTCTokenHolder = '0x73FddFb941c11d16C827169Bb94aCC227841C396';
7
8
const underlyingacBTC = await sdk.api.abi.multiCall({
9
calls: tokensInacBTC.map(token => ({
10
target: token,
11
params: [acBTCTokenHolder]
12
})),
13
abi: 'erc20:balanceOf',
14
block,
15
});
16
17
sdk.util.sumMultiBalanceOf(balances, underlyingacBTC);
Copied!
DefiLlama-Adapters/index.js at main · DefiLlama/DefiLlama-Adapters
GitHub
Example MultiCall Adapter