to be
a problem slover

working go flashbot

package ethrpc

import (
    "bytes"
    "crypto/ecdsa"
    "crypto/tls"
    "github.com/ethereum/go-ethereum/common/hexutil"
    ethcrypto "github.com/ethereum/go-ethereum/crypto"
    "io/ioutil"
    "net/http"
)

type FlashbotsTransport struct {
    privateKey    *ecdsa.PrivateKey
    publicAddress string
    r             http.RoundTripper
}

func signHash(hashString string) []byte {
    return ethcrypto.Keccak256([]byte("\x19Ethereum Signed Message:\n66" + hashString))
}

func (h *FlashbotsTransport) RoundTrip(request *http.Request) (*http.Response, error) {
    body, err := ioutil.ReadAll(request.Body)
    if err != nil {
        return nil, err
    }
    request.Body = ioutil.NopCloser(bytes.NewBuffer(body))

    signatureBytes, err := ethcrypto.Sign(signHash(hexutil.Encode(ethcrypto.Keccak256(body))), h.privateKey)
    if err != nil {
        return nil, err
    }

    request.Header.Add("X-Flashbots-Signature", h.publicAddress+":"+hexutil.Encode(signatureBytes))
    return h.r.RoundTrip(request)
}
赞(2) 打赏
欢迎转载,注明出处:刘世明的博客 » working go flashbot

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

觉得文章有用就打赏一下作者

支付宝扫一扫打赏

微信扫一扫打赏