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

# flashloan

> Source a flow input by borrowing the amount from a flashloan provider, repaid within the same transaction.

<Warning>
  **Not public yet.** Contact us to get early access.
</Warning>

`flashloan` sources a flow input by **borrowing** the amount from a flashloan provider instead of pulling it from the signer. The borrowed amount is made available to the flow as its input, so the rest of the flow can spend capital the user doesn't hold upfront.

Because a flashloan must be repaid in the same transaction, a flow that borrows via this materialiser **must** settle the loan (principal + the provider's fee) before it ends — typically with one or more [`lifi.flashloanRepay`](/composer/composer-api/ops) ops. If the loan isn't repaid, simulation reverts.

Config:

| Field          | Type                                                       | Notes                                                                                                                  |
| -------------- | ---------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------- |
| `providerKind` | `'aave-v3' \| 'erc3156' \| 'balancer-v2' \| 'morpho-blue'` | Which flashloan provider to borrow from. Fees vary by provider (e.g. Aave V3 charges 5 bps; Balancer V2 charges none). |
| `amount`       | integer string                                             | The amount to borrow, in the token's smallest units.                                                                   |

## Example

Borrow USDC via an Aave V3 flashloan and settle it within the flow:

```ts theme={"system"}
const builder = sdk.flow(8453, {
  name: 'flashloan-borrow',
  inputs: {
    borrowed: resources.erc20(USDC, 8453),
  },
});

// ... spend `builder.inputs.borrowed` across ops, then repay the loan
// (principal + fee) with `lifi.flashloanRepay` before the flow ends ...

const request = sdk.request(builder.build(), {
  signer: OWNER,
  inputs: {
    borrowed: materialisers.flashloan({
      providerKind: 'aave-v3',
      amount: '1000000000', // 1,000 USDC (6 decimals)
    }),
  },
});
```

For a complete, tested flow that uses two concurrent flashloans to migrate a borrow position, see the [debt-migration recipe](/composer/composer-api/recipes/debt-migration) and [`aaveToMorphoDebtMigration.ts`](https://github.com/lifinance/composer-sdk-examples/blob/main/examples/staged/aaveToMorphoDebtMigration.ts). For the minimal borrow-and-repay shape, see [`flashloanRepay.ts`](https://github.com/lifinance/composer-sdk-examples/blob/main/examples/staged/flashloanRepay.ts).
