Skip to content

Chris2035nku/Jupiter-Swap

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 

Repository files navigation

Jupiter Order Helper (JavaScript)

A resilient helper for building Jupiter swap transactions that automatically probes Ultra → Quote v6 → Lite endpoints, cools down rate-limited URLs, and can build both buy and sell legs with a single call.

Features

  • Endpoint selection: probes Ultra first, then Quote v6, then Lite, with cooldown handling.
  • Rate-limit awareness: cools endpoints on 429s and retries with backoff.
  • Optional Nozomi/Temporal API key injection (if configured via env).
  • Buy & sell builders: one call can return both directions.
  • Legacy or v0 transaction support (auto-deserializes base64).

Install

npm install @solana/web3.js node-fetch

Usage

import { Connection, Keypair } from "@solana/web3.js";
import { buildBuySellTransactions } from "./jupiter.js"; // adjust path as needed

const connection = new Connection("https://api.mainnet-beta.solana.com", "confirmed");
const signer = Keypair.fromSecretKey(/* your secret key Uint8Array */);

const inputMint  = "So11111111111111111111111111111111111111112"; // SOL (wrapped)
const outputMint = "Es9vMFrzaCERmJfrF4H2FYD4KCoNkY11McCe8BenwNYB"; // USDT

const { buyTx, sellTx, buyOrder, sellOrder } = await buildBuySellTransactions({
  inputMint,
  outputMint,
  buyAmountNative: 1_000_000, // lamports or token native units
  sellAmountToken: 0,         // set if you want a sell leg too
  slippage: 1,                // percent → converted to bps internally
  signerKeypair: signer,
  connection,
  forceLegacy: false,
});

// Sign/serialize/send buyTx or sellTx as needed:
// const sig = await connection.sendTransaction(buyTx, [signer], { skipPreflight: false });

Environment Variables

  • ULTRA_API_KEY: Jupiter Ultra API key (adds JUP-API-KEY/x-api-key headers).
  • JUP_ENDPOINT_COOLDOWN_MS: override per-endpoint cooldown after 429 (default 6000).
  • Optional Nozomi/Temporal passthrough:
    • USE_NOZOMI (true/false), NOZOMI_API_KEY / TEMPORAL_API_KEY
    • NOZOMI_ORDER_URL / NOZOMI_ENDPOINT / TEMPORAL_ORDER_URL / TEMPORAL_ENDPOINT

Notes

  • Endpoint choice is cached unless cooled down; logs will indicate Ultra/QuoteV6/Lite.
  • Amounts are expected in native units (e.g., lamports for SOL, token base units).
  • slippage is provided as percent; code converts to basis points.
  • For signing, recent blockhash and fee payer are applied automatically before partial sign.

License

MIT (see root LICENSE).

About

Jupiter Swapping on Solana made easy

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages