https://github.com/flashbots/web3-flashbots
Web3.py plugin for using Flashbots' bundle APIs
https://github.com/flashbots/web3-flashbots
Last synced: about 1 year ago
JSON representation
Web3.py plugin for using Flashbots' bundle APIs
- Host: GitHub
- URL: https://github.com/flashbots/web3-flashbots
- Owner: flashbots
- License: mit
- Created: 2021-02-13T15:56:43.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2024-07-31T23:41:48.000Z (almost 2 years ago)
- Last Synced: 2025-04-03T00:12:17.490Z (about 1 year ago)
- Language: Python
- Homepage: https://pypi.org/project/flashbots/
- Size: 262 KB
- Stars: 417
- Watchers: 18
- Forks: 218
- Open Issues: 8
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# web3-flashbots
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
```python
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_SIGNER_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](./examples/simple.py) for usage examples.
### Goerli
To use goerli, add the goerli relay RPC to the `flashbot` function arguments.
```python
flashbot(w3, ETH_ACCOUNT_SIGNATURE, "https://relay-goerli.flashbots.net")
```
## Development and testing
Install [poetry](https://python-poetry.org/)
Poetry will automatically fix your venv and all packages needed.
```sh
poetry install
```
Tips: PyCharm has a poetry plugin
## Simple Testnet Example
See [examples/simple.py](./examples/simple.py) for environment variable definitions.
```sh
poetry shell
ETH_SENDER_KEY= \
PROVIDER_URL=https://eth-holesky.g.alchemy.com/v2/ \
ETH_SIGNER_KEY= \
python examples/simple.py
```
## Linting
It's advisable to run black with default rules for linting
```sh
sudo pip install black # Black should be installed with a global entrypoint
black .
```