> For the complete documentation index, see [llms.txt](https://use.temporal.xyz/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://use.temporal.xyz/nozomi/send-bundle/javascript.md).

# JavaScript

Use full service RPC for fetching latest blockhash.

Two transactions from one signer, tip in the first, sent as one atomic bundle. Both are signed with the same blockhash so they expire together.

```javascript
import { Connection, Keypair, PublicKey, SystemProgram, TransactionMessage, VersionedTransaction } from "@solana/web3.js";
import bs58 from "bs58";

const NOZOMI_ENDPOINT = "https://nozomi.temporal.xyz";
const NOZOMI_API_KEY = "<YOUR_API_KEY>";
const NOZOMI_TIP = new PublicKey("TEMPaMeCRFAS9EKF53Jd6KpHxgL47uWLcpFArU1Fanq");
const TIP_LAMPORTS = 1_000_000; // 0.001 SOL, the default minimum

const SOLANA_RPC_ENDPOINT = "https://api.mainnet-beta.solana.com";

function encodeBundle(rawTxs) {
  if (rawTxs.length === 0 || rawTxs.length > 4) {
    throw new Error("bundle must contain 1-4 transactions");
  }
  let total = 0;
  for (const tx of rawTxs) {
    if (tx.length < 66 || tx.length > 1232) {
      throw new Error(`invalid tx size: ${tx.length}`);
    }
    total += 2 + tx.length;
  }
  const out = Buffer.allocUnsafe(total);
  let off = 0;
  for (const tx of rawTxs) {
    out.writeUInt16BE(tx.length, off);
    off += 2;
    Buffer.from(tx).copy(out, off);
    off += tx.length;
  }
  return out;
}

async function sendBundle(endpoint, apiKey, rawTxs) {
  const res = await fetch(`${endpoint}/api/sendBundle?c=${apiKey}`, {
    method: "POST",
    headers: { "Content-Type": "application/octet-stream" },
    body: encodeBundle(rawTxs),
  });
  if (!res.ok) {
    const text = await res.text();
    throw new Error(`sendBundle failed (${res.status}): ${text}`);
  }
}

function signTx(ixns, signer, blockhash) {
  const message = new TransactionMessage({
    payerKey: signer.publicKey,
    recentBlockhash: blockhash,
    instructions: ixns,
  }).compileToV0Message();
  const tx = new VersionedTransaction(message);
  tx.sign([signer]);
  return tx;
}

function buildFirstIxns() {
  // your instruction building logic for the first transaction..
  return [];
}

function buildSecondIxns() {
  // your instruction building logic for the second transaction..
  return [];
}

async function main() {
  const rpc = new Connection(SOLANA_RPC_ENDPOINT);
  const signer = Keypair.generate(); // replace with actual keypair loading logic

  // One blockhash for every member so the bundle expires as a unit.
  const { blockhash } = await rpc.getLatestBlockhash();

  // Tip goes in the first member; the second is untipped.
  const first = signTx(
    [
      ...buildFirstIxns(),
      SystemProgram.transfer({ fromPubkey: signer.publicKey, toPubkey: NOZOMI_TIP, lamports: TIP_LAMPORTS }),
    ],
    signer,
    blockhash
  );
  const second = signTx(buildSecondIxns(), signer, blockhash);

  // sendBundle returns no signatures: record them before submitting.
  const signatures = [first, second].map((tx) => bs58.encode(tx.signatures[0]));
  console.log("bundle signatures", signatures);

  await sendBundle(NOZOMI_ENDPOINT, NOZOMI_API_KEY, [first.serialize(), second.serialize()]);
  console.log("bundle accepted");

  // Confirm landing: every member lands in the same slot, or none does.
  const statuses = await rpc.getSignatureStatuses(signatures);
  console.log(statuses.value.map((s) => s?.slot ?? null));
}

main().catch((err) => {
  console.error(err);
});
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://use.temporal.xyz/nozomi/send-bundle/javascript.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
