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

Commit 4a7586b

Browse files
committed
cancelPrivateTransaction cleanup
1 parent 1370149 commit 4a7586b

File tree

6 files changed

+33
-8
lines changed

6 files changed

+33
-8
lines changed

examples/cancelPrivateTransaction/main.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,32 @@
11
package main
22

33
import (
4+
"errors"
45
"fmt"
56

67
"github.com/ethereum/go-ethereum/crypto"
78
"github.com/metachris/flashbotsrpc"
89
)
910

1011
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")
1113

1214
func main() {
1315
rpc := flashbotsrpc.New("https://relay.flashbots.net")
1416
rpc.Debug = true
1517

1618
cancelPrivTxArgs := flashbotsrpc.FlashbotsCancelPrivateTransactionRequest{
17-
TxHash: "0xfb34b88cd77215867aa8e8ff0abc7060178b8fed6519a85d0b22853dfd5e9fec",
19+
TxHash: "0xYOUR_TX_HASH",
1820
}
1921

2022
cancelled, err := rpc.FlashbotsCancelPrivateTransaction(privateKey, cancelPrivTxArgs)
2123
if err != nil {
22-
fmt.Printf("%+v\n", err)
24+
if errors.Is(err, flashbotsrpc.ErrRelayErrorResponse) {
25+
// ErrRelayErrorResponse means it's a standard Flashbots relay error response, so probably a user error, rather than JSON or network error
26+
fmt.Println(err.Error())
27+
} else {
28+
fmt.Printf("error: %+v\n", err)
29+
}
2330
return
2431
}
2532

examples/sendPrivateTransaction/main.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,21 +9,23 @@ import (
99
)
1010

1111
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")
1213

1314
func main() {
1415
rpc := flashbotsrpc.New("https://relay.flashbots.net")
1516
rpc.Debug = true
1617

1718
sendPrivTxArgs := flashbotsrpc.FlashbotsSendPrivateTransactionRequest{
18-
Tx: "0xYourTxHash",
19+
Tx: "0xYOUR_RAW_TX",
1920
}
2021

2122
txHash, err := rpc.FlashbotsSendPrivateTransaction(privateKey, sendPrivTxArgs)
2223
if err != nil {
2324
if errors.Is(err, flashbotsrpc.ErrRelayErrorResponse) {
24-
fmt.Println(err.Error()) // standard error response from relay
25+
// ErrRelayErrorResponse means it's a standard Flashbots relay error response, so probably a user error, rather than JSON or network error
26+
fmt.Println(err.Error())
2527
} else {
26-
fmt.Printf("unknown error: %+v\n", err)
28+
fmt.Printf("error: %+v\n", err)
2729
}
2830
return
2931
}

examples/sendbundle/main.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
package main
22

33
import (
4+
"errors"
45
"fmt"
56

67
"github.com/ethereum/go-ethereum/crypto"
78
"github.com/metachris/flashbotsrpc"
89
)
910

1011
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")
1113

1214
func main() {
1315
rpc := flashbotsrpc.New("https://relay.flashbots.net")
@@ -20,7 +22,12 @@ func main() {
2022

2123
result, err := rpc.FlashbotsSendBundle(privateKey, sendBundleArgs)
2224
if err != nil {
23-
fmt.Printf("%+v\n", err)
25+
if errors.Is(err, flashbotsrpc.ErrRelayErrorResponse) {
26+
// ErrRelayErrorResponse means it's a standard Flashbots relay error response, so probably a user error, rather than JSON or network error
27+
fmt.Println(err.Error())
28+
} else {
29+
fmt.Printf("error: %+v\n", err)
30+
}
2431
return
2532
}
2633

examples/userstats/main.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,29 @@
11
package main
22

33
import (
4+
"errors"
45
"fmt"
56

67
"github.com/ethereum/go-ethereum/crypto"
78
"github.com/metachris/flashbotsrpc"
89
)
910

1011
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")
1113

1214
func main() {
1315
rpc := flashbotsrpc.New("https://relay.flashbots.net")
1416

1517
// Query relay for user stats
1618
result, err := rpc.FlashbotsGetUserStats(privateKey, 13281018)
1719
if err != nil {
18-
panic(err)
20+
if errors.Is(err, flashbotsrpc.ErrRelayErrorResponse) {
21+
// ErrRelayErrorResponse means it's a standard Flashbots relay error response, so probably a user error, rather than JSON or network error
22+
fmt.Println(err.Error())
23+
} else {
24+
fmt.Printf("error: %+v\n", err)
25+
}
26+
return
1927
}
2028

2129
// Print result

flashbotsrpc.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -693,7 +693,7 @@ func (rpc *FlashbotsRPC) FlashbotsSendPrivateTransaction(privKey *ecdsa.PrivateK
693693

694694
// docs todo
695695
func (rpc *FlashbotsRPC) FlashbotsCancelPrivateTransaction(privKey *ecdsa.PrivateKey, param FlashbotsCancelPrivateTransactionRequest) (cancelled bool, err error) {
696-
rawMsg, err := rpc.CallWithFlashbotsSignature("eth_sendPrivateTransaction", privKey, param)
696+
rawMsg, err := rpc.CallWithFlashbotsSignature("eth_cancelPrivateTransaction", privKey, param)
697697
if err != nil {
698698
return false, err
699699
}

types.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"github.com/pkg/errors"
1010
)
1111

12+
// ErrRelayErrorResponse means it's a standard Flashbots relay error response - probably a user error rather than JSON or network error
1213
var ErrRelayErrorResponse = errors.New("relay error response")
1314

1415
// Syncing - object with syncing data info

0 commit comments

Comments
 (0)