### Quick start Source: https://github.com/jup-ag/docs/blob/main/guides/how-to-get-token-information.mdx A quick start example using curl to search for tokens by query. ```bash curl -X GET "https://api.jup.ag/tokens/v2/search?query=JUP" \ -H "x-api-key: YOUR_API_KEY" ``` -------------------------------- ### Install Libraries Source: https://github.com/jup-ag/docs/blob/main/get-started/environment-setup.mdx Install @solana/web3.js (v1) for transaction handling and @solana/spl-token for SPL token operations. ```bash npm install @solana/web3.js@1 @solana/spl-token bs58 ``` -------------------------------- ### Install the package Source: https://github.com/jup-ag/docs/blob/main/tool-kits/plugin/react-app-example.mdx Command to install the @jup-ag/plugin package using npm. ```bash npm install @jup-ag/plugin ``` -------------------------------- ### Full Referral SDK Example Source: https://github.com/jup-ag/docs/blob/main/ultra/add-fees-to-ultra.mdx This example demonstrates the complete workflow for setting up and managing referral accounts and fees using the referral SDK. It includes initializing referral accounts, setting up token accounts for specific tokens, and claiming all accrued fees. Ensure you have the necessary dependencies installed and replace placeholder values with your actual project and account details. ```javascript import { ReferralProvider } from "@jup-ag/referral-sdk"; import { Connection, Keypair, PublicKey, sendAndConfirmTransaction, sendAndConfirmRawTransaction } from "@solana/web3.js"; import fs from 'fs'; const connection = new Connection("https://api.mainnet-beta.solana.com"); const privateKeyArray = JSON.parse(fs.readFileSync('/Path/to/.config/solana/id.json', 'utf8').trim()); const wallet = Keypair.fromSecretKey(new Uint8Array(privateKeyArray)); const provider = new ReferralProvider(connection); const projectPubKey = new PublicKey('DkiqsTrw1u1bYFumumC7sCG2S8K25qc2vemJFHyW2wJc'); async function initReferralAccount() { const transaction = await provider.initializeReferralAccountWithName({ payerPubKey: wallet.publicKey, partnerPubKey: wallet.publicKey, projectPubKey: projectPubKey, name: "insert-name-here", }); const referralAccount = await connection.getAccountInfo( transaction.referralAccountPubKey, ); if (!referralAccount) { const signature = await sendAndConfirmTransaction(connection, transaction.tx, [wallet]); console.log('signature:', `https://solscan.io/tx/${signature}`); console.log('created referralAccountPubkey:', transaction.referralAccountPubKey.toBase58()); } else { console.log( `referralAccount ${transaction.referralAccountPubKey.toBase58()} already exists`, ); } } async function initReferralTokenAccount() { const mint = new PublicKey("So11111111111111111111111111111111111111112"); // the token mint you want to collect fees in const transaction = await provider.initializeReferralTokenAccountV2({ payerPubKey: wallet.publicKey, referralAccountPubKey: new PublicKey("insert-referral-account-pubkey-here"), // you get this from the initReferralAccount function mint, }); const referralTokenAccount = await connection.getAccountInfo( transaction.tokenAccount, ); if (!referralTokenAccount) { const signature = await sendAndConfirmTransaction(connection, transaction.tx, [wallet]); console.log('signature:', `https://solscan.io/tx/${signature}`); console.log('created referralTokenAccountPubKey:', transaction.tokenAccount.toBase58()); console.log('mint:', mint.toBase58()); } else { console.log( `referralTokenAccount ${transaction.tokenAccount.toBase58()} for mint ${mint.toBase58()} already exists`, ); } } async function claimAllTokens() { const transactions = await provider.claimAllV2({ payerPubKey: wallet.publicKey, referralAccountPubKey: new PublicKey("insert-referral-account-pubkey-here"), }) // Send each claim transaction one by one. for (const transaction of transactions) { transaction.sign([wallet]); const signature = await sendAndConfirmRawTransaction(connection, transaction.serialize(), [wallet]); console.log('signature:', `https://solscan.io/tx/${signature}`); } } // initReferralAccount(); // you should only run this once // initReferralTokenAccount(); // claimAllTokens(); ``` -------------------------------- ### Full Code Example Source: https://github.com/jup-ag/docs/blob/main/lend/borrow/create-position.mdx This example demonstrates how to create a lend/borrow position by loading a keypair, getting the create-position instruction, building the transaction, and sending it. ```typescript import { Connection, Keypair, Transaction, sendAndConfirmTransaction, } from "@solana/web3.js"; import { getInitPositionIx } from "@jup-ag/lend/borrow"; import fs from "fs"; import path from "path"; const KEYPAIR_PATH = "/path/to/your/keypair.json"; // Path to your local keypair file (update this path) const RPC_URL = "https://api.mainnet-beta.solana.com"; // RPC endpoint const VAULT_ID = 1; // Target vault (market); check protocol docs for vault IDs function loadKeypair(keypairPath: string): Keypair { const fullPath = path.resolve(keypairPath); const secret = JSON.parse(fs.readFileSync(fullPath, "utf8")); return Keypair.fromSecretKey(new Uint8Array(secret)); } // 1. Load user keypair and establish connection const userKeypair = loadKeypair(KEYPAIR_PATH); const connection = new Connection(RPC_URL, { commitment: "confirmed" }); const signer = userKeypair.publicKey; // 2. Get create-position instruction from SDK const { ix, nftId } = await getInitPositionIx({ vaultId: VAULT_ID, connection, signer, }); // 3. Build the transaction with latest blockhash and add create-position instruction // This prepares the transaction ready to be signed and sent (legacy transaction) const latestBlockhash = await connection.getLatestBlockhash(); const transaction = new Transaction({ feePayer: signer, ...latestBlockhash, }); transaction.add(ix); // 4. Sign and send the transaction const signature = await sendAndConfirmTransaction(connection, transaction, [userKeypair]); console.log("Create position successful! Position ID (nftId):", nftId); console.log("Signature:", signature); ``` -------------------------------- ### Create React Project Source: https://github.com/jup-ag/docs/blob/main/tool-kits/plugin/react-app-example.mdx Command to create a new React project with TypeScript template and start the development server. ```bash npx create-react-app plugin-demo --template typescript cd plugin-demo npm start ``` -------------------------------- ### Method 2: Using @jup-ag/plugin Package Source: https://github.com/jup-ag/docs/blob/main/tool-kits/plugin/nextjs-app-example.mdx This code snippet demonstrates how to initialize the Jupiter Plugin by installing and importing the @jup-ag/plugin package in a Next.js component. ```bash npm install @jup-ag/plugin ``` ```javascript "use client"; import React, { useEffect } from "react"; import "@jup-ag/plugin/css"; export default function PluginComponent() { useEffect(() => { import("@jup-ag/plugin").then((mod) => { const { init } = mod; init({ displayMode: "widget", integratedTargetId: "jupiter-plugin", }); }); }, []); return (

Jupiter Plugin Demo

); } ``` -------------------------------- ### Create a New Next.js Project Source: https://github.com/jup-ag/docs/blob/main/tool-kits/plugin/nextjs-app-example.mdx Creates a new Next.js project with the TypeScript template and starts the development server. ```bash npx create-next-app@latest plugin-demo --typescript cd plugin-demo npm run dev ``` -------------------------------- ### GET /squads/v5/order Request Example Source: https://github.com/jup-ag/docs/blob/main/swap/multisig.mdx Example of how to call the GET /squads/v5/order endpoint to initiate a multisig swap. ```typescript import { Jupiter } from "@jup-ag/core"; const jupiter = new Jupiter.Core({ cluster: "mainnet-beta", // or "devnet", "testnet" }); async function getMultisigOrder() { const inputMint = "So11111111111111111111111111111111111111112"; // SOL const outputMint = "EPjFWdd5AufqSSqeM2qN1xzyb2AR8G9AEiVvWzWjVz2"; // USDC const amount = "1000000"; // 1 SOL in lamports const taker = "YOUR_VAULT_PDA"; // Your Squads V5 vault PDA const settingsPda = "YOUR_SETTINGS_PDA"; // Your Squads V5 settings PDA const signers = "SIGNER_1_PUBKEY,SIGNER_2_PUBKEY,SIGNER_3_PUBKEY"; // Comma-separated signer public keys, first is fee payer try { const order = await jupiter.swap.getSquadsV5Order({ inputMint, outputMint, amount, taker, settingsPda, signers, }); console.log("Order details:", order); // order.transaction is the base64 encoded transaction ready to be signed // order.requestId is the UUID to pass to the execute endpoint } catch (error) { console.error("Error getting multisig order:", error); } } getMultisigOrder(); ``` -------------------------------- ### Run the Project Source: https://github.com/jup-ag/docs/blob/main/tool-kits/plugin/html-app-example.mdx Command to run the project using http-server. ```bash http-server ``` -------------------------------- ### Get all verified tokens Source: https://github.com/jup-ag/docs/blob/main/guides/how-to-get-token-information.mdx Example of getting all verified tokens using JavaScript. ```javascript const response = await fetch( 'https://api.jup.ag/tokens/v2/tag?query=verified', { headers: { 'x-api-key': 'YOUR_API_KEY' } } ); const verifiedTokens = await response.json(); ``` -------------------------------- ### Set up dependencies and wallet for signing Source: https://github.com/jup-ag/docs/blob/main/ultra/execute-order.mdx This snippet shows how to set up dependencies and a development wallet for signing transactions. ```bash npm install @solana/web3.js@1 ``` -------------------------------- ### Get all verified tokens Source: https://github.com/jup-ag/docs/blob/main/guides/how-to-get-token-information.mdx Example of getting all verified tokens using curl. ```bash curl -X GET "https://api.jup.ag/tokens/v2/tag?query=verified" \ -H "x-api-key: YOUR_API_KEY" ``` -------------------------------- ### Install Dependencies Source: https://github.com/jup-ag/docs/blob/main/ultra/add-fees-to-ultra.mdx Install the necessary SDKs for referral functionality and Solana interactions. ```bash npm install @jup-ag/referral-sdk npm install @solana/web3.js@1 # Using v1 of web3.js instead of v2 ``` -------------------------------- ### Get price for a single token Source: https://github.com/jup-ag/docs/blob/main/guides/how-to-get-token-price.mdx Example of how to get the price for a single token using cURL, JavaScript, and Python. ```bash curl -X GET "https://api.jup.ag/price/v3?ids=So11111111111111111111111111111111111111112" \ -H "x-api-key: YOUR_API_KEY" ``` ```javascript const response = await fetch( 'https://api.jup.ag/price/v3?ids=So11111111111111111111111111111111111111112', { headers: { 'x-api-key': 'YOUR_API_KEY' } } ); if (!response.ok) { throw new Error(`HTTP ${response.status}: ${response.statusText}`); } const prices = await response.json(); const solPrice = prices['So11111111111111111111111111111111111111112'].usdPrice; console.log(`SOL: $${solPrice}`); ``` ```python import requests response = requests.get( 'https://api.jup.ag/price/v3', params={'ids': 'So11111111111111111111111111111111111111112'}, headers={'x-api-key': 'YOUR_API_KEY'} ) response.raise_for_status() prices = response.json() sol_price = prices['So11111111111111111111111111111111111111112']['usdPrice'] print(f"SOL: ${sol_price}") ``` -------------------------------- ### Successful example response Source: https://github.com/jup-ag/docs/blob/main/ultra/get-balances.mdx An example of a successful response when fetching token balances. ```json { "SOL": { "amount": "0", "uiAmount": 0, "slot": 324307186, "isFrozen": false } } ``` -------------------------------- ### Failed example response Source: https://github.com/jup-ag/docs/blob/main/ultra/get-holdings.mdx An example of a failed response from the holdings endpoint, indicating an invalid address. ```json { "error": "Invalid address" } ``` -------------------------------- ### Create a New HTML Project Source: https://github.com/jup-ag/docs/blob/main/tool-kits/plugin/html-app-example.mdx Commands to create a new project directory and touch an index.html file. ```bash mkdir plugin-democd plugin-demotouch index.html ``` -------------------------------- ### Development Wallet using Solana CLI keyfile Source: https://github.com/jup-ag/docs/blob/main/get-started/environment-setup.mdx Load a development wallet from the Solana CLI keyfile. ```javascript import { Keypair } from '@solana/web3.js'; import fs from 'fs'; const privateKeyArray = JSON.parse( fs.readFileSync('/Path/to/.config/solana/id.json', 'utf8').trim() ); const wallet = Keypair.fromSecretKey(new Uint8Array(privateKeyArray)); ``` -------------------------------- ### Install Referral SDK Source: https://github.com/jup-ag/docs/blob/main/swap/order-and-execute.mdx Install the Jupiter Referral SDK using npm. This is the first step before setting up referral accounts. ```bash npm install @jup-ag/referral-sdk ``` -------------------------------- ### Successful example response Source: https://github.com/jup-ag/docs/blob/main/ultra/get-holdings.mdx An example of a successful response from the holdings endpoint, showing native SOL balance and token holdings. ```json { "amount": "1000000000", "uiAmount": 1, "uiAmountString": "1", "tokens": { "jupSoLaHXQiZZTSfEWMTRRgpnyFm8f6sZdosWBjx93v": [ { "account": "tokenaccountaddress", "amount": "1000000000", "uiAmount": 1, "uiAmountString": "1", "isFrozen": false, "isAssociatedTokenAccount": true, "decimals": 9, "programId": "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA" } ] } } ``` -------------------------------- ### HTML Example Source: https://github.com/jup-ag/docs/blob/main/guides/how-to-embed-a-swap-widget.mdx A complete HTML file demonstrating how to initialize the Jupiter Plugin with the integrated display mode. ```html Jupiter Plugin Demo

Jupiter Plugin Demo

``` -------------------------------- ### Example API Response for Prices Source: https://github.com/jup-ag/docs/blob/main/guides/how-to-get-token-price.mdx An example of the JSON response structure returned by the Jupiter API for token prices. ```json { "So11111111111111111111111111111111111111112": { "createdAt": "2024-06-05T08:55:25.527Z", "liquidity": 621679197.67, "usdPrice": 147.48, "blockId": 348004023, "decimals": 9, "priceChange24h": 1.29 }, "JUPyiwrYJFskUPiHa7hkeR8VUtAeFoSYbKedZNsDvCN": { "createdAt": "2024-06-07T10:56:42.584Z", "liquidity": 3036749.38, "usdPrice": 0.85, "blockId": 348004026, "decimals": 6, "priceChange24h": 2.15 } } ``` -------------------------------- ### Install Dependencies Source: https://github.com/jup-ag/docs/blob/main/lend/advanced/multiply.mdx Install necessary Solana web3, Jupiter Lend SDKs, and BN for amounts. ```bash npm install @solana/web3.js bn.js @jup-ag/lend @jup-ag/lend-read ``` -------------------------------- ### Next.js Example Source: https://github.com/jup-ag/docs/blob/main/guides/how-to-embed-a-swap-widget.mdx A Next.js page demonstrating how to initialize the Jupiter Plugin using the Script component and onReady. ```tsx "use client"; import { useEffect } from "react"; import Script from "next/script"; export default function SwapPage() { return ( <>