0

Recently I've been having some trouble with the X-Flashbots-Signature header when sending a request to the flashbots endpoint. My python code looks like this:

import requests
import json
import secrets
from eth_account import Account, messages
from web3 import Web3
from math import ceil

rpcUrl = RPC_NODE_PROVIDER
web3 = Web3(Web3.HTTPProvider(rpcUrl))

publicKey = ETH_PUBLIC_KEY
privateKey = ETH_PRIVATE_KEY
contractAddress = TEST_CONTRACT # test contract
data = CONTRACT_DATA # Contract data to execute

signed = []
for _ in range(2):
    nonce = web3.eth.getTransactionCount(publicKey, 'pending')
    checksumAddress = Web3.toChecksumAddress(contractAddress)
    checksumPublic = Web3.toChecksumAddress(publicKey)
    tx = {
        'nonce': nonce,
        'to': checksumAddress,
        'from': checksumPublic,
        'value': 0,
        'gasPrice': web3.toWei(200, 'gwei'),
        'data': data
    }
    gas = web3.eth.estimateGas(tx)
    tx['gas'] = ceil(gas + gas * .1)
    signed_tx = web3.eth.account.signTransaction(tx, privateKey)
    signed.append(Web3.toHex(signed_tx.rawTransaction))

dt = {
    'jsonrpc': '2.0',
    'method': 'eth_sendBundle',
    'params': [
        {
            'txs': [
                signed[0], signed[1] # Signed txs with web3.eth.account.signTransaction
            ],
            'blockNumber': web3.eth.block_number + 1,
        }
    ],
    'id': 1
}
pvk = secrets.token_hex(32)
pbk = Account.from_key(pvk).address

body = json.dumps(dt)
message = messages.encode_defunct(text=Web3.keccak(text=body).hex())
signature = pbk + ':' + Account.sign_message(message, pvk).signature.hex()

hd = {
    'Content-Type': 'application/json',
    'X-Flashbots-Signature': signature,
}

res = requests.post('https://relay.flashbots.net/', json=body, headers=hd,)
print(res.text)

This code is a modified version of code taken straight from the flashbots docs: https://docs.flashbots.net/flashbots-auction/searchers/advanced/rpc-endpoint/#authentication Upon running this code I get a 200 response from flashbots and it gives me a bundlehash, but the transaction never goes through.

When I input the bundlehash into "flashbots_getBundleStatsV2" method, I get this response:

{'id': 1, 'error': {'code': -32600, 'message': 'error in signature check 0xF65f5D0611c5B184D62C9b063585D7246D3F4df8'}, 'jsonrpc': '2.0'}

Any ideas would be greatly appreciated.

1 Answer 1

0

Likely due to a shift in the web3 version, that removed prefixes on some hashes.

Previously would look like:

message = messages.encode_defunct(text=w3.keccak(text=_tx_body).hex()) 
signature = f'{Account.from_key(FLA).address}:{Account.sign_message(message, FLA).signature.hex()}'

Currently:

message = messages.encode_defunct(text='0x' + w3.keccak(text=_tx_body).hex()) 
signature = f'{Account.from_key(FLA).address}:0x{Account.sign_message(message, FLA).signature.hex()}'
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.