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

> Execute your first Composer transaction: deposit USDC into a Morpho vault on Base through the LI.FI API.

This quickstart deposits 1 USDC into a Morpho vault on Base in one same-chain transaction: request a quote, approve the token, send the transaction. For cross-chain deposits, see [Cross-chain deposits](https://docs.li.fi/composer/lifi-api/guides/cross-chain-compose.md).

## Prerequisites

* A wallet with USDC on Base (1 USDC is enough)
* Node.js 18+ with `axios` and `viem` installed, or `curl` for the quote only

***

**1. Get a Composer quote**

Request a quote with `toToken` set to the vault token address:

```bash curl theme={"system"}
curl -X GET 'https://li.quest/v1/quote?fromChain=8453&toChain=8453&fromToken=0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913&toToken=0x7BfA7C4f149E7415b73bdeDfe609237e29CBF34A&fromAddress=0xYOUR_WALLET_ADDRESS&fromAmount=1000000'
```

`toToken` is the **position token address** of the target protocol, such as a vault share token. Take it from [Supported Protocols & Chains](https://docs.li.fi/composer/protocols-and-chains.md), which lists every token Composer can route to.

The response includes `transactionRequest`, a ready-to-sign EVM transaction, and the estimated output. The route uses Composer when a step in `includedSteps` has `tool: "composer"`:

```ts TypeScript theme={"system"}
const usesComposer = quote.includedSteps.some(
  (step: { tool: string }) => step.tool === "composer",
);
```

If a DEX can buy the vault token more cheaply, the quote uses that DEX instead (for example `tool: "nordstern"`). The user still receives the vault token.

> [!TIP]
>
> If the user reviews a quote for more than 30 seconds, re-fetch it before signing to get current pricing and simulation results.

**2. Set token allowance**

Approve the address in `quote.estimate.approvalAddress` to spend `fromAmount` of the input token. On Base this is the audited [LI.FI Diamond](https://basescan.org/address/0x1231DEB6f5749EF6cE6943a275A1D3E7486F4EaE) at `0x1231DEB6f5749EF6cE6943a275A1D3E7486F4EaE`; always approve the address returned in the quote. Native tokens such as ETH need no approval. The [full working example](#full-working-example) shows the allowance check, the approval and the send.

> [!WARNING]
>
> If an approval transaction was sent, re-fetch the quote before executing. The gas estimates in the original `transactionRequest` can be stale by the time the approval confirms.

**3. Send the transaction**

Send the `transactionRequest` from the quote. A same-chain route runs in one atomic transaction: either every step (swap and deposit) succeeds, or the transaction reverts and the USDC stays in the wallet. The deposit is complete once the transaction confirms. Cross-chain routes also need status polling and `PARTIAL` handling; see [Cross-chain deposits](https://docs.li.fi/composer/lifi-api/guides/cross-chain-compose.md#status-tracking).

The quote was simulated against current chain state, but prices and state can change before the transaction lands. `estimate.toAmountMin` is the minimum output after slippage; the transaction reverts below it.

***

## Full working example

This script runs the three steps. Set `PRIVATE_KEY` in the environment before running it.

```ts TypeScript theme={"system"}
import axios from 'axios';
import {
  createPublicClient,
  createWalletClient,
  http,
  erc20Abi,
  type Address,
  type Hex,
} from 'viem';
import { privateKeyToAccount } from 'viem/accounts';
import { base } from 'viem/chains';

const API_URL = 'https://li.quest/v1';

// --- Configuration ---
// Read the key from an environment variable; never hard-code it.
const PRIVATE_KEY = process.env.PRIVATE_KEY as Hex;
const RPC_URL = 'https://mainnet.base.org';
const FROM_CHAIN = 8453; // Base
const FROM_TOKEN = '0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913'; // USDC on Base
const TO_TOKEN = '0x7BfA7C4f149E7415b73bdeDfe609237e29CBF34A'; // Morpho vault token
const FROM_AMOUNT = '1000000'; // 1 USDC

// --- Setup ---
const account = privateKeyToAccount(PRIVATE_KEY);
const publicClient = createPublicClient({ chain: base, transport: http(RPC_URL) });
const walletClient = createWalletClient({ account, chain: base, transport: http(RPC_URL) });

// --- Helpers ---
const getQuote = async (fromAddress: string) => {
  const result = await axios.get(`${API_URL}/quote`, {
    params: {
      fromChain: FROM_CHAIN,
      toChain: FROM_CHAIN,
      fromToken: FROM_TOKEN,
      toToken: TO_TOKEN,
      fromAmount: FROM_AMOUNT,
      fromAddress,
    },
  });
  return result.data;
};

// Returns true when an approval transaction was sent.
const ensureAllowance = async (
  tokenAddress: Address,
  approvalAddress: Address,
  amount: bigint
): Promise<boolean> => {
  const allowance = await publicClient.readContract({
    address: tokenAddress,
    abi: erc20Abi,
    functionName: 'allowance',
    args: [account.address, approvalAddress],
  });

  if (allowance < amount) {
    console.log('Setting allowance...');
    const hash = await walletClient.writeContract({
      address: tokenAddress,
      abi: erc20Abi,
      functionName: 'approve',
      args: [approvalAddress, amount],
    });
    await publicClient.waitForTransactionReceipt({ hash });
    console.log('Allowance set.');
    return true;
  }
  return false;
};

// --- Main ---
const run = async () => {
  console.log('Wallet:', account.address);

  // 1. Get quote
  console.log('Requesting Composer quote...');
  let quote = await getQuote(account.address);
  const usesComposer = quote.includedSteps.some(
    (step: { tool: string }) => step.tool === 'composer'
  );
  console.log('Quote received. Tool:', quote.tool, '| Composer:', usesComposer);
  console.log('Estimated output:', quote.estimate.toAmount);

  // 2. Approve, then re-fetch the quote if an approval was sent
  const approved = await ensureAllowance(
    quote.action.fromToken.address as Address,
    quote.estimate.approvalAddress as Address,
    BigInt(quote.action.fromAmount)
  );
  if (approved) quote = await getQuote(account.address);

  // 3. Execute
  console.log('Sending transaction...');
  const hash = await walletClient.sendTransaction({
    to: quote.transactionRequest.to as Address,
    data: quote.transactionRequest.data as Hex,
    value: BigInt(quote.transactionRequest.value),
    gas: BigInt(quote.transactionRequest.gasLimit),
    gasPrice: BigInt(quote.transactionRequest.gasPrice),
  });
  console.log('Tx hash:', hash);

  const receipt = await publicClient.waitForTransactionReceipt({ hash });
  console.log('Confirmed in block:', receipt.blockNumber);
  console.log('Done! USDC converted into Morpho vault tokens.');
};

run().catch(console.error);
```

***

## Next steps

> [card] [Cross-chain deposits](https://docs.li.fi/composer/lifi-api/guides/cross-chain-compose.md)
>
> Bridge + deposit and swap + bridge + deposit across EVM chains

> [card] [Withdrawals Guide](https://docs.li.fi/composer/lifi-api/guides/withdrawals.md)
>
> Add the other half of the user journey with withdraw flows

> [card] [SDK Integration](https://docs.li.fi/composer/lifi-api/guides/sdk-integration.md)
>
> Use the LI.FI SDK for managed execution with hooks and events

> [card] [Vault Deposit Recipes](https://docs.li.fi/composer/lifi-api/recipes/vault-deposits.md)
>
> Copy-paste recipes for Morpho, Aave, Euler, and more


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