frd-go
frd-go copied to clipboard
Clients for Flashbots Relay Data, written in go.
frd-go
- Introduction
-
How do the clients work ?
- HTTP Client
- SSE Client
-
Getting Started !
- Installation
- Quickstart
- Contributing
- Author
Introduction
frd-go is a package which lets you use several clients to interact with Flashbots Relays, specifically with the Flashbots Data Transparency API:
- An HTTP client for standard requests to the relays.
- A client for SSE (server-sent events) events sent by the relays.
How do the clients work ?
HTTP Client
Using the http package from the goland standard library, it makes requests to the relay you've provided. List of supported endpoints:
- [x]
/relay/v1/data/bidtraces/proposer_payload_delivered
- [x]
/relay/v1/data/bidtraces/builder_blocks_received
- [x]
/relay/v1/data/validator_registration?pubkey=_pubkey_
SSE Client
Using the sse package made by r3labs, it connects to the
provided relayer and subscribe to incoming events: BidTrace
.
These bids are forwarded (along with an optional error that may have happened during parsing) in a channel you can use in your own application.
For now, it only supports connection to a single relay.
Getting started !
Installation
go get github.com/0xpanoramix/frd-go
Quickstart
Below is an example of how you can create a client and make requests to the relay:
package main
import (
"github.com/0xpanoramix/frd-go/constants"
"github.com/0xpanoramix/frd-go/data"
"log"
"time"
)
func main() {
clt := data.NewTransparencyClient(constants.FlashbotsRelayMainnet, time.Second)
traces, err := clt.GetProposerPayloadsDelivered(nil)
if err != nil {
log.Fatal(err)
}
log.Println(traces)
}
Below is an example of how you can create a sse-client:
package main
import (
"context"
"fmt"
"github.com/0xpanoramix/frd-go/sse"
"github.com/0xpanoramix/frd-go/topics"
"log"
)
func main() {
opts := []sse.Option{
sse.WithRelay("http://127.0.0.1:8080"),
sse.WithTopics(topics.BuilderBidValid),
sse.WithContext(context.Background()),
}
clt, err := sse.New(opts...)
if err != nil {
log.Fatal(err)
}
res, err := clt.Subscribe("messages")
data := <-res
// This will print a Flashbots BidTrace.
fmt.Println(data.Message.EventData)
clt.Unsubscribe()
}
Contributing
Make sure you have Go installed
go version
Then to build the project:
go build
And to run the tests:
go test ./... -v -race
Author
Made with ❤️ by 🤖 Luca Georges François 🤖