Created
January 5, 2026 01:07
-
-
Save sdeering/febce9a70292edf23bddadad18daaa3a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * Jito Bundle Submission Code | |
| * From: src/services/escrow-program.service.ts | |
| * | |
| * Regions: | |
| * - https://ny.mainnet.block-engine.jito.wtf | |
| * - https://frankfurt.mainnet.block-engine.jito.wtf | |
| * - https://tokyo.mainnet.block-engine.jito.wtf | |
| * - https://slc.mainnet.block-engine.jito.wtf | |
| * - https://amsterdam.mainnet.block-engine.jito.wtf | |
| */ | |
| // ============================================================================= | |
| // AUTH HEADERS | |
| // ============================================================================= | |
| private static getJitoAuthHeaders(): Record<string, string> { | |
| const headers: Record<string, string> = { 'Content-Type': 'application/json' }; | |
| // Optional UUID auth for higher limits (set in deployment secrets) | |
| const uuid = process.env.JITO_AUTH_UUID; | |
| if (uuid) { | |
| headers['x-jito-auth'] = uuid; | |
| } | |
| return headers; | |
| } | |
| // ============================================================================= | |
| // ENDPOINT | |
| // ============================================================================= | |
| private static getJitoBundleEndpointMainnet(baseUrl?: string): string { | |
| const url = baseUrl || 'https://mainnet.block-engine.jito.wtf'; | |
| return `${url}/api/v1/bundles`; | |
| } | |
| // ============================================================================= | |
| // BUNDLE SUBMISSION (core HTTP call) | |
| // ============================================================================= | |
| const response = await fetch(getJitoBundleEndpointMainnet(jitoBaseUrl), { | |
| method: 'POST', | |
| headers: getJitoAuthHeaders(), | |
| body: JSON.stringify({ | |
| jsonrpc: '2.0', | |
| id: 1, | |
| method: 'sendBundle', | |
| params: [serializedTransactions, { encoding: 'base64' }], | |
| }), | |
| }); | |
| // Response format: | |
| // Success: { "jsonrpc": "2.0", "result": "<bundleId>", "id": 1 } | |
| // Error: { "jsonrpc": "2.0", "error": { "code": -32097, "message": "Network congested..." }, "id": 1 } | |
| // ============================================================================= | |
| // EXAMPLE: Minimal bundle with SOL transfer + Jito tip | |
| // ============================================================================= | |
| import { Connection, Keypair, PublicKey, SystemProgram, VersionedTransaction, TransactionMessage, ComputeBudgetProgram, LAMPORTS_PER_SOL } from '@solana/web3.js'; | |
| const JITO_TIP_ACCOUNTS = [ | |
| '96gYZGLnJYVFmbjzopPSU6QiEV5fGqZNyN9nmNhvrZU5', | |
| 'HFqU5x63VTqvQss8hp11i4bVxUNPHQzPqbLQNsb5y4T6', | |
| 'Cw8CFyM9FkoMi7K7Crf6HNQqf4uEMzpKw6QNghXLvLkY', | |
| 'ADaUMid9yfUytqMBgopwjb2DTLSokTSzL1zt6iGPaS49', | |
| ]; | |
| async function createJitoBundle(connection: Connection, payer: Keypair, recipient: PublicKey) { | |
| const { blockhash } = await connection.getLatestBlockhash('confirmed'); | |
| const tipAccount = new PublicKey(JITO_TIP_ACCOUNTS[0]); | |
| const instructions = [ | |
| ComputeBudgetProgram.setComputeUnitLimit({ units: 200_000 }), | |
| ComputeBudgetProgram.setComputeUnitPrice({ microLamports: 1000 }), | |
| // Your transfer | |
| SystemProgram.transfer({ | |
| fromPubkey: payer.publicKey, | |
| toPubkey: recipient, | |
| lamports: 0.01 * LAMPORTS_PER_SOL, | |
| }), | |
| // Jito tip (MUST be last instruction) | |
| SystemProgram.transfer({ | |
| fromPubkey: payer.publicKey, | |
| toPubkey: tipAccount, | |
| lamports: 10000, // 0.00001 SOL minimum tip | |
| }), | |
| ]; | |
| const messageV0 = new TransactionMessage({ | |
| payerKey: payer.publicKey, | |
| recentBlockhash: blockhash, | |
| instructions, | |
| }).compileToV0Message(); | |
| const tx = new VersionedTransaction(messageV0); | |
| tx.sign([payer]); | |
| return Buffer.from(tx.serialize()).toString('base64'); | |
| } | |
| // Submit bundle | |
| async function submitBundle(serializedTxs: string[]) { | |
| const response = await fetch('https://ny.mainnet.block-engine.jito.wtf/api/v1/bundles', { | |
| method: 'POST', | |
| headers: { | |
| 'Content-Type': 'application/json', | |
| // 'x-jito-auth': process.env.JITO_AUTH_UUID // Optional: for higher rate limits | |
| }, | |
| body: JSON.stringify({ | |
| jsonrpc: '2.0', | |
| id: 1, | |
| method: 'sendBundle', | |
| params: [serializedTxs, { encoding: 'base64' }], | |
| }), | |
| }); | |
| return response.json(); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment