Redeeming cTokens
Burn cTokens to withdraw your deposit and interest from Kamino lending reserves.1
Import Dependencies
Import the required packages for Solana RPC communication, Kamino SDK operations, and Kit transaction building.2
Load Signer and Initialize Market
Load your keypair from a file and initialize RPC connections and the Kamino market.Replace
/path/to/your/keypair.json with the actual path to your keypair file. The kUsdcMint address represents the cToken (kV-STKUSDC) that you’ll be redeeming.3
Get User’s cToken Balance
Query the user’s cToken account to determine how many tokens can be redeemed.The
getTokenAccountsByOwner method fetches all token accounts owned by your wallet for the specified mint. The balance represents the total amount of cTokens you can redeem.4
Build Redeem Reserve Collateral Instructions
Generate instructions to redeem cTokens and receive the underlying asset plus interest.The
buildRedeemReserveCollateralTxns method creates instructions to burn your cTokens (kV-STKUSDC) and receive the underlying USDC plus any accrued interest. The redemption amount is calculated based on the current exchange rate.5
Build and Sign Transaction
Use Kit’s functional pipe pattern to build and sign the transaction with a fresh blockhash.6
Send and Confirm Transaction
Send the redemption transaction and wait for confirmation to receive your underlying assets.Once the transaction is confirmed, your cTokens (kV-STKUSDC) will be burned and you’ll receive the underlying asset (USDC) plus any interest earned during the holding period. The USDC will appear in your wallet.