Quantcast
Channel: Recent Questions - Solana Stack Exchange
Viewing all articles
Browse latest Browse all 7906

Need help in sending bundle using jito

$
0
0

I need new to this just trying to send a transaction using Jito bundle i fetched tip accounts and used one random and also using tip 0.005SOL and sending bundle but i get this response always

{"context": {"slot": 278073302  },"value": []}

value is empty tried checking few times but the value is always empty

Here is how i am sending bundle

import express from 'express';import { Keypair, PublicKey, Connection, SystemProgram, Transaction, ComputeBudgetProgram } from '@solana/web3.js';import bs58 from 'bs58';import dotenv from 'dotenv';import cors from 'cors';import fetch from 'node-fetch';dotenv.config();const router = express.Router();const RPC_URL = process.env.RPC_URL || 'https://api.mainnet-beta.solana.com';const FEE_RECEIVER_ADDRESS = process.env.FEE_RECEIVER_ADDRESS;const SYSTEM_FEE = parseInt(process.env.SYSTEM_FEE || '0');if (!FEE_RECEIVER_ADDRESS || !SYSTEM_FEE) {  console.error('Missing required environment variables for fee receiver.');  process.exit(1);}// Middlewarerouter.use(cors());router.use(express.json());async function getTipAccounts(): Promise<string[]> {  const response = await fetch('https://mainnet.block-engine.jito.wtf/api/v1/bundles', {    method: 'POST',    headers: { 'Content-Type': 'application/json' },    body: JSON.stringify({      jsonrpc: "2.0",      id: 1,      method: "getTipAccounts",      params: []    }),  });  if (!response.ok) {    const errorText = await response.text();    throw new Error(`Failed to fetch tip accounts: ${response.statusText} - ${errorText}`);  }  const data = await response.json();  if (!data || !data.result) {    throw new Error('Failed to fetch tip accounts');  }  console.log('Received tip accounts:', data.result);  return data.result;}async function sendBundle(transaction: Transaction): Promise<string> {  const serializedTransaction = bs58.encode(transaction.serialize());  const requestBody = {    jsonrpc: "2.0",    id: 1,    method: "sendBundle",    params: [[serializedTransaction]],  };  console.log('Sending bundle with request body:', JSON.stringify(requestBody, null, 2));  const response = await fetch('https://mainnet.block-engine.jito.wtf/api/v1/bundles', {    method: 'POST',    headers: { 'Content-Type': 'application/json' },    body: JSON.stringify(requestBody),  });  if (!response.ok) {    const errorText = await response.text();    throw new Error(`Failed to send bundle: ${response.statusText} - ${errorText}`);  }  const data = await response.json();  if (!data || !data.result) {    throw new Error('Failed to send bundle');  }  return data.result;}async function checkBundleStatus(bundleId: string): Promise<any> {  const requestBody = {    jsonrpc: "2.0",    id: 1,    method: "getBundleStatuses",    params: [[bundleId]],  };  console.log('Checking bundle status with request body:', JSON.stringify(requestBody, null, 2));  const response = await fetch('https://mainnet.block-engine.jito.wtf/api/v1/bundles', {    method: 'POST',    headers: { 'Content-Type': 'application/json' },    body: JSON.stringify(requestBody),  });  if (!response.ok) {    const errorText = await response.text();    throw new Error(`Failed to check bundle status: ${response.statusText} - ${errorText}`);  }  const data = await response.json();  if (!data || !data.result) {    throw new Error('Failed to check bundle status');  }  return data.result;}router.post('/', async (req, res) => {  const { private_key, wallet_to, transfer_amount, micro_lamports, units } = req.body;  if (!private_key || !wallet_to || !transfer_amount || !micro_lamports || !units) {    return res.status(400).json({      status: 'failed',      message: 'Missing required fields'    });  }  try {    const connection = new Connection(RPC_URL, 'confirmed');    const senderKeypair = Keypair.fromSecretKey(bs58.decode(private_key));    const receiverPublicKey = new PublicKey(wallet_to);    const feeReceiverPublicKey = new PublicKey(FEE_RECEIVER_ADDRESS);    const lamports = transfer_amount * 1e9;    const tipAccounts = await getTipAccounts();    const randomTipAccount = new PublicKey(tipAccounts[Math.floor(Math.random() * tipAccounts.length)]);    const tipAmount = 5000000; // 5,000,000 lamports (0.005 SOL)    console.log('Using tip account:', randomTipAccount.toBase58());    // Fetch recent blockhash    const { blockhash } = await connection.getRecentBlockhash();    const transaction = new Transaction({      recentBlockhash: blockhash,      feePayer: senderKeypair.publicKey,    }).add(      ComputeBudgetProgram.setComputeUnitPrice({ microLamports: micro_lamports }),      ComputeBudgetProgram.setComputeUnitLimit({ units }),      SystemProgram.transfer({        fromPubkey: senderKeypair.publicKey,        toPubkey: receiverPublicKey,        lamports,      }),      SystemProgram.transfer({        fromPubkey: senderKeypair.publicKey,        toPubkey: feeReceiverPublicKey,        lamports: SYSTEM_FEE,      }),      SystemProgram.transfer({        fromPubkey: senderKeypair.publicKey,        toPubkey: randomTipAccount,        lamports: tipAmount      })    );    transaction.sign(senderKeypair);    const bundleId = await sendBundle(transaction);    const bundleStatus = await checkBundleStatus(bundleId);    console.log('Bundle status:', JSON.stringify(bundleStatus, null, 2));    res.status(200).json({      status: 'success',      amount: transfer_amount,      to: wallet_to,      txid: bundleId    });  } catch (error) {    res.status(500).json({      status: 'failed',      message: error.message    });  }});export default router;

Viewing all articles
Browse latest Browse all 7906

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>