Documentation ¶
Overview ¶
Package flashbots implements RPC API bindings for the Flashbots relay and mev-geth for use with the w3 package.
Example ¶
package main import ( "crypto/ecdsa" "fmt" "math/big" "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/core/types" "github.com/lmittmann/flashbots" ) func main() { // Private key for request signing var prv *ecdsa.PrivateKey // Connect to Flashbots relay client := flashbots.MustDial("https://relay.flashbots.net", prv) defer client.Close() // Send bundle bundle := []*types.Transaction{ /* signed transactions... */ } var bundleHash common.Hash if err := client.Call( flashbots.SendBundle(&flashbots.SendBundleRequest{ Transactions: bundle, BlockNumber: big.NewInt(999_999_999), }).Returns(&bundleHash), ); 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 ¶
- func AuthTransport(privKey *ecdsa.PrivateKey) http.RoundTripper
- func BundleStats(bundleHash common.Hash, blockNumber *big.Int) w3types.RPCCallerFactory[*BundleStatsResponse]deprecated
- func BundleStatsV2(bundleHash common.Hash, blockNumber *big.Int) w3types.RPCCallerFactory[*BundleStatsV2Response]
- func CallBundle(r *CallBundleRequest) w3types.RPCCallerFactory[*CallBundleResponse]
- func CancelPrivateTx(hash common.Hash) w3types.RPCCallerFactory[bool]
- func Dial(rawurl string, prv *ecdsa.PrivateKey) (*w3.Client, error)
- func MustDial(rawurl string, prv *ecdsa.PrivateKey) *w3.Client
- func SendBundle(r *SendBundleRequest) w3types.RPCCallerFactory[common.Hash]
- func SendPrivateTx(r *SendPrivateTxRequest) w3types.RPCCallerFactory[common.Hash]
- func UserStats(blockNumber *big.Int) w3types.RPCCallerFactory[*UserStatsResponse]deprecated
- func UserStatsV2(blockNumber *big.Int) w3types.RPCCallerFactory[*UserStatsV2Response]
- type BundleStatsResponsedeprecated
- type BundleStatsV2Response
- type CallBundleRequest
- type CallBundleResponse
- type CallBundleResult
- type SendBundleRequest
- type SendPrivateTxRequest
- type UserStatsResponsedeprecated
- type UserStatsV2Response
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.
func BundleStats
deprecated
func BundleStats(bundleHash common.Hash, blockNumber *big.Int) w3types.RPCCallerFactory[*BundleStatsResponse]
BundleStats requests the bundles Flashbots relay stats. The given block number must be within 20 blocks of the current chain tip.
Deprecated: Use BundleStatsV2 instead.
func BundleStatsV2 ¶ added in v0.6.0
func BundleStatsV2(bundleHash common.Hash, blockNumber *big.Int) w3types.RPCCallerFactory[*BundleStatsV2Response]
BundleStatsV2 requests the bundles Flashbots relay stats. The given block number must be within 20 blocks of the current chain tip.
func CallBundle ¶ added in v0.2.0
func CallBundle(r *CallBundleRequest) w3types.RPCCallerFactory[*CallBundleResponse]
CallBundle simulates a bundle.
func CancelPrivateTx ¶ added in v0.5.0
func CancelPrivateTx(hash common.Hash) w3types.RPCCallerFactory[bool]
CancelPrivateTx stops the private transactions with the given hash from being submitted for future blocks by the Flashbots relay.
func Dial ¶ added in v0.5.0
Dial returns a new w3.Client connected to the URL rawurl that adds the 'X-Flashbots-Signature' to every request. An error is returned if the connection establishment fails.
Use w3.Dial to connect to an RPC endpoint that does not require signed requests.
func MustDial ¶ added in v0.5.0
func MustDial(rawurl string, prv *ecdsa.PrivateKey) *w3.Client
MustDial is like Dial but panics if the connection establishment fails.
Use w3.MustDial to connect to an RPC endpoint that does not require signed requests.
func SendBundle ¶
func SendBundle(r *SendBundleRequest) w3types.RPCCallerFactory[common.Hash]
SendBundle sends the bundle to the client's endpoint.
func SendPrivateTx ¶ added in v0.5.0
func SendPrivateTx(r *SendPrivateTxRequest) w3types.RPCCallerFactory[common.Hash]
SendPrivateTx sends a private transaction to the Flashbots relay.
func UserStats
deprecated
func UserStats(blockNumber *big.Int) w3types.RPCCallerFactory[*UserStatsResponse]
UserStats requests the users Flashbots relay stats. The given block number must be within 20 blocks of the current chain tip.
Deprecated: Use UserStatsV2 instead.
func UserStatsV2 ¶ added in v0.6.0
func UserStatsV2(blockNumber *big.Int) w3types.RPCCallerFactory[*UserStatsV2Response]
UserStatsV2 requests the users Flashbots relay stats. The given block number must be within 20 blocks of the current chain tip.
Types ¶
type BundleStatsV2Response ¶ added in v0.6.0
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 uint64 // 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.
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.
type CallBundleResult ¶ added in v0.2.0
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 uint64 // Minimum Unix Timestamp for which the bundle is valid MaxTimestamp uint64 // Maximum Unix Timestamp for which the bundle is valid RevertingTxHashes []common.Hash // List of tx hashes in bundle that are allowed to revert. ReplacementUuid uuid.UUID // UUID that can be used to cancel/replace this bundle }
func (SendBundleRequest) MarshalJSON ¶ added in v0.2.0
func (s SendBundleRequest) MarshalJSON() ([]byte, error)
MarshalJSON implements the json.Marshaler.
type SendPrivateTxRequest ¶ added in v0.5.0
type SendPrivateTxRequest struct { Tx *types.Transaction // Signed transaction to send. RawTx []byte // Raw signed transaction to send. MaxBlockNumber *big.Int // Max block number for which the tx should be included (Optional). Fast bool // Enable fast mode (Optional). See https://docs.flashbots.net/flashbots-protect/rpc/fast-mode }
func (SendPrivateTxRequest) MarshalJSON ¶ added in v0.5.0
func (c SendPrivateTxRequest) MarshalJSON() ([]byte, error)
MarshalJSON implements the json.Marshaler.
type UserStatsResponse
deprecated
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. }
Deprecated: Use UserStatsV2Response instead.
func (*UserStatsResponse) UnmarshalJSON ¶
func (u *UserStatsResponse) UnmarshalJSON(input []byte) error
UnmarshalJSON implements the json.Unmarshaler.
type UserStatsV2Response ¶ added in v0.6.0
type UserStatsV2Response struct { IsHighPriority bool // True if the searcher has an high enough reputation to be in the high priority queue. AllTimeValidatorPayments *big.Int // Total amount paid to validators over all time. AllTimeGasSimulated *big.Int // Total amount of gas simulated across all bundles submitted to the relay. Last7dValidatorPayments *big.Int // Total amount paid to validators 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. Last1dValidatorPayments *big.Int // Total amount paid to validators over the last day. Last1dGasSimulated *big.Int // Total amount of gas simulated across all bundles submitted to the relay in the last day. }
func (*UserStatsV2Response) UnmarshalJSON ¶ added in v0.6.0
func (u *UserStatsV2Response) UnmarshalJSON(input []byte) error
UnmarshalJSON implements the json.Unmarshaler.