@solsdk/jito-ts
Version:
## What is it and why do you need it?
133 lines (86 loc) • 5.68 kB
Markdown
# jito-ts — TypeScript SDK for Jito Block Engine, Relayer, and Geyser
## What is it and why do you need it?
**jito-ts** is a TypeScript SDK for interacting with the Jito infrastructure on Solana: Block Engine (MEV bundles), Relayer, and Geyser (data streaming). It allows you to:
- Form and send MEV bundles to the Jito Block Engine
- Subscribe to bundle processing results
- Get information about leaders, tip accounts, etc.
- Work with the Geyser API for streaming account, program, and block updates
- Simulate bundle execution via RPC
The SDK is intended for developers who want to integrate Jito infrastructure into their services, bots, research utilities, or analytics tools.
## Main components and architecture
- **Block Engine SDK** — work with bundles, sending, subscribing to results, getting information about leaders and tip accounts.
- **Geyser SDK** — subscribe to account, program, and block updates (real-time Solana event streaming).
- **RPC extension** — extended Solana RPC connection class with bundle simulation support.
- **Authorization** — JWT/Access Token support for protected methods (Block Engine, Geyser).
## How to use the SDK
### 1. Installation and setup
- Requires Node.js 20+, yarn >=1.22
- Install dependencies: `yarn`
- For gRPC protocol support, proto files must be generated (usually already in the repo, but if changed — use scripts from `scripts/`)
### 2. Authorization
- Access to Block Engine and Geyser requires keys and/or access token.
- For Block Engine: use a Solana Keypair (file or object).
- For Geyser: access token (issued via Jito admin or support).
### 3. Main usage scenarios
#### Block Engine
- **Forming and sending bundles**: use the `Bundle` class to create atomic sets of transactions, send via `SearcherClient.sendBundle`.
- **Getting information**: methods `getTipAccounts`, `getConnectedLeaders`, `getNextScheduledLeader`.
- **Subscribing to results**: `onBundleResult` — allows you to receive the result of processed bundles.
- **Asynchronous result streaming**: `bundleResults` — async generator for receiving bundle results in for-await-of style (alternative to onBundleResult, convenient for async logic integration).
#### Geyser
- **Subscribe to account updates**: `onAccountUpdate`
- **Subscribe to program updates**: `onProgramUpdate`
- **Subscribe to new blocks**: `onProcessedBlock`
- **Get heartbeat interval**: `getHeartbeatIntervalMillis`
#### RPC
- **Bundle simulation**: use the `JitoRpcConnection` class and the `simulateBundle` method to check how a bundle will execute without sending it to the network.
## Main methods and classes
### Block Engine
- `SearcherClient.sendBundle(bundle)` — send an MEV bundle
- `SearcherClient.getTipAccounts()` — get the list of tip accounts
- `SearcherClient.getConnectedLeaders()` — get the list of validator leaders
- `SearcherClient.getNextScheduledLeader()` — get the next leader
- `SearcherClient.onBundleResult(cb, errCb)` — subscribe to bundle processing results
- `SearcherClient.bundleResults(onError)` — async generator for streaming bundle results (used with for-await-of)
- `Bundle.addTransactions(...txs)` — add transactions to a bundle
- `Bundle.addTipTx(keypair, lamports, tipAccount, blockhash)` — add a tip transaction
### Geyser
- `GeyserClient.onAccountUpdate(accounts, cb, errCb)` — subscribe to account updates
- `GeyserClient.onProgramUpdate(programs, cb, errCb)` — subscribe to program updates
- `GeyserClient.onProcessedBlock(cb, errCb)` — subscribe to new blocks
- `GeyserClient.getHeartbeatIntervalMillis()` — get the heartbeat interval
### RPC
- `JitoRpcConnection.simulateBundle(bundle, config?)` — simulate bundle execution
## How authorization works
- For Block Engine, a Solana Keypair is used: the SDK performs challenge-response and obtains JWT tokens for gRPC.
- For Geyser, an access token is required (issued separately).
- Authorization happens automatically when creating a client if the required parameters are provided.
## Where to find examples
- `src/examples/simple_bundle` — example of sending a simple bundle with memo and tip
- `src/examples/geyser` — example of subscribing to account, program, and block updates via Geyser
## Typical scenarios (without code)
1. **Send an MEV bundle**: create a Bundle, add transactions, add a tip, send via SearcherClient.
2. **Subscribe to results**: use onBundleResult or bundleResults to get the bundle processing status.
3. **Receive account/program/block updates**: create a GeyserClient, subscribe to the required events.
4. **Simulate bundle execution**: use JitoRpcConnection and simulateBundle for dry-run checking.
## FAQ and tips
- For gRPC to work, you need proper access to Jito endpoints (sometimes VPN or IP whitelisting is required).
- If you encounter authorization errors — check the validity of your keys/tokens.
- For production use, it is recommended to handle stream errors and re-subscribe on connection loss.
- For testing, use devnet endpoints if available.
## Links and support
- [NPM jito-ts](https://www.npmjs.com/package/@solsdk/jito-ts)
- [Jito Documentation](https://docs.jito.network/)
If you want to add your own example or extend the SDK — see the structure in the `src/sdk/` folder and follow the existing patterns. Questions and bugs — via Discord or GitHub Issues.
<!--
keywords: solana, jito, mev, block-engine, geyser, sdk, typescript, blockchain, bundles, grpc, relayer, searcher, tip, validator, streaming, rpc, web3, defi, crypto, high-frequency, trading, analytics, bot, solana-sdk, solana-mev, jito-labs
-->