Prerequisites
- Node.js 22 or later.
- A Solana mainnet-beta RPC endpoint. The public endpoint works for reads; use a dedicated provider for trading.
- For steps 3 and 4: a keypair holding USDC (in its associated token account) and a little SOL for transaction fees and, on a first buy, the position account’s rent.
1. Read a market
2. Quote
Quotes are the program’s exact integer answer, computed locally from the market account.3. Buy and sell
buy and sell refuse before signing, with a KashValidationError,
when the market is not accepting the trade, for example because it is
not active or is frozen.
4. Build, simulate, then send
The one-call methods are a build followed by a send. Split them when you want to inspect a plan, simulate it, or hand it to a different signer:5. Redeem and close
After a market resolves (or is cancelled), redeem the position, then close the empty position account to reclaim its rent:Next
Error handling
What each failure means, and which ones are safe to retry.
Runnable examples
Read-and-quote, buy-and-sell, and redeem-and-close scripts.