Skip to content
This repository was archived by the owner on Oct 20, 2024. It is now read-only.

Golang client for Flashbots Relay, mev-geth and standard Ethereum JSON-RPC API endpoints

License

Notifications You must be signed in to change notification settings

stackup-wallet/flashbotsrpc

This branch is 3 commits behind metachris/flashbotsrpc:master.

Folders and files

NameName
Last commit message
Last commit date
Mar 30, 2022
May 24, 2023
Aug 16, 2021
Mar 30, 2022
May 24, 2023
Jun 27, 2023
Jun 27, 2023
Mar 30, 2022
Mar 30, 2022
Aug 16, 2021
Aug 16, 2021
Aug 16, 2021
Dec 21, 2022
Jun 27, 2023
Aug 16, 2021

Repository files navigation

Flashbots RPC client

Test status

Fork of ethrpc with additional Flashbots RPC methods:

  • FlashbotsCallBundle (eth_callBundle)
  • FlashbotsSendBundle (eth_sendBundle)
  • FlashbotsGetUserStats (flashbots_getUserStats)
  • FlashbotsSendPrivateTransaction (eth_sendPrivateTransaction)
  • FlashbotsCancelPrivateTransaction (eth_cancelPrivateTransaction)
  • FlashbotsSimulateBlock: simulate a full block

Usage

Add library to your project:

go get github.com/metachris/flashbotsrpc

Create a new private key here for testing (you probably want to use an existing one):

privateKey, _ := crypto.GenerateKey()

Simulate transactions with eth_callBundle:

callBundleArgs := flashbotsrpc.FlashbotsCallBundleParam{
    Txs:              []string{"YOUR_RAW_TX"},
    BlockNumber:      fmt.Sprintf("0x%x", 13281018),
    StateBlockNumber: "latest",
}

result, err := rpc.FlashbotsCallBundle(privateKey, callBundleArgs)
if err != nil {
    log.Fatal(err)
}
fmt.Printf("%+v\n", result)

Get Flashbots user stats:

rpc := flashbotsrpc.New("https://relay.flashbots.net")
result, err := rpc.FlashbotsGetUserStats(privateKey, 13281018)
if err != nil {
    log.Fatal(err)
}
fmt.Printf("%+v\n", result)

Send a transaction bundle to Flashbots with eth_sendBundle:

sendBundleArgs := flashbotsrpc.FlashbotsSendBundleRequest{
    Txs:         []string{"YOUR_RAW_TX"},
    BlockNumber: fmt.Sprintf("0x%x", 13281018),
}

result, err := rpc.FlashbotsSendBundle(privateKey, sendBundleArgs)
if err != nil {
    log.Fatal(err)
}
fmt.Printf("%+v\n", result)

Send a transaction bundle to a list of Builder endpoints with eth_sendBundle (full example [/examples/broadcastbundle]):

urls := []string{
	"https://relay.flashbots.net",
    // Refer to https://www.mev.to/builders for builder endpoints 
}
rpc := flashbotsrpc.NewBuilderBroadcastRPC(urls)

sendBundleArgs := flashbotsrpc.FlashbotsSendBundleRequest{
    Txs:         []string{"YOUR_RAW_TX"},
    BlockNumber: fmt.Sprintf("0x%x", 13281018),
}

results := rpc.BroadcastBundle(privateKey, sendBundleArgs)
for _, result := range results {
    if result.Err != nil {
        log.Fatal(result.Err)
    }
    fmt.Printf("%+v\n", result.BundleResponse)
}

More examples

You can find example code in the /examples/ directory.

About

Golang client for Flashbots Relay, mev-geth and standard Ethereum JSON-RPC API endpoints

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Go 99.5%
  • Makefile 0.5%