# Astralane

> A sendTransaction that tips an Astralane tip account is sent through Astralane's sender in the region.

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

On the `rpc-<region>` endpoints, a `sendTransaction` that pays a tip to an [Astralane tip account](https://astralane.gitbook.io/docs/low-latency/endpoints-and-configs) is sent through Astralane's sender in the same region. No separate tip transaction is needed: the tip is one of the instructions in the transaction you send.

* constant-k sends each transaction to the nearest Astralane region on its own: `rpc-newyork` to Astralane New York, `rpc-frankfurt` to Frankfurt, `rpc-amsterdam` to Amsterdam. You do not pick an Astralane region or endpoint.
* Send the transaction with `"encoding":"base64"`. Base58 sends and [version 1 transactions](https://docs.constant-k.com/rpc/sending-transactions/#version-1-transactions) take the normal path.
* The tip is a System Program transfer to a tip account in the transaction's own account keys, not one loaded through an address lookup table.
* The minimum tip is 1,000,000 lamports (0.001 SOL) today. A lower tip is sent from the constant-k node as usual. The minimum goes down as more tips go through Astralane; see [Tip schedule](#tip-schedule).
* Your `skipPreflight` setting is passed on.
* When the Astralane path is busy or does not answer, the transaction is sent from the constant-k node. No send is refused for this reason.
* The response carries `X-CK-Tx-Route: astralane`, or a value that starts with `astralane_fallback_` when the transaction went from the constant-k node.
* constant-k also registers a copy of each tipped transaction with Astralane.
* The tip is the user's, paid on-chain to Astralane. Staked and Neon Zero endpoints do not use this path.

## Tip schedule

The minimum tip follows the Astralane tier of the constant-k account. Astralane sets the tier from the tips all constant-k users send through it in the last 7 days. More tips move the account up, and a higher tier has a lower minimum tip.

| Astralane tier | Tips through constant-k, last 7 days | Minimum tip                    | Bundles |
| :------------- | :----------------------------------- | :----------------------------- | :------ |
| Free (today)   | —                                    | 1,000,000 lamports (0.001 SOL) | No      |
| VIP 1          | More than 4 SOL                      | 100,000 lamports (0.0001 SOL)  | Yes     |
| VIP 2          | More than 5 SOL                      | 100,000 lamports (0.0001 SOL)  | Yes     |
| VIP 3          | More than 8 SOL                      | 10,000 lamports (0.00001 SOL)  | Yes     |

* Astralane checks the tier every hour. A move up applies at the next check.
* If the 7-day total stays under a tier's mark, the account drops one tier after a 7-day grace period.
* When the tier changes, constant-k changes the minimum the same day and adds a row to the [changelog](https://docs.constant-k.com/get-started/changelog/).
* Source: [Astralane fee tiers](https://astralane.gitbook.io/docs/low-latency/send-txn-fee-tiers).

## Bundles

Astralane bundles (`sendBundle` with an Astralane tip, up to 4 transactions) are ready on constant-k and open once the Astralane account reaches the tier that includes bundles. Until then, a bundle that tips only Astralane is answered with the error `Astralane bundles are not available yet` and is not sent. Bundles that tip Jito are sent through [Jito](https://docs.constant-k.com/rpc/sending-transactions/jito/) as before.

## Example

The tip transfer goes after the app's own instructions, in the same transaction.

**TypeScript**

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

```ts title="astralane-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";

// An Astralane tip account, https://astralane.gitbook.io/docs/low-latency/endpoints-and-configs
const tipAccount = address("astra4uejePWneqNaJKuFFA8oonqCE1sqF6b45kDMZm");

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

// 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_000_000n), // the tip, after the app instructions
        }),
      ],
      m,
    ),
);

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

// fetch, so the X-CK-Tx-Route response header is visible
const response = await fetch(endpoint, {
  method: "POST",
  headers: { "Content-Type": "application/json" },
  body: JSON.stringify({
    jsonrpc: "2.0",
    id: 1,
    method: "sendTransaction",
    params: [wireTx, { encoding: "base64", skipPreflight: true }],
  }),
});

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

console.log("Sent:", result, "Route:", response.headers.get("x-ck-tx-route"));
```

**cURL**

```bash
curl -sS -D - -o /dev/null "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":"sendTransaction","params":["BASE64_SIGNED_TRANSACTION_WITH_TIP",{"encoding":"base64","skipPreflight":true}]}' \
  | grep -i "x-ck-tx-route"
```

**Python**

```python title="astralane_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(signed_tx: bytes) -> tuple[str, str | None]:
    """signed_tx: a signed transaction that carries a 1,000,000 lamports tip
    transfer to an Astralane tip account among its instructions."""
    params = [
        base64.b64encode(signed_tx).decode(),
        {"encoding": "base64", "skipPreflight": True},
    ]
    response = requests.post(
        URL,
        json={"jsonrpc": "2.0", "id": 1, "method": "sendTransaction", "params": params},
        timeout=10,
    )
    body = response.json()
    if "error" in body:
        raise RuntimeError(body["error"])
    return body["result"], response.headers.get("x-ck-tx-route")
```
