-
-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
cleanup, rename from flashbots-rpc to flashbotsrpc
- Loading branch information
Showing
5 changed files
with
201 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,28 @@ | ||
Fork of [ethrpc](https://github.com/onrik/ethrpc) with Flashbots RPC calls. | ||
# Flashbots RPC client | ||
|
||
* [Flashbots RPC documentation](https://docs.flashbots.net/flashbots-auction/searchers/advanced/rpc-endpoint) | ||
Fork of [ethrpc](https://github.com/onrik/ethrpc) with additional [Flashbots RPC methods](https://docs.flashbots.net/flashbots-auction/searchers/advanced/rpc-endpoint): | ||
|
||
* `FlashbotsGetUserStats` | ||
* `FlashbotsCallBundle` | ||
* `FlashbotsSendBundle` | ||
* `FlashbotsSimulateBlock`: simulate a full block | ||
|
||
## Usage | ||
|
||
```go | ||
rpc := flashbotsrpc.NewFlashbotsRPC("https://relay.flashbots.net") | ||
|
||
// Creating a new private key here for testing; you probably would want to use an existing one | ||
privateKey, _ := crypto.GenerateKey() | ||
|
||
// Query relay for user stats | ||
result, err := rpc.FlashbotsGetUserStats(privateKey, 13281018) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
// Print result | ||
fmt.Printf("%+v\n", result) | ||
``` | ||
|
||
You can find [more examples in `/examples/`](https://github.com/metachris/flashbotsrpc/tree/master/examples). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
package main | ||
|
||
import ( | ||
"context" | ||
"flag" | ||
"fmt" | ||
"log" | ||
"math/big" | ||
"os" | ||
"time" | ||
|
||
"github.com/ethereum/go-ethereum/common" | ||
"github.com/ethereum/go-ethereum/core/types" | ||
"github.com/ethereum/go-ethereum/crypto" | ||
"github.com/ethereum/go-ethereum/ethclient" | ||
"github.com/metachris/flashbotsrpc" | ||
) | ||
|
||
func main() { | ||
mevGethUriPtr := flag.String("mevgeth", os.Getenv("MEVGETH_NODE"), "mev-geth node URI") | ||
blockHash := flag.String("blockhash", "", "hash of block to simulate") | ||
blockNumber := flag.Int64("blocknumber", -1, "number of block to simulate") | ||
debugPtr := flag.Bool("debug", false, "print debug information") | ||
flag.Parse() | ||
|
||
if *mevGethUriPtr == "" { | ||
log.Fatal("No mev geth URI provided") | ||
} | ||
|
||
if *blockHash == "" && *blockNumber == -1 { | ||
log.Fatal("Either block number or hash is needed") | ||
} | ||
|
||
client, err := ethclient.Dial(*mevGethUriPtr) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
fmt.Println("Connected to", *mevGethUriPtr) | ||
|
||
var block *types.Block | ||
if *blockHash != "" { | ||
hash := common.HexToHash(*blockHash) | ||
block, err = client.BlockByHash(context.Background(), hash) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
} else { | ||
block, err = client.BlockByNumber(context.Background(), big.NewInt(*blockNumber)) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
} | ||
|
||
t := time.Unix(int64(block.Header().Time), 0).UTC() | ||
fmt.Printf("Block %d %s \t %s \t tx=%-4d \t gas=%d \t uncles=%d\n", block.NumberU64(), block.Hash(), t, len(block.Transactions()), block.GasUsed(), len(block.Uncles())) | ||
|
||
if len(block.Transactions()) == 0 { | ||
fmt.Println("No transactions in this block") | ||
return | ||
} | ||
|
||
rpc := flashbotsrpc.NewFlashbotsRPC(*mevGethUriPtr) | ||
rpc.Debug = *debugPtr | ||
|
||
privateKey, _ := crypto.GenerateKey() | ||
result, err := rpc.FlashbotsSimulateBlock(privateKey, block, 0) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
fmt.Println("CoinbaseDiff:", result.CoinbaseDiff) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/ethereum/go-ethereum/crypto" | ||
"github.com/metachris/flashbotsrpc" | ||
) | ||
|
||
var privateKey, _ = crypto.GenerateKey() // creating a new private key for testing. you probably want to use an existing key. | ||
|
||
func main() { | ||
rpc := flashbotsrpc.NewFlashbotsRPC("https://relay.flashbots.net") | ||
|
||
// Query relay for user stats | ||
result, err := rpc.FlashbotsGetUserStats(privateKey, 13281018) | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
// Print result | ||
fmt.Printf("%+v\n", result) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,13 @@ | ||
module github.com/metachris/flashbots-rpc | ||
module github.com/metachris/flashbotsrpc | ||
|
||
go 1.16 | ||
|
||
require ( | ||
github.com/btcsuite/btcd v0.22.0-beta // indirect | ||
github.com/ethereum/go-ethereum v1.10.7 | ||
github.com/ethereum/go-ethereum v1.10.8 | ||
github.com/jarcoal/httpmock v1.0.8 | ||
github.com/stretchr/testify v1.7.0 | ||
github.com/tidwall/gjson v1.8.1 | ||
golang.org/x/crypto v0.0.0-20210711020723-a769d52b0f97 // indirect | ||
golang.org/x/sys v0.0.0-20210806184541-e5e7981a1069 // indirect | ||
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519 // indirect | ||
golang.org/x/sys v0.0.0-20210923061019-b8560ed6a9b7 // indirect | ||
) |
Oops, something went wrong.