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());
}
// 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: TransactionInstruction[],
signer: Keypair,
rpcClient: Connection
): Promise<void> {
// 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());
}
# Define constants
FAST_URL_ENGINES = "https://fast.circular.bot/transactions"
FAST_TIP = PublicKey("FAST3dMFZvESiEipBvLSiXq3QCV51o3xuoHScqRU6cB6")
MIN_TIP_AMOUNT = 1_000_000
API_KEY = "your-api-key"
def send_fast_tx(ixs, signer, rpc_client, front_running_protection=False):
# Create transfer instruction
tip_ix = transfer(
TransferParams(
from_pubkey=signer.public_key,
to_pubkey=FAST_TIP,
lamports=MIN_TIP_AMOUNT,
)
)
ixs.append(tip_ix)
# Get the latest blockhash
blockhash = rpc_client.get_recent_blockhash()["result"]["value"]["blockhash"]
# Create and sign the transaction
tx = Transaction(recent_blockhash=blockhash, fee_payer=signer.public_key)
for ix in ixs:
tx.add(ix)
tx.sign(signer)
# Serialize the transaction to Base64
serialized_tx = base64.b64encode(tx.serialize()).decode("utf-8")
# Send the transaction via the Fast endpoint
headers = {
"Content-Type": "application/json",
"x-api-key": API_KEY,
}
payload = {
"jsonrpc": "2.0",
"id": 1,
"method": "sendTransaction",
"params": [
serialized_tx, # base58 or base64
{
"frontRunningProtection": front_running_protection, # false = SWQOS + Jito, true = only Jito
},
],
}
response = requests.post(FAST_URL_ENGINES, json=payload, headers=headers)
# Print response
print("Transaction sent:", response.json())
// Define constants
const FAST_URL_ENGINES: &str = "https://fast.circular.bot/transactions";
const FAST_TIP: &str = "FAST3dMFZvESiEipBvLSiXq3QCV51o3xuoHScqRU6cB6";
const MIN_TIP_AMOUNT: u64 = 1_000_000;
const API_KEY: &str = "your-api-key";
async fn send_fast_tx(
ixs: Vec<Instruction>,
signer: &Keypair,
rpc_client: &RpcClient,
front_running_protection: bool,
) -> Result<(), Box<dyn std::error::Error>> {
// Create transfer instruction
let fast_tip_pubkey = Pubkey::from_str(FAST_TIP)?;
let tip_instruction = system_instruction::transfer(
&signer.pubkey(),
&fast_tip_pubkey,
MIN_TIP_AMOUNT,
);
let mut instructions = ixs;
instructions.push(tip_instruction);
// Get the latest blockhash
let recent_blockhash = rpc_client.get_latest_blockhash()?;
// Create and sign the transaction
let mut transaction = Transaction::new_with_payer(&instructions, Some(&signer.pubkey()));
transaction.try_sign(&[signer], recent_blockhash)?;
// Serialize transaction to Base64
let serialized_tx = base64::encode(transaction.serialize()?);
// Send transaction using Fast endpoint
let client = Client::new();
let payload = json!({
"jsonrpc": "2.0",
"id": 1,
"method": "sendTransaction",
"params": [
serialized_tx, // base58 or base64
{
"frontRunningProtection": front_running_protection // false = SWQOS + Jito, true = only Jito
}
]
});
let response = client
.post(FAST_URL_ENGINES)
.header("Content-Type", "application/json")
.header("x-api-key", API_KEY)
.json(&payload)
.send()
.await?;
let response_json: serde_json::Value = response.json().await?;
println!("Transaction sent: {:?}", response_json);
Ok(())
}
Last updated