# Public Transactions

The `blxr_tx` endpoint allows users to send a single transaction faster than the p2p network using the BDN. The endpoint returns a transaction hash.

This service is available via both the **Cloud API** and **Gateway API**.

The bloXroute best practice is for users to send transactions to both the Gateway-API and to their blockchain node. You should send transactions in parallel to the Gateway and to your blockchain node as a backup.

For latency-sensitive orderflow, WebSocket is recommended and can provide latency improvement over HTTP/HTTPS. If you prefer to short-lived connections, use HTTP over HTTPS for improved latency.

## Submission Endpoint

* Method: `blxr_tx`
* Cloud API Endpoint: `api.blxrbdn.com`
* Gateway API Endpoint: `127.0.0.1:28333/ws` (assumes WebSocket port 28333)
* Request type: *`HTTPS,WSS`*

### Parameters

<table><thead><tr><th width="279.3333333333333">Parameter</th><th width="217">Description</th><th>Instructions &#x26; Notes</th></tr></thead><tbody><tr><td><strong><code>transaction</code></strong></td><td>Raw transactions bytes without <strong><code>0x</code></strong> prefix.</td><td><strong>Mandatory</strong><em>.</em> Learn more about constructing the transaction <a href="/pages/mjPF3cLN6i2pitLcepLd">here</a>.</td></tr><tr><td><strong><code>blockchain_network</code></strong></td><td>Blockchain network name.</td><td><p>Mandatory. Use <strong><code>BSC-Mainnet</code></strong> for BSC Mainnet</p><p>*Use with Cloud-API when working with BSC.</p></td></tr><tr><td><strong><code>node_validation</code></strong></td><td>Transaction is sent to the blockchain node for validation, and the Gateway returns any error message received in response.</td><td><p>Available only with Gateway API</p><p>Optional</p><p>Default: False</p></td></tr></tbody></table>

### Example

#### Cloud-API

{% tabs %}
{% tab title="wscat WS" %}

```bash
wscat -c wss://api.blxrbdn.com/ws --header "Authorization: <YOUR-AUTHORIZATION-HEADER>"
> {"jsonrpc": "2.0", "id": 1, "method": "blxr_tx", "params": 
  {"transaction": "f86b0184...e0b58219",
   "blockchain_network": "BSC-Mainnet"}}
< ....
```

{% endtab %}

{% tab title="Node.js WS" %}

```javascript
const WebSocket = require('ws');

const ws = new WebSocket(
  "wss://api.blxrbdn.com/ws", 
  {
    headers: { 
      "Authorization" : <YOUR-AUTHORIZATION-HEADER>  
    },
    rejectUnauthorized: false,
  }
);

function proceed() {
    // ETH Example
    ws.send(`{"jsonrpc": "2.0", "id": 1, "method": "blxr_tx", "params": {"transaction": "f86b0184...e0b58219"}}`);
    // BSC Example
    // ws.send(`{"jsonrpc": "2.0", "id": 1, "method": "blxr_tx", "params": {"transaction": "f86b0184...e0b58219", "blockchain_network": "BSC-Mainnet"}}`);
    //
    // or use a variable for the transaction string:
    // rawTx = "f86b0184...e0b58219";
    // ws.send(`{"jsonrpc": "2.0", "id": 1, "method": "blxr_tx", "params": {"transaction": "${rawTx}"}}`);
}


function handle(response) {
    console.log(response.toString()); // or process it generally
}

ws.on('open', proceed);
ws.on('message', handle);

```

{% endtab %}

{% tab title="Python WS" %}

```python
# Python 3.7 or higher required due to the use of asyncio.run()
import asyncio, json, ssl
from websocket import create_connection

async def main():
    try:
        ws = create_connection('wss://api.blxrbdn.com/ws',
                               header=["Authorization:{}".format("YOUR_AUTHORIZATION_HEADER")],
                               sslopt={"cert_reqs": ssl.CERT_NONE})
        # ETH Example
        request = json.dumps({"id": 1, "method": "blxr_tx", "params": {"transaction": "f86b0184...e0b58219"}})
        
        # BSC Example
        request = json.dumps({"id": 1, "method": "blxr_tx", "params": {"transaction": "f86b0184...e0b58219", "blockchain_network": "BSC-Mainnet"}})
        
        ws.send(str(request))
        while True:
            response = json.loads(ws.recv())
            print(response) # or process it generally
    except Exception as e:
        print(f'Connection failed, Reason: {e}')


if __name__ == '__main__':
    asyncio.run(main()
```

{% endtab %}

{% tab title="golang WS" %}

```go
package main

import (
	"crypto/tls"
	"fmt"
	"github.com/gorilla/websocket"
	"net/http"
)

func main() {
	tlsConfig := &tls.Config{
		InsecureSkipVerify: true,
	}
	dialer := websocket.DefaultDialer
	dialer.TLSClientConfig = tlsConfig
	wsSubscriber, _, err := dialer.Dial("wss://api.blxrbdn.com/ws", http.Header{"Authorization": []string{<YOUR-AUTHORIZATION-HEADER>}})

	if err != nil {
		fmt.Println(err)
		return
	}

        // ETH Example
	request := `{"jsonrpc": "2.0", "id": 1, "method": "blxr_tx", "params": {"transaction": "f86b0184...e0b58219"}}`
        // BSC Example
        // request := `{"jsonrpc": "2.0", "id": 1, "method": "blxr_tx", "params": {"transaction": "f86b0184...e0b58219", "blockchain_network": "BSC-Mainnet"}}`
	err = wsSubscriber.WriteMessage(websocket.TextMessage, []byte(request))
	if err != nil {
		fmt.Println(err)
		return
	}

	_, response, err := wsSubscriber.ReadMessage()
	if err != nil {
		fmt.Println(err)
	}
	fmt.Println(string(response)) // or process it generally
}

```

{% endtab %}

{% tab title="HTTPS POST" %}

```bash
# ETH Example
curl https://api.blxrbdn.com \
    -X POST \
    -H "Content-Type: application/json" \
    -H "Authorization: <YOUR-AUTHORIZATION-HEADER>" \
    -d '{"method": "blxr_tx", "id": "1", "params": {"transaction": "f86b0184...e0b58219"}}'

# BSC Example
curl https://api.blxrbdn.com \
  -X POST \
  -H "Content-Type: application/json" \
  -H "Authorization: <YOUR-AUTHORIZATION-HEADER>" \
  -d '{
    "jsonrpc": "2.0",
    "id": 1,
    "method": "blxr_tx",
    "params": {
      "transaction": "f86b0184...e0b58219",
      "blockchain_network": "BSC-Mainnet",
      "backrunme_reward_address": "0xYourRewardAddressHere"
    }
  }'

```

{% endtab %}
{% endtabs %}

#### Gateway-API:

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

```bash
# ETH Example
wscat -c ws://127.0.0.1:28333/ws --header "Authorization: <YOUR-AUTHORIZATION-HEADER>"
> {"jsonrpc": "2.0", "id": 1, "method": "blxr_tx", "params":
   {"transaction": "f86b0184...e0b58219"}}
< ......

```

{% endtab %}

{% tab title="Node.js" %}

```javascript
const WebSocket = require('ws');

const ws = new WebSocket(
  "ws://127.0.0.1:28333/ws", 
  {
    headers: { 
      "Authorization" : <YOUR-AUTHORIZATION-HEADER>
    },
    rejectUnauthorized: false,
  }
);

function proceed() {
    // ETH Example
    ws.send(`{"jsonrpc": "2.0", "id": 1, "method": "blxr_tx", "params": {"transaction": "f86b0184...e0b58219"}}`);
    // BSC Example
    // ws.send(`{"jsonrpc": "2.0", "id": 1, "method": "blxr_tx", "params": {"transaction": "f86b0184...e0b58219", "blockchain_network": "BSC-Mainnet"}}`);
    //
    // or use a variable for the transaction string:
    // rawTx = "f86b0184...e0b58219";
    // ws.send(`{"jsonrpc": "2.0", "id": 1, "method": "blxr_tx", "params": {"transaction": "${rawTx}"}}`);
}


function handle(response) {
    console.log(response.toString()); // or process it generally
}

ws.on('open', proceed);
ws.on('message', handle);
```

{% endtab %}

{% tab title="Python" %}

<pre class="language-python"><code class="lang-python"># Python 3.7 or higher required due to the use of asyncio.run()
<strong>import asyncio, json, ssl
</strong>from websocket import create_connection

async def main():
    try:
        ws = create_connection('ws://127.0.0.1:28333/ws',
                               header=["Authorization:{}".format("YOUR_AUTHORIZATION_HEADER")],
                               sslopt={"cert_reqs": ssl.CERT_NONE})
        # ETH Example
        request = json.dumps({"id": 1, "method": "blxr_tx", "params": {"transaction": "f86b0184...e0b58219"}})
        
        # BSC Example
        request = json.dumps({"id": 1, "method": "blxr_tx", "params": {"transaction": "f86b0184...e0b58219", "blockchain_network": "BSC-Mainnet"}})
        
        ws.send(str(request))
        while True:
            response = json.loads(ws.recv())
            print(response) # or process it generally
    except Exception as e:
        print(f'Connection failed, Reason: {e}')
</code></pre>

{% endtab %}

{% tab title="golang" %}

```go
package main

import (
	"crypto/tls"
	"fmt"
	"github.com/gorilla/websocket"
	"net/http"
)

func main() {
	tlsConfig := &tls.Config{
		InsecureSkipVerify: true,
	}
	dialer := websocket.DefaultDialer
	dialer.TLSClientConfig = tlsConfig
	wsSubscriber, _, err := dialer.Dial("ws://127.0.0.1:28333/ws", http.Header{"Authorization": []string{<YOUR-AUTHORIZATION-HEADER>}})

	if err != nil {
		fmt.Println(err)
		return
	}

  // ETH Example
	request := `{"jsonrpc": "2.0", "id": 1, "method": "blxr_tx", "params": {"transaction": "f86b0184...e0b58219"}}`
  // BSC Example
  // request := `{"jsonrpc": "2.0", "id": 1, "method": "blxr_tx", "params": {"transaction": "f86b0184...e0b58219", "blockchain_network": "BSC-Mainnet"}}`
	err = wsSubscriber.WriteMessage(websocket.TextMessage, []byte(request))
	if err != nil {
		fmt.Println(err)
		return
	}

	_, response, err := wsSubscriber.ReadMessage()
	if err != nil {
		fmt.Println(err)
	}
	fmt.Println(string(response)) // or process it generally
}
```

{% endtab %}

{% tab title="gRPC" %}

<pre class="language-go"><code class="lang-go"><strong> main
</strong>
<strong>import (
</strong>	"context"
	"fmt"
	"time"
	
	pb "github.com/bloXroute-Labs/bxgateway-private-go/bxgateway/v2/protobuf"
	"google.golang.org/grpc"
	"google.golang.org/grpc/credentials"
)

<strong>func main() {
</strong>	// gRPC server default values
	gatewayHostIP := "127.0.0.1"
	gatewayGRPCPort := 5001
	
	// this will use localhost CA to verify the certificate
	creds := credentials.NewClientTLSFromCert(nil, "")

	// Open gRPC connection to Gateway.
	conn, _ := grpc.Dial(
		fmt.Sprintf("%v:%v", gatewayHostIP, gatewayGRPCPort), 
		grpc.WithTransportCredentials(creds),
	)

<strong>	// Use the Gateway client connection interface. 
</strong>	client := pb.NewGatewayClient(conn)
	
	// create context and defer cancel of context
	callContext, cancel := context.WithTimeout(context.Background(), 24*time.Hour)
	defer cancel()
	
	// send tx
	reply, err := client.BlxrTx(callContext, &#x26;pb.BlxrTxRequest{AuthHeader: "&#x3C;YOUR-AUTHORIZATION-HEADER>", Transaction: "f86b0184...e0b58219"})
	if err != nil {
		print(err)
		return
	}
	
	txHash := reply.TxHash
	print(txHash) // or process it generally
}
</code></pre>

{% endtab %}
{% endtabs %}

#### Response

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

```bash
{
    "jsonrpc": "2.0", 
    "id": "1", 
    "result": {
        "tx_hash": "ffd59870844e5...bfa54a69"
    }
}    
```

{% 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.bloxroute.com/bsc/submit-transactions/public-transactions.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.
