This is the initial stage in sending lamports, will try to send a bundle later on
// USE npx ts-node script.ts to run this .tsrequire("dotenv").config();// import { searcherClient } from "jito-ts/dist/sdk/block-engine/searcher";const { searcherClient } = require("jito-ts/dist/sdk/block-engine/searcher");import * as Web3 from "@solana/web3.js";import { Connection, Keypair } from "@solana/web3.js";import * as Fs from "fs";import { onBundleResult, sendBundles } from "./utils/utilities";import bs58 from "bs58";export type JitoRegion = "mainnet" | "amsterdam" | "frankfurt" | "ny" | "tokyo";export const JitoEndpoints = { mainnet: "https://mainnet.block-engine.jito.wtf/api/v1/transactions", amsterdam:"https://amsterdam.mainnet.block-engine.jito.wtf/api/v1/transactions", frankfurt:"https://frankfurt.mainnet.block-engine.jito.wtf/api/v1/transactions", ny: "https://ny.mainnet.block-engine.jito.wtf/api/v1/transactions", tokyo: "https://tokyo.mainnet.block-engine.jito.wtf/api/v1/transactions",};export function getJitoEndpoint(region: JitoRegion) { return JitoEndpoints[region];}export async function sendTxUsingJito({ serializedTx, region = "ny",}: { serializedTx: Uint8Array | Buffer | number[]; region: JitoRegion;}) { let rpcEndpoint = getJitoEndpoint(region); let encodedTx = bs58.encode(serializedTx); let payload = { jsonrpc: "2.0", id: 1, method: "sendTransaction", params: [encodedTx], }; let res = await fetch(`${rpcEndpoint}?bundleOnly=true`, { method: "POST", body: JSON.stringify(payload), headers: { "Content-Type": "application/json" }, }); let json = await res.json(); if (json.error) { throw new Error(json.error.message); } return json;}async function main() { const connection = new Connection( Web3.clusterApiUrl("mainnet-beta"),"confirmed" ); const decodedKey = new Uint8Array( JSON.parse( Fs.readFileSync("/home/muhammad/wallet/keypair1.json").toString() ) as number[] ); const keypair = Keypair.fromSecretKey(decodedKey); console.log(keypair.publicKey.toBase58()); const to = Keypair.generate(); const transferTx = new Web3.Transaction(); const { lastValidBlockHeight, blockhash } = await connection.getLatestBlockhash(); transferTx.add( Web3.SystemProgram.transfer({ fromPubkey: keypair.publicKey, toPubkey: to.publicKey, lamports: 0.001 * Web3.LAMPORTS_PER_SOL, }) ); transferTx.feePayer = keypair.publicKey; transferTx.sign(keypair); transferTx.recentBlockhash = blockhash; let txSerialize = transferTx.serialize(); // Send Transaction using Jito try { const response = await sendTxUsingJito({ serializedTx: txSerialize, region: "ny", // Specify the desired region }); console.log("Transaction sent successfully:", response); } catch (error) { console.error("Error sending transaction:", error); }}main();
By running this script npx ts-node script.ts
results in the error below.
Error: Package subpath './dist/lib/client' is not defined by "exports" in /home/muhammad/Desktop/PhantomXBackPackConnect/node_modules/rpc-websockets/package.json