# Network

> The default sendTransaction path on the rpc-<region> hostnames: its rate, node rebroadcasting and resending the same transaction.

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

The network path is the default: `sendTransaction` on an `rpc-<region>` hostname, served by the constant-k node. The call works as it does on any Solana RPC. Hostnames are on [Endpoints](https://docs.constant-k.com/get-started/endpoints/).

## Rates

| Plan         | Network path |
| :----------- | :----------- |
| Free         | 1/s          |
| Operator     | 15/s         |
| Blade Runner | 50/s         |
| Nexus        | 200/s        |

The figure is a rate per second, not a monthly allowance, and nothing accrues or expires. Network sends have no monthly cap. Limits are counted per region, so a key holds the full rate in New York and the full rate in Frankfurt at the same time. See [Upstream limits](https://docs.constant-k.com/get-started/upstream-limits/).

## Rebroadcasting

The staked route takes one shot: no retry and no rebroadcast. That is why `maxRetries` is forced to `0` on staked hostnames, and why the client owns retries there. See [Staked endpoints](https://docs.constant-k.com/rpc/sending-transactions/staked/#staked-endpoints).

The constant-k node behaves differently. These settings are the same in every region.

| Setting                                 | Value                      |
| :-------------------------------------- | :------------------------- |
| Leaders a send is forwarded to          | The next 4 in the schedule |
| Rebroadcast interval                    | 420 ms                     |
| Rebroadcasts when `maxRetries` is unset | 2                          |
| Highest `maxRetries` the node honours   | 5                          |

Which of the two applies depends on how the send was routed.

| Send                              | Rebroadcast by                                                                                                                                                                       |
| :-------------------------------- | :----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Any send on a regular hostname    | The node, on the schedule above, unless `maxRetries: 0` is set.                                                                                                                      |
| A staked hostname, `local_` value | The node, on the schedule above. `maxRetries` is passed through, so the client's own value applies.                                                                                  |
| A staked hostname, staked value   | Nobody. `maxRetries` was rewritten to `0` before the send, and that rewritten value also applies if the staked route errors and the transaction is re-sent from the constant-k node. |

A client that sets `maxRetries: 0` and rebroadcasts on its own, as the [send-and-confirm loop](https://docs.constant-k.com/rpc/sending-transactions/#a-send-and-confirm-loop) does, replaces this entirely. A client loop makes the interval and the stopping condition explicit, and does not share the node's retry queue with every other caller when the network is busy.

## Resending the same transaction

The staked path serves a repeat of the same transaction from the constant-k node, so one transaction is never handed to the staked route twice. The window is 60 seconds, about the life of a blockhash.

The match is on the encoded transaction string as sent. A signed transaction always serializes to the same bytes and the same signature, so a rebroadcast matches and is safe by construction. Re-signing against a fresh blockhash produces a different transaction, which takes the staked path again. The same transaction re-encoded from base58 to base64, or the other way, does not match.

Re-signing while the previous transaction can still land is the hazard this does not cover: two transactions with different blockhashes are two transactions, and both can execute. The old blockhash has to expire first.

A transaction served this way is still sent, and the node rebroadcasts it as described in [Rebroadcasting](#rebroadcasting).

## Example

**TypeScript**

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

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

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
        }),
      ],
      m,
    ),
);

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

const signature = await rpc
  .sendTransaction(wireTx, { encoding: "base64", skipPreflight: true, maxRetries: 0n })
  .send();

console.log("Sent:", signature);
```

**cURL**

```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": "sendTransaction",
    "params": [
      "BASE64_SIGNED_TRANSACTION",
      {"encoding": "base64", "skipPreflight": true, "maxRetries": 0}
    ]
  }'
```

**Python**

```python title="network_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) -> str:
    """signed_tx: a signed, serialized transaction, e.g. bytes(tx) from solders."""
    params = [
        base64.b64encode(signed_tx).decode(),
        {"encoding": "base64", "skipPreflight": True, "maxRetries": 0},
    ]
    body = requests.post(
        URL,
        json={"jsonrpc": "2.0", "id": 1, "method": "sendTransaction", "params": params},
        timeout=10,
    ).json()
    if "error" in body:
        raise RuntimeError(body["error"])
    return body["result"]
```
