Package flashbots implements RPC API bindings for the Flashbots relay and
mev-geth for use with the w3
package.
go get github.com/lmittmann/flashbots
Connect to the Flashbots relay. The AuthTransport
adds the X-Flashbots-Signature header to every request from the client.
// Private key for request authentication
var privKey *ecdsa.PrivateKey
// Connect to Flashbots relay
rpcClient, err := rpc.DialHTTPWithClient(
"https://relay.flashbots.net",
&http.Client{
Transport: flashbots.AuthTransport(privKey),
},
)
// Create w3 client form rpc client
client := w3.NewClient(rpcClient)
defer client.Close()Send a bundle to the Flashbots relay.
var bundle types.Transactions // list of signed transactions
var bundleHash common.Hash
err := client.Call(
flashbots.SendBundle(&flashbots.SendBundleRequest{
Transactions: bundle,
BlockNumber: big.NewInt(999_999_999),
}).Returns(&bundleHash),
)⚠ The Flashbots relay does not support batch requests. Thus, sending more than one call in
Client.Callwill result in a server error.
List of supported RPC methods.
| Method | Go Code |
|---|---|
eth_sendBundle |
flashbots.SendBundle(r *flashbots.SendBundleRequest).Returns(bundleHash *common.Hash) |
eth_callBundle |
flashbots.CallBundle(r *flashbots.CallBundleRequest).Returns(resp *flashbots.CallBundleResponse) |
eth_sendPrivateTransaction |
flashbots.SendPrivateTransaction(r *flashbots.SendPrivateTransactionRequest).Returns(txHash *common.Hash) |
eth_cancelPrivateTransaction |
flashbots.CancelPrivateTransaction(txHash common.Hash).Returns(success *bool) |
flashbots_getUserStats |
flashbots.UserStats(blockNumber *big.Int).Returns(resp *flashbots.UserStatsResponse) |
flashbots_getBundleStats |
flashbots.BundleStats(bundleHash common.Hash, blockNumber *big.Int).Returns(resp *flashbots.BundleStatsResponse) |