Skip to content

Integrating Flashbots Protect

Flashbots Protect is an RPC service that helps protect your users' Ethereum transactions from dangerous frontrunning attacks by submitting transactions to a private mempool that remains hidden from bots. You can also use the service to earn MEV refunds on any MEV realized through backrunning.

To integrate Flashbots Protect with Privy, first configure the Flashbots RPC URL for the chain your app needs:

tsx
import {mainnet} from 'viem/chains';

import {addRpcUrlOverrideToChain} from '@privy-io/react-auth';

// Configure the Flashbots RPC URL for mainnet
const mainnetWithFlashbotsProtect = addRpcUrlOverrideToChain(
  mainnet,
  'https://rpc.flashbots.net/fast',
);

Next, pass the chain configured with the Flashbots RPC URL to the config.supportedChains property of the PrivyProvider:

tsx
<PrivyProvider
  appId="your-privy-app-id"
  config={{
    ...theRestOfYourConfig,
    supportedChains: [mainnetWithFlashbotsProtect, ...otherChains],
  }}
>
  {/* your app's content */}
</PrivyProvider>

That's it! Once you've configured Flashbots Protect as the RPC URL for your desired chain, Privy will route your users' transactions through the private Flashbots mempool.

INFO

Flashbots Protect currently only supports Ethereum mainnet, the Ethereum Sepolia testnet, and the Ethereum Holesky testnet. The team is actively building support for other networks, including L2s, as well.