Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
## [3.0.0] – 2025-05-06

### Breaking Changes
- Renamed all `.rawTransaction` properties to `.raw_transaction` (Web3.py v7 naming).
- Completely refactored middleware for Web3.py v7: now a class-based middleware using `wrap_make_request`.
- Overhauled `FlashbotProvider`:
- Replaced internal Web3 HTTP utils with `requests.post`.
- Switched to EIP-191 signing via `eth_account.messages.encode_defunct`.
- Removed deprecated imports from `eth_account._utils`.

### Added
- Official compatibility with Web3.py v7 (7.x series).
- Expanded tests covering `_parse_signed_tx` for legacy, EIP-2930 (type=1), and EIP-1559 (type=2) transactions.
- Configurable `request_timeout` parameter for `FlashbotProvider` (default: 10 seconds).
- Custom exception hierarchy: `FlashbotsError`, `InvalidTransactionError`, `TransactionSignatureError`, `BlockExtrapolationError`, `FlashbotsRequestError`.
- Explicit `__all__` exports in package `__init__.py`.

### Fixed
- Ensured numeric RLP fields (bytes) are converted to `int`.
- Added recovery of `chainId` for legacy transactions signed under EIP-155.
- Updated examples (`examples/simple.py`) to use `.raw_transaction` and new middleware/provider APIs.

### Changed
- Replaced `assert` statements with explicit validation raising domain-specific exceptions.
- Replaced lambda functions with list comprehensions for better readability.
- Improved error handling in `FlashbotProvider` with specific exception types for timeouts and connection errors.
- Added return type hints to `simulate()` and `extrapolate_timestamp()` methods.
- Migrated from Poetry to uv for package management (PEP 621 compliant `pyproject.toml`).

17 changes: 5 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,33 +32,26 @@ 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.
Install [uv](https://docs.astral.sh/uv/getting-started/installation/)

```sh
poetry install
uv sync --dev
```

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=<sender_private_key> \
PROVIDER_URL=https://eth-holesky.g.alchemy.com/v2/<alchemy_key> \
ETH_SIGNER_KEY=<signer_private_key> \
python examples/simple.py
uv run 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 .
uv run ruff check .
uv run ruff format .
```
2 changes: 1 addition & 1 deletion examples/simple.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ def main() -> None:

tx1_signed = w3.eth.account.sign_transaction(tx1, private_key=sender.key)
bundle = [
{"signed_transaction": tx1_signed.rawTransaction},
{"signed_transaction": tx1_signed.raw_transaction},
{"transaction": tx2, "signer": sender},
]

Expand Down
25 changes: 25 additions & 0 deletions flashbots/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,35 @@
from web3 import Web3
from web3._utils.module import attach_modules

from .exceptions import (
BlockExtrapolationError,
FlashbotsError,
FlashbotsProviderError,
FlashbotsRequestError,
FlashbotsTransactionError,
InvalidTransactionError,
TransactionSignatureError,
)
from .flashbots import Flashbots
from .middleware import construct_flashbots_middleware
from .provider import FlashbotProvider

__all__ = [
"BlockExtrapolationError",
"FlashbotsError",
"FlashbotsProviderError",
"FlashbotsRequestError",
"FlashbotsTransactionError",
"InvalidTransactionError",
"TransactionSignatureError",
"Flashbots",
"FlashbotProvider",
"FlashbotsWeb3",
"construct_flashbots_middleware",
"flashbot",
"DEFAULT_FLASHBOTS_RELAY",
]

DEFAULT_FLASHBOTS_RELAY = "https://relay.flashbots.net"


Expand Down
43 changes: 43 additions & 0 deletions flashbots/exceptions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
"""Custom exceptions for the Flashbots library."""


class FlashbotsError(Exception):
"""Base exception for all Flashbots errors."""

pass


class FlashbotsTransactionError(FlashbotsError):
"""Error related to transaction processing."""

pass


class InvalidTransactionError(FlashbotsTransactionError):
"""Raised when a transaction is invalid or malformed."""

pass


class TransactionSignatureError(FlashbotsTransactionError):
"""Raised when transaction signature verification fails."""

pass


class BlockExtrapolationError(FlashbotsError):
"""Raised when block timestamp extrapolation fails."""

pass


class FlashbotsProviderError(FlashbotsError):
"""Error related to the Flashbots provider."""

pass


class FlashbotsRequestError(FlashbotsProviderError):
"""Raised when a request to Flashbots relay fails."""

pass
Loading