Skip to main content
Deposit to Kamino Earn vaults using the Kamino TypeScript SDK. Create and manage deposit flows with complete flexibility and control.

Earn Deposit with SDK

1

Import Dependencies

Import the required packages for Solana RPC communication, Kamino SDK operations, and Kit transaction building.
import {
  createSolanaRpc,
  createSolanaRpcSubscriptions,
  address,
  pipe,
  createTransactionMessage,
  setTransactionMessageFeePayerSigner,
  setTransactionMessageLifetimeUsingBlockhash,
  appendTransactionMessageInstructions,
  signTransactionMessageWithSigners,
  sendAndConfirmTransactionFactory,
  getSignatureFromTransaction,
} from '@solana/kit';
import { KaminoVault } from '@kamino-finance/klend-sdk';
import { parseKeypairFile } from '@kamino-finance/klend-sdk/dist/utils/signer.js';
import { Decimal } from 'decimal.js';
2

Load Keypair and Initialize Vault

Load the keypair from file, initialize RPC connections, and create the vault instance.
const KEYPAIR_FILE = '/path/to/your/keypair.json';
const signer = await parseKeypairFile(KEYPAIR_FILE);

const rpc = createSolanaRpc('https://api.mainnet-beta.solana.com');
const rpcSubscriptions = createSolanaRpcSubscriptions('wss://api.mainnet-beta.solana.com');

const vault = new KaminoVault(
  rpc,
  address('HDsayqAsDWy3QvANGqh2yNraqcD8Fnjgh73Mhb3WRS5E') // USDC vault
);
3

Build Deposit Instructions

Generate deposit instructions for the specified amount using the SDK.
const depositAmount = new Decimal(1.0);
const bundle = await vault.depositIxs(signer, depositAmount);
const instructions = [...(bundle.depositIxs || [])];

if (!instructions.length) {
  throw new Error('No instructions returned by Kamino SDK');
}
The SDK’s depositIxs method generates all the necessary instructions to deposit assets into the vault, handling token accounts and vault interactions automatically.
4

Build and Sign Transaction

Fetch the latest blockhash and construct the transaction message using the functional pipe pattern.
const { value: latestBlockhash } = await rpc.getLatestBlockhash().send();

const transactionMessage = pipe(
  createTransactionMessage({ version: 0 }),
  (tx) => setTransactionMessageFeePayerSigner(signer, tx),
  (tx) => setTransactionMessageLifetimeUsingBlockhash(latestBlockhash, tx),
  (tx) => appendTransactionMessageInstructions(instructions, tx)
);

const signedTransaction = await signTransactionMessageWithSigners(transactionMessage);
5

Send and Confirm Transaction

Submit the signed transaction to the Solana network and wait for confirmation.
const signature = getSignatureFromTransaction(signedTransaction);

await sendAndConfirmTransactionFactory({ rpc, rpcSubscriptions })(signedTransaction, {
  commitment: 'confirmed',
  skipPreflight: true,
});

console.log('Deposit successful! Signature:', signature);
Your deposit is complete! The SDK handled all the complexity of building the transaction, and your assets are now earning yield in the vault.