# Gateway and OFR Setup

### Get authorization header

In order to receive shreds through the Optimized Feed Relay (OFR) and connect to bloXroute's OFR Relay, you must use a OFR Gateway. To do this, you need to [register-an-account](https://docs.bloxroute.com/getting-started/register-an-account "mention") and get [Broken link](https://docs.bloxroute.com/solana/optimized-feed-relay/broken-reference "mention").

### **Installation**

```bash
docker pull bloxroute/solana-gateway:latest
```

### Startup

{% hint style="warning" %}
Ensure that your gateway can receive inbound traffic on **UDP Port 18888** as described here: [requirements](https://docs.bloxroute.com/solana/optimized-feed-relay/requirements "mention")
{% endhint %}

```bash
docker run --name bxgateway-solana -d \
  --network=host bloxroute/solana-gateway:latest \
  -auth-header=[AuthHeader] \
  -network-interface=eno1 \
  -tvu-port=8001 \
  -ofr-host=ny.solana-v2.blxrbdn.com \
  -port=18888
```

{% hint style="info" %}
The values used for `network-interface` argument and `tvu-port` argument could vary based on the hosting machine. Please follow the [gateway arguments](https://docs.bloxroute.com/solana/startup-arguments#required-gateway-arguments) section to determine the proper values.
{% endhint %}

## Verify the Gateway and OFR is running correctly

To verify that your Gateway is running correctly and shreds are being received through OFR, monitor the stdout or logfile logs. Every minute it should report the amount of shreds it sends and receives.

The output should be similar to the following:

```
time="2025-01-06T10:56:00.000160" level="info" msg="stats: total shreds by source: [(10.142.0.47:0, 449771), (185.26.9.3:8381, 434018)] unseen shreds by source: [(185.26.9.3:8381, 385382), (10.142.0.47:0, 70913)]. Seen 84.46% of shreds first from BDN"
```

**Note:** The Gateway does not need to be restarted if your Solana node restarts.

## Sample program to receive shreds through OFR <a href="#sample-program-to-receive-shreds-from-gateway" id="sample-program-to-receive-shreds-from-gateway"></a>

{% hint style="info" %}
Traders with Enterprise Elite plan or above can start a ofr gateway to run without a local Solana node, with gateway startup arguments like `-no-validator -broadcast-addresses 127.0.0.1:1820`. Custom programs can then be deployed to listen at the addresses to receive and consume shreds from the OFR Relay.
{% endhint %}

For example, running a custom UDP server with code below to receive shreds from gateway:

```go
package main

import (
	"fmt"
	"net"
)

func main() {
	conn, err := net.ListenUDP("udp", &net.UDPAddr{
		IP:   net.ParseIP("0.0.0.0"),
		Port: 1820,
	})
	if err != nil {
		fmt.Printf("Error starting UDP server: %v\n", err)
		return
	}
	defer conn.Close()

	fmt.Printf("UDP server listening\n")

	buffer := make([]byte, 1228) // 1228 - udp shred size

	// Continuously read data
	for {
		n, addr, err := conn.ReadFromUDP(buffer)
		if err != nil {
			fmt.Printf("Error reading from UDP connection: %v\n", err)
			continue
		}
		
		// or process it generally
		fmt.Printf("Received message from %s: %s\n", addr.String(), string(buffer[:n]))
	}
}
```

## Firedancer Compatibility

OFR is compatible with [Firedancer](https://docs.firedancer.io/guide/getting-started.html). You just need to mount the location of hugepages used by Firedancer to the docker container and enable Firedancer mode:

```bash
docker run --name bxgateway-solana -d \
  --volume /mnt/.fd:/mnt/.fd \ # mount hugepages directory
  --network=host bloxroute/solana-gateway:latest \
  -auth-header=[AuthHeader] \
  -network-interface=eno1 \
  -tvu-port=8001 \
  -ofr-host=ny.solana-v2.blxrbdn.com \
  -port=18888 \
  -firedancer  # enable Firedancer mode
  
# This configuration reads shreds directly from Firedancer’s
# `fd1_shred_store.wksp` memory-mapped workspace.
```
