Skip to main content
If your custom logic is compute-heavy, add ComputeBudgetProgram.setComputeUnitLimit({ units: 1_000_000 }) (or higher) as the first instruction in your transaction.
The @jup-ag/lend SDK provides helper functions to retrieve the instructions needed to execute a flashloan. To perform a flashloan, construct a transaction where the borrow instruction occurs first, followed by your custom logic (which uses the borrowed funds), and ending with the payback instruction.
Solana processes the entire list of instructions atomically. If your custom logic fails to return the borrowed amount via paybackIx, the entire transaction reverts and you only pay network fees.

Parameters

getFlashloanIx accepts the following parameters:

Execute Flashloan

1

Import Dependencies

Import the required packages for Solana RPC, Jupiter Lend flashloan SDK, and versioned transaction building.
2

Load Keypair and Initialise Connection

Load the signer and create the RPC connection. Define the asset and borrow amount.
3

Get Flashloan Instructions

Fetch the borrow and payback instructions from the SDK. You borrow and return the same amount with no flashloan fees.
You can also use getFlashBorrowIx and getFlashPaybackIx separately if you need to fetch the instructions independently.
4

Define Custom Logic

Define the instructions that use the borrowed funds. This could be trades, clearing bad debt, collateral swapping, or any custom flashloan logic.
5

Build and Sign Transaction

Assemble the transaction. Order is critical: your custom logic must be placed exactly between the borrow and payback instructions.
6

Send and Confirm Transaction

Send the transaction to the network.

Full code example