Withdraw
The second half of unwinding a position. After you unstake and the farm’s withdrawal cooldown elapses, the stake sits as pending withdrawal. This moves those tokens out of the farm vault back to your token account.This flow requires a non-delegated farm, since the instruction needs the stake token mint. No Scope prices or refresh are needed here, because it moves already-unstaked tokens and does not touch reward accounting. The instruction only succeeds on-chain once the withdrawal cooldown has elapsed; if there is nothing past cooldown, it fails.
1
Import Dependencies
Import the packages for Solana RPC communication, Kit transaction building, the keypair loader, and the Farms SDK.2
Configure Constants and Initialize
Set the keypair path, RPC endpoints, target farm, and stake token mint. Load the signer and initialize the farms client.3
Build Withdraw Instruction
Resolve the user-state key, then build the withdraw-unstaked instruction. The third argument is the farm address.4
Build, Sign, and Send Transaction
Compose the v0 transaction, sign, verify it fits the size limit, then send and confirm.The withdrawal is complete. Your unstaked tokens have been transferred back to your wallet.