Examples

// Define constants
const FAST_URL_ENGINES = "https://fast.circular.bot/transactions";
const FAST_TIP = new PublicKey("FAST3dMFZvESiEipBvLSiXq3QCV51o3xuoHScqRU6cB6");
const MIN_TIP_AMOUNT = 1_000_000;

async function sendFastTx(
  ixs,
  signer,
  rpcClient
) {
  // Create transfer instruction
  const tipIx = SystemProgram.transfer({
    fromPubkey: signer.publicKey,
    toPubkey: FAST_TIP,
    lamports: MIN_TIP_AMOUNT,
  });
  ixs.push(tipIx);

  // Get the latest blockhash
  const { blockhash } = await rpcClient.getLatestBlockhash();

  // Create transaction and sign it
  const tx = new Transaction().add(...ixs);
  tx.recentBlockhash = blockhash;
  tx.feePayer = signer.publicKey;
  tx.sign(signer);

  // Serialize the transaction to Base64
  const serializedTx = tx.serialize().toString("base64");
  
  // Send the transaction
  const response = await fetch(FAST_URL_ENGINES, {
    method: "POST",
    headers: {
      "Content-Type": "application/json",
      "x-api-key": "your-api-key"
    },
    body: JSON.stringify({
      jsonrpc: "2.0",
      id: 1,
      method: "sendTransaction",
      params: [
        serializedTx, // base58 or base64
        {
          frontRunningProtection: false, // false = SWQOS + Jito, true = only Jito 
        },
      ],
    }),
  });

  console.log("Transaction sent :", await response.json());
}

Last updated