> ## Documentation Index
> Fetch the complete documentation index at: https://developers.jup.ag/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Deposit to Earn

> Deposit assets into Jupiter Earn vaults to start earning yield.

Deposit assets into [Jupiter Earn](https://developers.jup.ag/docs/lend/earn.md) vaults using the SDK.\
The SDK generates transaction instructions that you can add to your own transaction flow. The [Earn API](https://developers.jup.ag/docs/lend/earn/api.md) exposes the same operations over HTTP.

***

## Getting Started

Import the required packages for Solana RPC and Jupiter Earn SDK operations.

## 1. Import Dependencies

Import the packages you need for Solana RPC and Jupiter Lend (Earn) SDK operations.

```typescript theme={null}
import { Connection, PublicKey, Transaction } from "@solana/web3.js";
import BN from "bn.js";
import { getDepositIxs, getMintIxs } from "@jup-ag/lend/earn";
```

## 2. Build Instructions

Use the Jupiter Earn SDK to generate deposit instructions.

```typescript theme={null}
const connection = new Connection("https://api.mainnet-beta.solana.com");
const signer = new PublicKey("YOUR_WALLET_ADDRESS");

const { ixs: depositIxs } = await getDepositIxs({
    connection,
    signer,
    asset: new PublicKey("EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v"), // USDC Mint
    amount: new BN(10_000_000), // 10 USDC (6 decimals)
  });

console.log('Deposit Instructions:', depositIxs);
```

> [!NOTE]
>
> **Important**
>
> * `amount` = underlying asset amount being deposited (e.g. USDC)
> * Not vault shares
> * To deposit by specifying the number of vault shares to receive, use `getMintIxs`

## Complete Flow

This example builds, signs, and sends a deposit transaction.

## 1. Import Dependencies

Import the packages you need for Solana RPC and Jupiter Lend (Earn) SDK operations.

```typescript theme={null}
import {
 Connection,
 Keypair,
 PublicKey,
 Transaction,
 sendAndConfirmTransaction,
} from "@solana/web3.js";
import BN from "bn.js";
import { getDepositIxs } from "@jup-ag/lend/earn";
import fs from "fs";
import path from "path";
```

## 2. Set up connection and deposit parameters

Set your RPC, signer, asset mint, and deposit amount.

```typescript theme={null}
const RPC_URL = "https://api.mainnet-beta.solana.com";
const userKeypair = Keypair.generate(); // <-- Replace this with your wallet
const ASSET_MINT = new PublicKey("EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v");
const DEPOSIT_AMOUNT = new BN(10_000_000);
```

If your signer is stored as a local JSON keypair file, you can load it using the helper function below.

```typescript theme={null}
function loadKeypair(keypairPath: string): Keypair {
  const fullPath = path.resolve(keypairPath);
  const secret = JSON.parse(fs.readFileSync(fullPath, "utf8"));
  return Keypair.fromSecretKey(new Uint8Array(secret));
}
```

Then initialise your signer:

```
const userKeypair = loadKeypair("/path/to/your/keypair.json");
```

## 3. Build Deposit Instructions

Build a transaction from the deposit instructions, set blockhash and fee payer, then sign with the user keypair and send the transaction.

```typescript theme={null}
const { ixs: depositIxs } = await getDepositIxs({
    connection,
    signer,
    asset: ASSET_MINT,
    amount: DEPOSIT_AMOUNT,
});
```

## 4. Build and send transaction

Build a transaction from the deposit instructions, set blockhash and fee payer, then sign with the user keypair and send the transaction.

```typescript theme={null}
const latestBlockhash = await connection.getLatestBlockhash();
const transaction = new Transaction({
    feePayer: signer,
    ...latestBlockhash,
});
transaction.add(...depositIxs);

const signature = await sendAndConfirmTransaction(connection, transaction, [userKeypair]);
console.log("Deposit successful! Signature:", signature);
```

> [!TIP]
>
> You have successfully deposited your assets into Jupiter Earn Vaults. Your assets are now earning yield. Check the resulting position with [Read Earn data](https://developers.jup.ag/docs/lend/earn/read-data.md), and exit with [Withdraw](https://developers.jup.ag/docs/lend/earn/withdraw.md).

## Full code example

```typescript expandable theme={null}
import {
    Connection,
    Keypair,
    PublicKey,
    Transaction,
    sendAndConfirmTransaction,
} from "@solana/web3.js";
import BN from "bn.js";
import { getDepositIxs } from "@jup-ag/lend/earn";
import fs from "fs";
import path from "path";


const KEYPAIR_PATH = "/path/to/your/keypair.json"; // Path to your local keypair file (update this path)
const ASSET_MINT = new PublicKey("EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v"); // Asset mint to deposit (USDC for example)
const DEPOSIT_AMOUNT = new BN(10_000_000); // Amount to deposit, in smallest units (e.g., 1 USDC = 1_000_000)
const RPC_URL = "https://api.mainnet-beta.solana.com"; // RPC endpoint

function loadKeypair(keypairPath: string): Keypair {
    const fullPath = path.resolve(keypairPath);
    const secret = JSON.parse(fs.readFileSync(fullPath, "utf8"));
    return Keypair.fromSecretKey(new Uint8Array(secret));
}

// 1. Load user keypair and establish connection
const userKeypair = loadKeypair(KEYPAIR_PATH);
const connection = new Connection(RPC_URL, { commitment: "confirmed" });
const signer = userKeypair.publicKey;

// 2. Get deposit instructions from SDK
const { ixs: depositIxs } = await getDepositIxs({
    connection,
    signer,
    asset: ASSET_MINT,
    amount: DEPOSIT_AMOUNT,
});

if (!depositIxs?.length) {
    throw new Error("No deposit instructions returned by Jupiter Lend SDK.");
}

// 3. Build the transaction with latest blockhash and add deposit instructions
// This prepares the transaction ready to be signed and sent
const latestBlockhash = await connection.getLatestBlockhash();
const transaction = new Transaction({
    feePayer: signer,
    ...latestBlockhash,
});
transaction.add(...depositIxs);
transaction.sign(userKeypair);

// 4. Sign and send the transaction
const signature = await sendAndConfirmTransaction(connection, transaction, [userKeypair]);
console.log("Deposit successful! Signature:", signature);
```


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