> ## Documentation Index
> Fetch the complete documentation index at: https://docs.li.fi/llms.txt
> Use this file to discover all available pages before exploring further.

# balanceOf

> Use the on-chain balance of an address at execution time as the input amount

`balanceOf` sets a flow input's amount to `owner`'s balance of the input token, read on chain when the transaction executes, and spends exactly that. It works for ERC-20 and native inputs.

`balanceOf` moves no tokens, so the tokens it counts must already be on the execution proxy, for example tokens a bridge delivered there or leftovers from an earlier flow. In practice `owner` is the proxy, which the compile result returns as `userProxy`. To pull the signer's whole wallet balance instead, use the sweep form of [`directDeposit`](https://docs.li.fi/composer/composer-api/materialisers/direct-deposit).

## Plan with assumptions and preconditions

The amount is unknown at compile time, so the simulation needs a stand-in. Two compile options provide it:

* **`preconditions`**: an `erc20Balance` precondition on the proxy makes the simulation assume the proxy holds that balance. Nothing checks the real balance at compile time.
* **`assumptions`**: an estimated amount per input, in base units, for example `{ amountIn: 1000000000n }`. Composer plans the downstream ops with it.

## Example

Deposit whatever USDC the execution proxy holds into Aave v3, simulating as if 1,000 USDC has arrived:

```ts theme={"system"}
import { createComposeSdk, guards, materialisers, preconditions, resources } from '@lifi/composer-sdk';

const USDC = '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48';
// Aave v3 aEthUSDC receipt token on Ethereum mainnet
const A_ETH_USDC = '0x98C23E9d8f34FEFb1B7BD6a91B7FF122F4e16F5c';
// Your execution proxy: `userProxy` on any earlier compile result for this signer.
const PROXY = '0xYourExecutionProxy';

const sdk = createComposeSdk({
  baseUrl: 'https://composer.li.quest',
  apiKey: process.env.LIFI_API_KEY!,
});

const builder = sdk.flow(1, {
  name: 'deposit-from-proxy',
  inputs: { amountIn: resources.erc20(USDC, 1) },
});

builder.lifi.zap('deposit', {
  bind: { amountIn: builder.inputs.amountIn },
  config: { resourceOut: resources.erc20(A_ETH_USDC, 1) },
  guards: [guards.slippage({ port: 'amountOut', bps: 100 })],
});

await builder.compile({
  signer: '0xYourSignerAddress',
  inputs: {
    // Spend whatever USDC the proxy holds when the transaction executes.
    amountIn: materialisers.balanceOf({ owner: PROXY }),
  },
  // Simulate as if 1,000 USDC is on the proxy.
  preconditions: [
    preconditions.erc20Balance({ wallet: PROXY, token: USDC, balance: '1000000000' }),
  ],
  sweepTo: builder.context.sender,
});
```


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.