> ## 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.

# Quickstart

> Install the SDK and compile your first Flow to calldata in a few minutes.

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](https://docs.li.fi/composer/composer-api/recipes/swap-and-deposit.md).

## Prerequisites

* Node.js 24 or later, and a LI.FI API key on your server. See [Before you start](https://docs.li.fi/composer/composer-api/overview.md#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](https://docs.li.fi/composer/composer-api/guides/build-a-flow.md#wire-in-a-signer).

## 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**.

```bash theme={"system"}
npm install @lifi/composer-sdk @lifi/compose-spec
# or: yarn add @lifi/composer-sdk @lifi/compose-spec
# or: pnpm add @lifi/composer-sdk @lifi/compose-spec
```

**2. Set your API key**

```bash theme={"system"}
export LIFI_API_KEY=<your-key>
```

**3. Write the flow**

Save this as `quickstart.ts` and replace `0xYourSignerAddress` with the signer's address. It is adapted from [`swapAndZap.ts`](https://github.com/lifinance/composer-sdk-examples/blob/main/examples/swapAndZap.ts) in the `composer-sdk-examples` repo.

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

const WETH = '0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2';
const USDC = '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48';
const A_ETH_USDC = '0x98C23E9d8f34FEFb1B7BD6a91B7FF122F4e16F5c';

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

// One resource input: the WETH the flow spends, on chain 1.
const builder = sdk.flow(1, {
  name: 'swap-and-zap-quickstart',
  inputs: {
    amountIn: resources.erc20(WETH, 1),
  },
});

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

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

const main = async () => {
  const result = await builder.compile({
    signer: '0xYourSignerAddress',
    inputs: {
      amountIn: materialisers.directDeposit({
        amount: '1000000000000000000', // 1 WETH (18 decimals)
      }),
    },
    sweepTo: builder.context.sender,
  });

  if (result.status !== 'success') {
    throw new Error(`${result.error.kind}: ${result.error.message}`);
  }

  // Every transaction to submit, in order.
  for (const action of result.actions ?? []) {
    if (action.kind !== 'transaction') continue;
    console.log(action.purpose, action.transactionRequest.to);
  }

  // What the signer receives, with the expected and the guaranteed amount.
  for (const [key, output] of Object.entries(terminalOutputs(result.outputs))) {
    console.log(key, output.amount.estimate?.value, output.amount.minimum?.value);
  }
};

main().catch((err) => {
  console.error(err);
  process.exit(1);
});
```

**4. Run it**

```bash theme={"system"}
npx tsx quickstart.ts
```

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](https://docs.li.fi/composer/composer-api/ops.md).
* **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](https://docs.li.fi/composer/composer-api/concepts/simulation-and-guards.md).
* **Materialiser.** `directDeposit` tells Composer how to fund the input: pull exactly 1 WETH from the signer into the [execution proxy](https://docs.li.fi/composer/composer-api/overview.md#account-model).
* **`sweepTo`.** Sends whatever the flow leaves on the proxy, here the aEthUSDC, to the signer. See [`sweepTo`](https://docs.li.fi/composer/composer-api/concepts/sweeping-and-amounts#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](https://docs.li.fi/composer/composer-api/concepts/execution-model.md#the-compile-response) for every field.

To see the Flow document the SDK sends, call `builder.build()`. [Flow Schema: Complete request](https://docs.li.fi/composer/composer-api/reference/flow-wire-format.md#complete-request) shows this flow on the wire.

## Next steps

> [card] [Build a same-chain flow](https://docs.li.fi/composer/composer-api/guides/build-a-flow.md)
>
> Signing and submission, runtime values, preconditions and errors, step by step.

> [card] [Go cross-chain](https://docs.li.fi/composer/composer-api/guides/build-a-cross-chain-flow.md)
>
> Run a deposit on another chain, from one signature.

For more complete flows, see [Recipes](https://docs.li.fi/composer/composer-api/recipes.md).


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