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

Commit e8a0f2d

Browse files
committed
examples: callBundle
1 parent 3d779a7 commit e8a0f2d

File tree

3 files changed

+67
-9
lines changed

3 files changed

+67
-9
lines changed

README.md

Lines changed: 32 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,26 +11,48 @@ Fork of [ethrpc](https://github.com/onrik/ethrpc) with additional [Flashbots RPC
1111

1212
## Usage
1313

14+
Add library to your project:
15+
1416
`go get github.com/metachris/flashbotsrpc`
1517

16-
```go
17-
rpc := flashbotsrpc.New("https://relay.flashbots.net")
18+
Create a new private key here for testing (you probably want to use an existing one):
1819

19-
// Creating a new private key here for testing, you probably want to use an existing one
20+
```go
2021
privateKey, _ := crypto.GenerateKey()
22+
```
23+
24+
#### Simulate transactions with `eth_callBundle`:
25+
26+
```go
27+
callBundleArgs := flashbotsrpc.FlashbotsCallBundleParam{
28+
Txs: []string{"YOUR_RAW_TX"},
29+
BlockNumber: fmt.Sprintf("0x%x", 13281018),
30+
StateBlockNumber: "latest",
31+
}
32+
33+
result, err := rpc.FlashbotsCallBundle(privateKey, callBundleArgs)
34+
if err != nil {
35+
log.Fatal(err)
36+
}
37+
fmt.Printf("%+v\n", result)
38+
```
39+
40+
#### Get Flashbots user stats:
2141

22-
// flashbots_getUserStats example
23-
// ------------------------------
42+
```go
43+
rpc := flashbotsrpc.New("https://relay.flashbots.net")
2444
result, err := rpc.FlashbotsGetUserStats(privateKey, 13281018)
2545
if err != nil {
2646
log.Fatal(err)
2747
}
2848
fmt.Printf("%+v\n", result)
49+
```
50+
51+
#### Send a transaction bundle to Flashbots with `eth_sendBundle`:
2952

30-
// eth_sendBundle example
31-
// ----------------------
53+
```go
3254
sendBundleArgs := flashbotsrpc.FlashbotsSendBundleRequest{
33-
Txs: []string{"YOUR_HASH"},
55+
Txs: []string{"YOUR_RAW_TX"},
3456
BlockNumber: fmt.Sprintf("0x%x", 13281018),
3557
}
3658

@@ -41,4 +63,6 @@ if err != nil {
4163
fmt.Printf("%+v\n", result)
4264
```
4365

66+
#### More examples
67+
4468
You can find example code in the [`/examples/` directory](https://github.com/metachris/flashbotsrpc/tree/master/examples).

examples/callBundle/main.go

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package main
2+
3+
import (
4+
"errors"
5+
"fmt"
6+
7+
"github.com/ethereum/go-ethereum/crypto"
8+
"github.com/metachris/flashbotsrpc"
9+
)
10+
11+
var privateKey, _ = crypto.GenerateKey() // creating a new private key for testing. you probably want to use an existing key.
12+
// var privateKey, _ = crypto.HexToECDSA("YOUR_PRIVATE_KEY")
13+
14+
func main() {
15+
rpc := flashbotsrpc.New("https://relay.flashbots.net")
16+
opts := flashbotsrpc.FlashbotsCallBundleParam{
17+
Txs: []string{"YOUR_RAW_TX"},
18+
BlockNumber: fmt.Sprintf("0x%x", 13281018),
19+
StateBlockNumber: "latest",
20+
}
21+
22+
result, err := rpc.FlashbotsCallBundle(privateKey, opts)
23+
if err != nil {
24+
if errors.Is(err, flashbotsrpc.ErrRelayErrorResponse) { // user/tx error, rather than JSON or network error
25+
fmt.Println(err.Error())
26+
} else {
27+
fmt.Printf("error: %+v\n", err)
28+
}
29+
return
30+
}
31+
32+
// Print result
33+
fmt.Printf("%+v\n", result)
34+
}

examples/sendbundle/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ func main() {
1616
rpc.Debug = true
1717

1818
sendBundleArgs := flashbotsrpc.FlashbotsSendBundleRequest{
19-
Txs: []string{"YOUR_HASH"},
19+
Txs: []string{"YOUR_RAW_TX"},
2020
BlockNumber: fmt.Sprintf("0x%x", 13281018),
2121
}
2222

0 commit comments

Comments
 (0)