Skip to content

Instantly share code, notes, and snippets.

@sbarratt
Created Apr 11, 2021
Embed
What would you like to do?
flashbots http attempt
package main
import (
"fmt"
"log"
"bytes"
"math/big"
"encoding/json"
"io/ioutil"
"net/http"
"strconv"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/hexutil"
"github.com/ethereum/go-ethereum/crypto"
)
func main() {
pk, err := crypto.HexToECDSA("b72aefb5233f04314b01f8541db76439cc421a8f2a076338491512e9e1a8e6d8")
if err != nil {
log.Fatal(err)
}
addr := common.HexToAddress("0xfa2707dE5Ab94a924A151112cEcfe972235c6281")
body_json := map[string]interface{}{
"jsonrpc": "2.0",
"method": "flashbots_getUserStats",
"params": []string{hexutil.EncodeBig(big.NewInt(123))},
"id": 0,
}
body, _ := json.Marshal(body_json)
hashedBody := crypto.Keccak256Hash([]byte(body)).Hex()
sig, err := crypto.Sign(crypto.Keccak256([]byte("\x19Ethereum Signed Message:\n"+strconv.Itoa(len(hashedBody))+hashedBody)), pk)
signature := addr.Hex() + ":" + hexutil.Encode(sig)
req, err := http.NewRequest("POST", "https://relay.flashbots.net", bytes.NewReader(body))
if err != nil {
log.Fatalf("Could not create request")
}
req.Header.Add("X-Flashbots-Signature", signature)
fmt.Println(req)
client := &http.Client{}
resp, err := client.Do(req)
if err != nil {
panic(err)
}
defer resp.Body.Close()
fmt.Println("response Status:", resp.Status)
fmt.Println("response Headers:", resp.Header)
response_body, _ := ioutil.ReadAll(resp.Body)
fmt.Println("response Body:", string(response_body))
}
@sbarratt

This comment has been minimized.

Copy link
Owner Author

@sbarratt sbarratt commented Apr 11, 2021

Result from go run flash.go:

&{POST https://relay.flashbots.net HTTP/1.1 1 1 map[X-Flashbots-Signature:[0xfa2707dE5Ab94a924A151112cEcfe972235c6281:0x5ac9fbd8263c90d781668e74934e7af343c6153a193479440ade73d5783d78d41f790a62a01dcf9dc211c591368bc577bf67d29264e74935ae8fbd716739a29501]] {0xc0000c8f60} 0x642440 76 [] false relay.flashbots.net map[] map[] <nil> map[]   <nil> <nil> <nil> 0xc000018140}
response Status: 400 Bad Request
response Headers: map[Cf-Cache-Status:[DYNAMIC] Cf-Ray:[63e829d79c7ced57-SJC] Cf-Request-Id:[0964f87ac30000ed578ea6d000000001] Content-Length:[38] Content-Type:[application/json; charset=utf-8] Date:[Sun, 11 Apr 2021 23:58:31 GMT] Etag:[W/"26-KQ4f5KXWDamfpgEZs5coCpxYhV8"] Expect-Ct:[max-age=604800, report-uri="https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct"] Nel:[{"max_age":604800,"report_to":"cf-nel"}] Report-To:[{"max_age":604800,"group":"cf-nel","endpoints":[{"url":"https:\/\/a.nel.cloudflare.com\/report?s=Zh9WP%2FcGU3qXa1r7ruPP0aTrltqac4fwANyCEI6dg4lukQ7jjtMxG5ftwtbORFEUbfqqTgDiDGXY4rZhqmL7v%2FM7HQp9s%2Fr1ydNy%2BiH7XJFv8BoCjKDIcHIjJay5yuEq"}]}] Server:[cloudflare] Set-Cookie:[__cfduid=d2b166bb755f3984e4c95520191691c571618185511; expires=Tue, 11-May-21 23:58:31 GMT; path=/; domain=.flashbots.net; HttpOnly; SameSite=Lax; Secure] X-Powered-By:[Express] X-Ratelimit-Limit:[60] X-Ratelimit-Remaining:[59] X-Ratelimit-Reset:[1618185530]]
response Body: {"error":{"message":"missing method"}}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment