Documentation ¶
Overview ¶
Package flashbots implements RPC API bindings for the Flashbots relay and mev-geth for use with the w3 package (github.com/lmittmann/w3).
Example ¶
package main import ( "crypto/ecdsa" "fmt" "math/big" "net/http" "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/rpc" "github.com/lmittmann/flashbots" "github.com/lmittmann/w3" ) func main() { // Private key for request authentication var privKey *ecdsa.PrivateKey // Connect to relay rpcClient, err := rpc.DialHTTPWithClient( "https://relay.flashbots.net", &http.Client{ Transport: flashbots.AuthTransport(privKey), }, ) if err != nil { fmt.Printf("Failed to connect to Flashbots relay: %v\n", err) return } client := w3.NewClient(rpcClient) defer client.Close() // Send bundle var ( bundle types.Transactions // list of signed transactions bundleHash common.Hash ) err = client.Call( flashbots.SendBundle(&flashbots.SendBundleRequest{ Transactions: bundle, BlockNumber: big.NewInt(999_999_999), }).Returns(&bundleHash), ) if err != nil { fmt.Printf("Failed to send bundle to Flashbots relay: %v\n", err) return } fmt.Printf("Sent bundle successfully: %s\n", bundleHash) }
Output:
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AuthTransport ¶
func AuthTransport(privKey *ecdsa.PrivateKey) http.RoundTripper
AuthTransport returns a http.RoundTripper that adds the 'X-Flashbots-Signature' header to every request.
Types ¶
type BundleStatsFactory ¶
type BundleStatsFactory struct {
// contains filtered or unexported fields
}
func BundleStats ¶
func BundleStats(bundleHash common.Hash, blockNumber *big.Int) *BundleStatsFactory
BundleStats requests the bundles Flashbots relay stats. The given block number must be within 20 blocks of the current chain tip.
func (*BundleStatsFactory) CreateRequest ¶
func (f *BundleStatsFactory) CreateRequest() (rpc.BatchElem, error)
CreateRequest implements the w3/core.RequestCreator interface.
func (*BundleStatsFactory) HandleResponse ¶
func (f *BundleStatsFactory) HandleResponse(elem rpc.BatchElem) error
HandleResponse implements the w3/core.ResponseHandler interface.
func (*BundleStatsFactory) Returns ¶
func (f *BundleStatsFactory) Returns(bundleStats *BundleStatsResponse) *BundleStatsFactory
type BundleStatsResponse ¶
type CallBundleFactory ¶ added in v0.2.0
type CallBundleFactory struct {
// contains filtered or unexported fields
}
func CallBundle ¶ added in v0.2.0
func CallBundle(r *CallBundleRequest) *CallBundleFactory
CallBundle simulates a bundle.
func (*CallBundleFactory) CreateRequest ¶ added in v0.2.0
func (f *CallBundleFactory) CreateRequest() (rpc.BatchElem, error)
CreateRequest implements the w3/core.RequestCreator interface.
func (*CallBundleFactory) HandleResponse ¶ added in v0.2.0
func (f *CallBundleFactory) HandleResponse(elem rpc.BatchElem) error
HandleResponse implements the w3/core.ResponseHandler interface.
func (*CallBundleFactory) Returns ¶ added in v0.2.0
func (f *CallBundleFactory) Returns(resp *CallBundleResponse) *CallBundleFactory
type CallBundleRequest ¶ added in v0.2.0
type CallBundleRequest struct { Transactions types.Transactions // List of signed transactions to simulate in a bundle. RawTransactions [][]byte // List of signed raw transactions to simulate in a bundle. BlockNumber *big.Int // Block number for which the bundle is valid. StateBlockNumber *big.Int // Block number of state to use for simulation, "latest" if nil. Timestamp *big.Int // Timestamp of block used for simulation (Optional). }
func (CallBundleRequest) MarshalJSON ¶ added in v0.2.0
func (c CallBundleRequest) MarshalJSON() ([]byte, error)
MarshalJSON implements the json.Marshaler interface.
type CallBundleResponse ¶ added in v0.2.0
type CallBundleResponse struct { BundleGasPrice *big.Int BundleHash common.Hash CoinbaseDiff *big.Int EthSentToCoinbase *big.Int GasFees *big.Int StateBlockNumber *big.Int TotalGasUsed uint64 Results []CallBundleResult }
func (*CallBundleResponse) UnmarshalJSON ¶ added in v0.2.0
func (c *CallBundleResponse) UnmarshalJSON(input []byte) error
UnmarshalJSON implements the json.Unmarshaler interface.
type CallBundleResult ¶ added in v0.2.0
type SendBundleFactory ¶
type SendBundleFactory struct {
// contains filtered or unexported fields
}
func SendBundle ¶
func SendBundle(r *SendBundleRequest) *SendBundleFactory
SendBundle sends the bundle to the client's endpoint.
func (*SendBundleFactory) CreateRequest ¶
func (f *SendBundleFactory) CreateRequest() (rpc.BatchElem, error)
CreateRequest implements the w3/core.RequestCreator interface.
func (*SendBundleFactory) HandleResponse ¶
func (f *SendBundleFactory) HandleResponse(elem rpc.BatchElem) error
HandleResponse implements the w3/core.ResponseHandler interface.
func (*SendBundleFactory) Returns ¶
func (f *SendBundleFactory) Returns(hash *common.Hash) *SendBundleFactory
type SendBundleRequest ¶ added in v0.2.0
type SendBundleRequest struct { Transactions types.Transactions // List of signed transactions to execute in a bundle. RawTransactions [][]byte // List of signed raw transactions to execute in a bundle. BlockNumber *big.Int // Block number for which the bundle is valid MinTimestamp *big.Int // Minimum Unix Timestamp for which the bundle is valid MaxTimestamp *big.Int // Maximum Unix Timestamp for which the bundle is valid RevertingTxHashes []common.Hash // List of tx hashes in bundle that are allowed to revert. }
func (SendBundleRequest) MarshalJSON ¶ added in v0.2.0
func (s SendBundleRequest) MarshalJSON() ([]byte, error)
MarshalJSON implements the json.Marshaler interface.
type UserStatsFactory ¶
type UserStatsFactory struct {
// contains filtered or unexported fields
}
func UserStats ¶
func UserStats(blockNumber *big.Int) *UserStatsFactory
UserStats requests the users Flashbots relay stats. The given block number must be within 20 blocks of the current chain tip.
func (*UserStatsFactory) CreateRequest ¶
func (f *UserStatsFactory) CreateRequest() (rpc.BatchElem, error)
CreateRequest implements the w3/core.RequestCreator interface.
func (*UserStatsFactory) HandleResponse ¶
func (f *UserStatsFactory) HandleResponse(elem rpc.BatchElem) error
HandleResponse implements the w3/core.ResponseHandler interface.
func (*UserStatsFactory) Returns ¶
func (f *UserStatsFactory) Returns(userStats *UserStatsResponse) *UserStatsFactory
type UserStatsResponse ¶
type UserStatsResponse struct { IsHighPriority bool // True if the searcher has an high enough reputation to be in the high priority queue. AllTimeMinerPayments *big.Int // Total amount paid to miners over all time. AllTimeGasSimulated *big.Int // Total amount of gas simulated across all bundles submitted to the relay. Last7dMinerPayments *big.Int // Total amount paid to miners over the last 7 days. Last7dGasSimulated *big.Int // Total amount of gas simulated across all bundles submitted to the relay in the last 7 days. Last1dMinerPayments *big.Int // Total amount paid to miners over the last day. Last1dGasSimulated *big.Int // Total amount of gas simulated across all bundles submitted to the relay in the last day. }
func (*UserStatsResponse) UnmarshalJSON ¶
func (u *UserStatsResponse) UnmarshalJSON(input []byte) error
UnmarshalJSON implements the json.Unmarshaler interface.