frd-go

command module
v0.3.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 11, 2022 License: MIT Imports: 1 Imported by: 0

README

frd-go

  1. Introduction
  2. How do the clients work ?
    1. HTTP Client
    2. SSE Client
  3. Getting Started !
    1. Installation
    2. Quickstart
  4. Contributing
  5. 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:

  • /relay/v1/data/bidtraces/proposer_payload_delivered
  • /relay/v1/data/bidtraces/builder_blocks_received
  • /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 🤖

Documentation

The Go Gopher

There is no documentation for this package.

Directories

Path Synopsis
internal

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL