# Jito

> Sending through Jito with `sendBundle`, one transaction or a bundle of up to 5, relayed to the Jito Block Engine, with the limits and how keys take turns.

Source: https://docs.constant-k.com/rpc/sending-transactions/jito/

`sendBundle` sends a bundle in the Jito format through the endpoint, and constant-k relays it to the Jito Block Engine in the same region (Frankfurt, New York, Amsterdam). It is included in the Operator, Blade Runner and Nexus plans, not in the Free plan. It is served on the `rpc-<region>` hostnames, not on the `staked-rpc-<region>` or Neon Zero hostnames.

The methods are [sendBundle](https://docs.constant-k.com/rpc/http/sendbundle/), [simulateBundle](https://docs.constant-k.com/rpc/http/simulatebundle/), [getBundleStatuses](https://docs.constant-k.com/rpc/http/getbundlestatuses/) and [getInflightBundleStatuses](https://docs.constant-k.com/rpc/http/getinflightbundlestatuses/).

## How a bundle lands

A bundle is 1 to 5 signed transactions. They run in order and land together, or none land. If one transaction fails, none land, and a failed bundle costs nothing.

The bundle must pay a tip of at least 1,000 lamports to a Jito tip account, inside one of its transactions. The tip goes to Jito and the leader, not to constant-k.

A bundle lands only when the current leader runs a Jito or BAM client. The `encoding` parameter takes `base58` by default; `base64` is recommended.

## One transaction through Jito

A `sendTransaction` on an `rpc-<region>` endpoint that pays a Jito tip account is sent to the Jito Block Engine in the same region.

* Send the transaction with `"encoding":"base64"`. The tip is a System Program transfer of at least 1,000 lamports to a [Jito tip account](https://docs.jito.wtf/lowlatencytxnsend/#gettipaccounts), in the transaction's own account keys.
* It shares the region's Jito relay with bundles. When the relay is busy or Jito does not answer, the transaction is sent from the constant-k node instead. No send is refused for this reason.
* The response carries `X-CK-Tx-Route: jito`, or a value that starts with `jito_fallback_` when the transaction went from the constant-k node.
* A transaction that also tips an Astralane tip account at or above the [Astralane minimum](https://docs.constant-k.com/rpc/sending-transactions/astralane/) is sent through Astralane.
* To send it as a bundle of one instead, so a failed transaction costs nothing, use `sendBundle`.

Every plan includes it. On the Free plan, `sendTransaction` and `sendBundle` run at 1 per second.

## Example

**TypeScript**

```bash
npm install @solana/kit @solana-program/system @solana-program/compute-budget
```

```ts title="bundle-send.ts"
import { readFileSync } from "node:fs";
import {
  address,
  appendTransactionMessageInstructions,
  createKeyPairSignerFromBytes,
  createSolanaRpc,
  createTransactionMessage,
  getBase64EncodedWireTransaction,
  lamports,
  pipe,
  setTransactionMessageFeePayerSigner,
  setTransactionMessageLifetimeUsingBlockhash,
  signTransactionMessageWithSigners,
} from "@solana/kit";
import {
  getSetComputeUnitLimitInstruction,
  getSetComputeUnitPriceInstruction,
} from "@solana-program/compute-budget";
import { getTransferSolInstruction } from "@solana-program/system";

// A Jito tip account, https://docs.jito.wtf/lowlatencytxnsend/
const tipAccount = address("96gYZGLnJYVFmbjzopPSU6QiEV5fGqZNyN9nmNhvrZU5");

const rpc = createSolanaRpc(
  `https://rpc-newyork.constant-k.com/?api-key=${process.env.CK_API_KEY}`,
);

// A Solana CLI keypair file (JSON array of 64 bytes)
const payer = await createKeyPairSignerFromBytes(
  new Uint8Array(JSON.parse(readFileSync(process.env.KEYPAIR_PATH!, "utf8"))),
);

const { value: latestBlockhash } = await rpc
  .getLatestBlockhash({ commitment: "confirmed" })
  .send();

const message = pipe(
  createTransactionMessage({ version: 0 }),
  (m) => setTransactionMessageFeePayerSigner(payer, m),
  (m) => setTransactionMessageLifetimeUsingBlockhash(latestBlockhash, m),
  (m) =>
    appendTransactionMessageInstructions(
      [
        getSetComputeUnitLimitInstruction({ units: 1_000 }),
        getSetComputeUnitPriceInstruction({ microLamports: 10_000n }),
        getTransferSolInstruction({
          source: payer,
          destination: address("RECIPIENT_ADDRESS"),
          amount: lamports(1_000_000n), // 0.001 SOL
        }),
        getTransferSolInstruction({
          source: payer,
          destination: tipAccount,
          amount: lamports(1_000n), // the bundle tip, inside the transaction
        }),
      ],
      m,
    ),
);

const signedTx = await signTransactionMessageWithSigners(message);
const wireTx = getBase64EncodedWireTransaction(signedTx);

const response = await fetch(
  `https://rpc-newyork.constant-k.com/?api-key=${process.env.CK_API_KEY}`,
  {
    method: "POST",
    headers: { "Content-Type": "application/json" },
    body: JSON.stringify({
      jsonrpc: "2.0",
      id: 1,
      method: "sendBundle",
      params: [[wireTx], { encoding: "base64" }],
    }),
  },
);

const { result, error } = await response.json();
if (error) {
  throw new Error(JSON.stringify(error));
}

console.log("Bundle id:", result);
```

**cURL**

One transaction that carries the tip transfer:

```bash
curl "https://rpc-newyork.constant-k.com/?api-key=YOUR_API_KEY" \
  -X POST -H "Content-Type: application/json" \
  -d '{
    "jsonrpc": "2.0",
    "id": 1,
    "method": "sendBundle",
    "params": [["BASE64_SIGNED_TRANSACTION"], {"encoding": "base64"}]
  }'
```

**Python**

```python title="bundle_send.py"
import base64
import os

import requests

URL = f"https://rpc-newyork.constant-k.com/?api-key={os.environ['CK_API_KEY']}"

def send_bundle(signed_txs: list[bytes]) -> str:
    """signed_txs: 1 to 5 signed transactions, in the order they should run.

    One of them carries the tip transfer to a Jito tip account.
    """
    params = [
        [base64.b64encode(tx).decode() for tx in signed_txs],
        {"encoding": "base64"},
    ]
    body = requests.post(
        URL,
        json={"jsonrpc": "2.0", "id": 1, "method": "sendBundle", "params": params},
        timeout=10,
    ).json()
    if "error" in body:
        raise RuntimeError(body["error"])
    return body["result"]
```

## Limits

| Limit                  | Applies to                       | Value                                                                                                                                                                                                                                                                                                   |
| :--------------------- | :------------------------------- | :------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| Plan bundle rate       | Your key, per region             | `sendBundle` requests: Operator 1 every 2 s, Blade Runner 2/s, Nexus 5/s. A request over the rate returns HTTP `429`, `Rate limit exceeded (sendBundle: <rate>)`, with `Retry-After` and `X-Retry-After-Ms`.                                                                                            |
| Plan transaction limit | Your key, per region             | Each transaction in a bundle counts as one send: Operator 15/s, Blade Runner 50/s, Nexus 200/s. Bundle transactions share this limit with `sendTransaction`.                                                                                                                                            |
| Plan bundle limit      | Your key, per region             | `simulateBundle`, `getBundleStatuses` and `getInflightBundleStatuses` together: Operator 5/s, Blade Runner 25/s, Nexus 100/s. `simulateBundle` runs in the region and does not use the relay rate.                                                                                                      |
| Landing rate           | Your key, per region             | When fewer than half of a key's recent bundles land, its `sendBundle` rate and its share of the relay fall with it, down to a tenth of the plan's at 0%. The plan rate returns as bundles land. Recent bundles count most: a bundle sent 30 minutes ago counts half. See [Landing rate](#landing-rate). |
| Relay rate             | Every key in the region together | Set by Jito; today 5 bundle requests per second per region. Bundle status calls count against it too.                                                                                                                                                                                                   |

`getSignatureStatuses` on the transaction signatures checks whether a bundle landed without using the relay rate.

## Taking turns

The relay rate is shared, so keys take turns at it.

* When only one key is sending bundles in a region, it gets every opening, and the relay never sits idle while that key is waiting.
* When several keys want the relay at the same moment, openings are shared in proportion to each plan's bundle rate (Nexus 5, Blade Runner 2, Operator 1 every 2 s) times the key's landing factor. Of the keys waiting, the next opening goes to the one furthest behind its share.
* A refused request returns HTTP `429`, code `-32005`, `Bundle relay busy: fair share at this site, retry in <N> ms`, with the headers `Retry-After` (seconds) and `X-Retry-After-Ms`.
* `X-Retry-After-Ms` is the earliest moment the key can be served. A key that sends more than its share gets no extra openings.
* A refused request does not count against the plan's transaction limit.
* A bundle that cannot go out yet waits at the relay for up to 1 second and is sent the moment its turn comes. It is refused only when its turn does not come within that time.

## Landing rate

Jito raises the region's relay rate when more of the relayed bundles land, so the relay favours keys whose bundles land.

| Item                    | Value                                                                                                                                                                                                                                                                                                                                                                 |
| :---------------------- | :-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Landed                  | The bundle's first transaction is confirmed without an error on the region's node within 90 seconds. A landed bundle is a win.                                                                                                                                                                                                                                        |
| Counts against the rate | A bundle counts against the rate when it reverted in the simulation before the relay, when Jito Block Engine reports it `Invalid`, or when its score is under the region's low-score line. Each lowers the landing rate.                                                                                                                                              |
| Not counted             | A bundle is not counted when its durable nonce was already used by another transaction, when the simulation timed out or was unavailable, or when it was valid, scored fine, and did not win. The landing rate is unchanged.                                                                                                                                          |
| Score                   | The tip plus the priority fee, divided by the requested compute units. Jito ranks bundles by this measure.                                                                                                                                                                                                                                                            |
| Low-score line          | The 10th percentile of the scores of landed bundles in the region over the last 24 hours. A bundle under this line counts against the rate. It is off until 200 bundles have landed.                                                                                                                                                                                  |
| Counted from            | 20 checked bundles. Before that the key keeps the full plan rate.                                                                                                                                                                                                                                                                                                     |
| Starts over             | After 24 hours with no bundle in the region. The key then has the full plan rate again for its next 20 checked bundles. A shorter pause keeps the landing rate.                                                                                                                                                                                                       |
| Landing factor          | The landing rate divided by 50%, between 0.1 and 1. At 50% or more it is 1.                                                                                                                                                                                                                                                                                           |
| Applies to              | The key's `sendBundle` rate and its share of the relay, per region.                                                                                                                                                                                                                                                                                                   |
| Simulation              | At a landing factor of 1, bundles are not simulated: landed bundles show they work, and a bundle never waits for a simulation. Under 1, every bundle is simulated on the region's current state before the relay, and a bundle that fails simulation is refused with a chance of 1 minus the factor: half at 0.5, nine in ten at 0.1. A refused bundle counts as bad. |
| Headers                 | Every `sendBundle` answer carries `X-Bundle-Landing-Rate` (percent) and `X-Bundle-Rate-Factor` once the rate counts.                                                                                                                                                                                                                                                  |

A bundle whose compute unit limit is close to its simulated use scores higher. A bundle that requests the default 200,000 per instruction scores low.

A bundle refused after its simulation returns HTTP `400`, `Simulation failed: <error>. Fewer than half of your recent bundles landed in this region, so bundles that fail simulation can be refused`. The same bundle sent again gets the same answer.

A request over the reduced rate returns HTTP `429`, `Rate limit exceeded (sendBundle: <rate>). The rate is reduced because <N>% of your recent bundles landed in this region; at 50% or more the plan rate returns`, with `Retry-After` and `X-Retry-After-Ms`.

## Sending well

* One bundle per opportunity. Copies of one trade sent together use up the region's relay rate, and at most one of them can land.
* An exact copy of a bundle (the same transactions in the same order) sent to the same region within 60 seconds is refused with `Duplicate bundle` and is not relayed again. It still counts against the plan's transaction limit.
* Versions of the same trade from one key are sent once. A version is the same payer and the same instructions with a different tip, priority fee, compute unit limit or blockhash. Only the version with the best score goes to Jito: the score is the tip plus the priority fee, divided by the requested compute units, the way Jito and BAM rank bundles. The other versions are refused with `Superseded`, and so is any version of that trade sent within 2 seconds after one went out.
* The `X-Retry-After-Ms` value replaces a fixed backoff.
* Landing is checked with `getSignatureStatuses`.
* The tip and the priority fee, over the requested compute units, set the bundle's place in the Jito auction. A compute unit limit close to what the transaction uses beats a bigger tip with a loose limit. A transaction with no limit is charged the default of 200,000 compute units per instruction. The relay does not change the tip.
* A bundle can be checked first with `simulateBundle`. Its transactions run in order on the region's current state, and each one sees the changes of the ones before it.
* Bundles land more often with a recent blockhash, a compute unit limit close to the units used, a tip that matches the current auction, and one bundle per opportunity. Bundles that land keep the key's full rate.

## Tips and bundles

Stake-weighted delivery, a priority fee and a tip act at different stages, so one does not substitute for another.

| Mechanism              | What it decides                                                              |
| :--------------------- | :--------------------------------------------------------------------------- |
| Staked path            | Whether the leader accepts the connection when its inbound capacity is full. |
| Priority fee           | Where the transaction ranks once the leader holds it.                        |
| Tip to a block builder | Whether several transactions land together and in order, or not at all.      |

A staked send carrying no meaningful compute unit price still loses to transactions that pay one, because reaching the leader and being chosen by the leader are separate problems. Atomicity across more than one transaction is the one thing neither the staked path nor a priority fee provides.

Bundle status comes from [getBundleStatuses](https://docs.constant-k.com/rpc/http/getbundlestatuses/) and [getInflightBundleStatuses](https://docs.constant-k.com/rpc/http/getinflightbundlestatuses/), which count against the plan's bundle limit, or from `getSignatureStatuses` on the transaction signatures, which does not use the bundle relay. Limits and taking turns are above; the staked path is on [SWQoS](https://docs.constant-k.com/rpc/sending-transactions/staked/) and priority fees on [Priority fees](https://docs.constant-k.com/rpc/sending-transactions/#priority-fees).

## Jito relay stats API

`GET https://www.constant-k.com/wp-json/ck-jito-relay/v1/stats` returns the key's relay numbers, the same ones the My Account Jito Relay section shows. The API key goes in the `X-API-Key` header or in `Authorization: Bearer`. The call goes to `www.constant-k.com`; a redirect drops the header, so the bare domain does not work.

```bash
curl -s https://www.constant-k.com/wp-json/ck-jito-relay/v1/stats \
  -H "X-API-Key: YOUR_API_KEY"
```

| Field                   | Meaning                                                                               |
| :---------------------- | :------------------------------------------------------------------------------------ |
| `state`                 | `ok`, `limited` (the relay holds some of the key's bundles back) or `no_data`.        |
| `relay_allowed_pct`     | The lowest across the regions. Below 100 means the key is limited.                    |
| `landing_rate_pct`      | Landed over checked, the rate the My Account section shows.                           |
| `send_rate`             | Bundles per second right now, all regions added up.                                   |
| `last_hour`, `last_24h` | Counters: `relayed`, `landed`, `missed`, `unchecked`, `held_back`, `refused_by_jito`. |
| `sites`                 | The same numbers for each region.                                                     |

The numbers update about once a minute, so polling every 60 seconds is enough. The steering fields are `landing_rate_pct`, `relay_allowed_pct` and `state: limited`; `unchecked` only says the landing check did not see those bundles, which is normal for busy keys. A rate with no data is `null`, never 0.

| Status | Meaning                                                               |
| :----- | :-------------------------------------------------------------------- |
| `401`  | The key is missing or unknown.                                        |
| `503`  | The stats are briefly unavailable; they return within about a minute. |
