DeFi Llama
Search…
General EVM contract calls

Balance Calls

erc20.balanceOf can be used to get token balances
return {
[tokenAddress]: (
await sdk.api.erc20.balanceOf({
tokenAddress,
tokenHolderAddress,
block,
chain
})
).output,
};
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)
const balance_okt = (
await sdk.api.eth.getBalance({
target,
block,
chain: 'okexchain'
})
).output;
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.
const sdk = require('@defillama/sdk');
const response = (await sdk.api.abi.call({<params>})).output
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.
await sdk.util.sumSingleBalance(balances, tokenAddress, balanceOfToken);
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.
const tokensInacBTC = [
'0x2260fac5e5542a773aa44fbcfedf7c193bc2c599',
'0xEB4C2781e4ebA804CE9a9803C67d0893436bB27D'
];
const acBTCTokenHolder = '0x73FddFb941c11d16C827169Bb94aCC227841C396';
const underlyingacBTC = await sdk.api.abi.multiCall({
calls: tokensInacBTC.map(token => ({
target: token,
params: [acBTCTokenHolder]
})),
abi: 'erc20:balanceOf',
block,
});
sdk.util.sumMultiBalanceOf(balances, underlyingacBTC);
DefiLlama-Adapters/index.js at main · DefiLlama/DefiLlama-Adapters
GitHub
Example MultiCall Adapter
Copy link
On this page
Balance Calls
Custom Contract Calls