[Ethereum] How to create and send Flashbot transactions

flashbotsminingpythontransactionsweb3.py

So far, I only understand flashbot bundles are signed raw transactions with one of them being a bribe to the miner for the mining fee, but :

  • Is the bribing transaction special in the way it is valid for all all block.coinbase being used or is it valid only for a single miner? If yes, how do I build and sign such special formated bribing transactions?
  • In order to determine the gas price for standard/mempool transactions, there’s https://ethgasstation.info/, but how to compute the minimal amount for the bribe being sent to block.coinbase which would allow getting the bundle mined into a reasonable timeframe? I’m asking this in general and without considering competition because I imagine miners won’t accept transaction which doesn’t pay more than gas price and that the price to be paid isn’t flat in the way the amount of gas consumed still matters.
  • Since I’m not running my own node, how I can build such transaction bundles from my signed rawtransaction list, and how to submit them to the flashbots relay without running my own node once they are built into the correct binary format? Something which is not explained by https://github.com/flashbots/pm/blob/main/guides/searcher-onboarding.md
  • If I create my own mining pool, how can I receive flashbot transaction? Is there a place where I need to subscribe?

My interest, here isn’t to create transaction bundles since there’s a single transaction to perform in the case I’m interested in, but to get that transaction being mined first since flashbot transactions are mined at the beginning of the block (frontrunning transactions still using the mempool). And with the point that nobody is using flashbots yet.
Though I understand that I need to create a bundle of at least 2 transactions though since one of them must be for the miner.

Best Answer

The official flashbots searcher onboarding guide is a good source to get started.

  • block.coinbase in Solidity refers to the miner of the current block. You can use the ethers.js flashbots bundle provider to bundle your transactions with a final call to the Flashbots "CheckAndSend" contract. That way, the miner will only be rewarded, if the previous transactions of your bundle were successful. (The miner will not include your bundle, if he doesn't get rewarded.)

  • The flashbots bribe is independent from the current gas price. You're competing with the bribes of other flashbot searchers. Currently MEV geth only allows for the inclusion of one flashbots bundle per block (but this may change soon). Generally speaking, the less alpha, the higher the bribe. Meaning, if you intend to be running widespread simple arbitrage code, consider bribing with 99% of the arbitrage profit, to get your bundles mined at all (hopefully).

  • Unless you have private connections to miners with significant hash rate, you'll probably want to use (and trust) the official flashbots relay, which is also used in the ethers.js flashbots bundle provider. Check this example from its readme:

// Using the map below ships two different bundles, targeting the next two blocks
const blockNumber = await provider.getBlockNumber()
const minTimestamp = (await provider.getBlock(blockNumber)).timestamp
const maxTimestamp = minTimestamp + 120
const bundlePromises = [blockNumber + 1, blockNumber + 2].map((targetBlockNumber) =>
  flashbotsProvider.sendBundle(
    [
      {
        signedTransaction: SIGNED_ORACLE_UPDATE_FROM_PENDING_POOL // serialized signed transaction hex
      },
      {
        signer: wallet, // ethers signer
        transaction: transaction // ethers populated transaction object
      }
    ],
    targetBlockNumber, // block number at which this bundle is valid
    {
      minTimestamp, // optional minimum timestamp at which this bundle is valid (inclusive)
      maxTimestamp, // optional maximum timestamp at which this bundle is valid (inclusive)
      revertingTxHashes: [tx1, tx2] // optional list of transaction hashes allowed to revert. Without specifying here, any revert invalidates the entire bundle.
    }
  )
)
Related Topic