Skip to main content

web3-flashbots.py

Project description

This library works by injecting flashbots as a new module in the Web3.py instance, which allows submitting "bundles" of transactions directly to miners. This is done by also creating a middleware which captures calls to eth_sendBundle and eth_callBundle, and sends them to an RPC endpoint which you have specified, which corresponds to mev-geth.

To apply correct headers we use the flashbot method which injects the correct header on POST.

Quickstart

from eth_account.signers.local import LocalAccount
from web3 import Web3, HTTPProvider
from flashbots import flashbot
from eth_account.account import Account
import os

ETH_ACCOUNT_SIGNATURE: LocalAccount = Account.from_key(os.environ.get("ETH_SIGNATURE_KEY"))


w3 = Web3(HTTPProvider("http://localhost:8545"))
flashbot(w3, ETH_ACCOUNT_SIGNATURE)

Now the w3.flashbots.sendBundle method should be available to you. Look in examples/simple.py for usage examples.

Goerli

To use goerli, add the goerli relay RPC to the flashbot function arguments.

flashbot(w3, ETH_ACCOUNT_SIGNATURE, "https://relay-goerli.flashbots.net")

Development and testing

Install poetry

Poetry will automatically fix your venv and all packages needed.

poetry install

Tips: PyCharm has a poetry plugin

Simple Goerli Example

See examples/simple.py for environment variable definitions.

poetry shell
ETH_SENDER_KEY=<sender_private_key> \nPROVIDER_URL=https://eth-goerli.alchemyapi.io/v2/<alchemy_key> \nETH_SIGNER_KEY=<signer_private_key> \npython examples/simple.py

Linting

It's advisable to run black with default rules for linting

sudo pip install black # Black should be installed with a global entrypoint
black .

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

flashbots-1.1.1.tar.gz (10.0 kB view details)

Uploaded Source

Built Distribution

flashbots-1.1.1-py3-none-any.whl (10.0 kB view details)

Uploaded Python 3

File details

Details for the file flashbots-1.1.1.tar.gz.

File metadata

  • Download URL: flashbots-1.1.1.tar.gz
  • Upload date:
  • Size: 10.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.0 CPython/3.9.15

File hashes

Hashes for flashbots-1.1.1.tar.gz
Algorithm Hash digest
SHA256 94e7c768d6d5072271defccba39310ff3ac69ef6845b6a6ac188e679c9488ac0
MD5 3a4b84f299a249d001c5e781017c8d6d
BLAKE2b-256 052ac30bf0bf366f5772b535731912d6307363183b3179da3f5e426aec6ef446

See more details on using hashes here.

File details

Details for the file flashbots-1.1.1-py3-none-any.whl.

File metadata

  • Download URL: flashbots-1.1.1-py3-none-any.whl
  • Upload date:
  • Size: 10.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.0 CPython/3.9.15

File hashes

Hashes for flashbots-1.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 d919d633b026ffec8bd65cd53d68f54dc98d41d299a6b4d31c2e16d4e1e87b36
MD5 c010b9c22a3a3010227271cbf1451989
BLAKE2b-256 40d9806908319ec53375297ece08dd1ad00af8becb5d63c236e2a7023a50bb22

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page