Skip to main content
This quickstart compiles a Flow that swaps 1 WETH into USDC and zaps the USDC into an Aave lending position on Ethereum. The result lists every transaction the user signs, in order. It follows the Swap and deposit recipe.

Prerequisites

  • Node.js 24 or later, and a LI.FI API key on your server. See Before you start.
  • A signer address. The quickstart compiles the flow but does not send it. Signing and submission are in Build a same-chain flow.

Steps

1

Install the SDK

Install @lifi/composer-sdk and its peer dependency @lifi/compose-spec. Both packages must be on the same version; these docs target 0.14.0.
2

Set your API key

3

Write the flow

Save this as quickstart.ts and replace 0xYourSignerAddress with the signer’s address. It is adapted from swapAndZap.ts in the composer-sdk-examples repo.
4

Run it

The script prints an approval action for WETH and the execute action, then the aEthUSDC output zap.amountOut with its estimate and its minimum.

What the code does

  • Input. amountIn is a resource: a token balance the flow tracks from step to step. You choose input names and node ids (swap, zap); the response keys its outputs by them.
  • Ops. lifi.swap turns WETH into USDC with a 3% slippage bound. lifi.zap takes the swap’s output and deposits it into Aave. See the op catalog.
  • Guard. guards.slippage({ port: 'amountOut', bps: 100 }) makes the transaction revert if the zap delivers more than 1% below the simulated amount. The swap needs no guard: its slippage config already sets a floor. See Guards.
  • Materialiser. directDeposit tells Composer how to fund the input: pull exactly 1 WETH from the signer into the execution proxy.
  • sweepTo. Sends whatever the flow leaves on the proxy, here the aEthUSDC, to the signer. See sweepTo.
  • Result. The default simulation policy throws a ComposeError when the simulation reverts, so the status check only narrows the type. Submit the transactions in result.actions order; see the compile response for every field.
To see the Flow document the SDK sends, call builder.build(). Flow Schema: Complete request shows this flow on the wire.

Next steps

Build a same-chain flow

Signing and submission, runtime values, preconditions and errors, step by step.

Go cross-chain

Run a deposit on another chain, from one signature.
For more complete flows, see Recipes.