Skip to main content
balanceOf resolves a flow input amount from an on-chain ERC20.balanceOf(owner) read at compile time. Use it when the partner wants to spend “whatever the user currently holds” rather than a caller-specified amount — for example, dust-sweep flows or “move my full balance” UX. The owner is typically the sender’s own EOA (builder.context.sender) or the flow’s execution proxy (builder.context.executionAddress). The read is performed by the compiler via an RPC call; the resulting amount is baked into the compiled calldata as a constant.

Example

Sweep the caller’s full USDC balance into a swap:
const builder = sdk.flow(1, {
  name: 'swap-full-balance',
  inputs: { amountIn: resources.erc20(USDC, 1) },
});

builder.lifi.swap('swap', {
  bind: { amountIn: builder.inputs.amountIn },
  config: {
    resourceOut: resources.erc20(WETH, 1),
    slippage: 0.03,
  },
});

const request = sdk.request(builder.build(), {
  signer: OWNER,
  inputs: {
    amountIn: materialisers.balanceOf({ owner: OWNER }),
  },
  sweepTo: builder.context.sender,
});