# Examples

{% tabs %}
{% tab title="Javascript" %}

```javascript
// 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());
}
```

{% endtab %}

{% tab title="Typescript" %}

```typescript
// 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());
}
```

{% endtab %}

{% tab title="Python" %}

<pre class="language-python"><code class="lang-python"><strong># Define constants
</strong>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())
</code></pre>

{% endtab %}

{% tab title="Rust" %}

```rust
// 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(())
}
```

{% endtab %}
{% endtabs %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.circular.bot/circular-docs/api/fast/examples.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
