Created
April 11, 2021 23:58
-
-
Save sbarratt/0a60f2cf3aaa1a760ad3fcab7e9aff64 to your computer and use it in GitHub Desktop.
flashbots http attempt
This file contains hidden or 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
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)) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Result from
go run flash.go
: