# 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())