Skip to content

Commit d2fb64b

Browse files
odysseus0claude
andcommitted
Update Go example to use generic eth_sendBundle instead of deprecated API
Changes the Go example to demonstrate authentication with eth_sendBundle instead of the deprecated flashbots_getUserStats method. Keeps the same structure and authentication logic as the original example. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
1 parent 3fcb65f commit d2fb64b

File tree

1 file changed

+71
-0
lines changed

1 file changed

+71
-0
lines changed

docs/flashbots-auction/quick-start.mdx

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ Next, you need a means to communicate with the Flashbots network. The Flashbots
4848
values={[
4949
{ label: 'ethers.js', value: 'ethers.js', },
5050
{ label: 'web3.py', value: 'web3.py' },
51+
{ label: 'go', value: 'go' },
5152
{ label: 'rust', value: 'rust'},
5253
]}
5354
>
@@ -100,6 +101,76 @@ ETH_ACCOUNT_SIGNATURE: LocalAccount = Account.from_key(os.environ.get("ETH_SIGNA
100101
flashbot(w3, ETH_ACCOUNT_SIGNATURE)
101102
```
102103

104+
</TabItem>
105+
<TabItem value="go">
106+
107+
```go
108+
package main
109+
110+
import (
111+
"bytes"
112+
"crypto/ecdsa"
113+
"encoding/json"
114+
"io/ioutil"
115+
"net/http"
116+
"time"
117+
118+
"github.com/ethereum/go-ethereum/accounts"
119+
"github.com/ethereum/go-ethereum/common/hexutil"
120+
"github.com/ethereum/go-ethereum/crypto"
121+
)
122+
123+
const (
124+
flashbotURL = "https://relay.flashbots.net"
125+
flashbotXHeader = "X-Flashbots-Signature"
126+
)
127+
128+
var (
129+
// authSigner is an Ethereum private key that does NOT store funds and is NOT your bot's primary key.
130+
// This is an identifying key for signing payloads to establish reputation and whitelisting
131+
privateKey, _ = crypto.HexToECDSA(
132+
"2e19800fcbbf0abb7cf6d72ee7171f08943bc8e5c3568d1d7420e52136898154",
133+
)
134+
)
135+
136+
func flashbotHeader(signature []byte, privateKey *ecdsa.PrivateKey) string {
137+
return crypto.PubkeyToAddress(privateKey.PublicKey).Hex() +
138+
":" + hexutil.Encode(signature)
139+
}
140+
141+
func main() {
142+
// Example: create a Flashbots authenticated request
143+
mevHTTPClient := &http.Client{
144+
Timeout: time.Second * 3,
145+
}
146+
147+
// Prepare your RPC request (e.g., eth_sendBundle, eth_callBundle, etc.)
148+
params := map[string]interface{}{
149+
"jsonrpc": "2.0",
150+
"id": 1,
151+
"method": "eth_sendBundle", // or other Flashbots RPC methods
152+
"params": []interface{}{ /* your bundle params */ },
153+
}
154+
155+
payload, _ := json.Marshal(params)
156+
req, _ := http.NewRequest("POST", flashbotURL, bytes.NewBuffer(payload))
157+
158+
// Sign the payload for Flashbots authentication
159+
headerReady, _ := crypto.Sign(
160+
accounts.TextHash([]byte(hexutil.Encode(crypto.Keccak256(payload)))),
161+
privateKey,
162+
)
163+
164+
req.Header.Add("content-type", "application/json")
165+
req.Header.Add("Accept", "application/json")
166+
req.Header.Add(flashbotXHeader, flashbotHeader(headerReady, privateKey))
167+
168+
resp, _ := mevHTTPClient.Do(req)
169+
res, _ := ioutil.ReadAll(resp.Body)
170+
_ = res // process response
171+
}
172+
```
173+
103174
</TabItem>
104175
<TabItem value="rust">
105176

0 commit comments

Comments
 (0)