i'm making some experiments with jito, i'm searching on jito discord i see that people are having trouble landing bundles. The rpc response is OK, but the bundle shows as invalid. Tried with 0.1 sol but not sure if i'm missing anything?
const jito_tip_1 = new PublicKey("HFqU5x63VTqvQss8hp11i4wVV8bD44PvwucfZ2bU7gRe");
const tipAmount = 1020000;
async function sendBundle(transaction:Transaction[]): Promise<string> {
let serializedTransactions = [];
for (const tx of transaction) {
serializedTransactions.push(bs58.encode(tx.serialize()))
}
const requestBody = {
jsonrpc: "2.0",
id: 1,
method: "sendBundle",
params: [serializedTransactions],
};
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');
}
console.log('data.resultado sendbundle :', data)
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),
});
//console.log('Checking bundle status with response body:', JSON.stringify(response,
null, 2));
//console.log('resposta check bundle', response )
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');
}
console.log('data.resultado checkbundle :', data)
return data.result;
}
async function getInflightBundleStatuses(bundleId: string): Promise<any> {
const requestBody = {
jsonrpc: "2.0",
id: 1,
method: "getInflightBundleStatuses",
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');
}
console.log('data.resultado getInflightBundleStatuses :', data.result.value)
return data.result;
}
(async () => {
try {
const transaction = new Transaction().add(
SystemProgram.transfer({
fromPubkey: from.publicKey,
toPubkey: to,
lamports: LAMPORTS_PER_SOL/100000,
})
);
transaction.recentBlockhash = (await
connection.getLatestBlockhash('confirmed')).blockhash;
transaction.feePayer = from.publicKey;
transaction.sign(from);
const transaction_jito = new Transaction().add(
SystemProgram.transfer({
fromPubkey: from.publicKey,
toPubkey: to,
lamports: LAMPORTS_PER_SOL/100000,
}),
SystemProgram.transfer({
fromPubkey: from.publicKey,
toPubkey: jito_tip_1,
lamports: tipAmount,
})
);
transaction_jito.recentBlockhash = (await
connection.getLatestBlockhash('confirmed')).blockhash;
transaction_jito.feePayer = from.publicKey;
transaction_jito.sign(from);
const bundleId = await sendBundle([transaction, transaction_jito]);
const InflightBundleStatuses = await getInflightBundleStatuses(bundleId);
const bundleStatus = await checkBundleStatus(bundleId);
} catch(e) {
console.error(`Oops, something went wrong: ${e}`)
}
})();