Skip to content

v3.0.0: Web3.py v7 support, uv migration, code quality improvements - #104

Open
kais92 wants to merge 12 commits into
flashbots:masterfrom
kais92:feature/web3-v7-support
Open

v3.0.0: Web3.py v7 support, uv migration, code quality improvements#104
kais92 wants to merge 12 commits into
flashbots:masterfrom
kais92:feature/web3-v7-support

Conversation

@kais92

@kais92 kais92 commented May 6, 2025

Copy link
Copy Markdown

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.
    • Removed deprecated imports from eth_account._utils.

Added

  • Official compatibility with Web3.py v7 (7.x series).
  • New helper get_transaction_type() to detect legacy, access list, and EIP-1559 tx types.
  • Expanded tests covering _parse_signed_tx for legacy, EIP-2930 (type=1), and EIP-1559 (type=2) transactions.

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.

@odysseus0

Copy link
Copy Markdown
Contributor

Pushed latest updates to this branch: added simulation test coverage and refreshed dependency/lockfile updates.

odysseus0 and others added 8 commits December 31, 2025 16:15
The gasPrice field was missing from the list of fields that get
converted from bytes to int, causing inconsistent behavior for
EIP-2930 access list transactions.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
The function was added but never used in the codebase.
Removing to avoid dead code.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
The timeout was hardcoded to 10 seconds. Users can now configure
it via the request_timeout parameter (default remains 10 seconds).

Also removes unused json import.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Change deprecated [tool.poetry.dev-dependencies] to
  [tool.poetry.group.dev.dependencies]
- Add pytest ^8.0.0 as explicit dev dependency

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Introduce domain-specific exceptions for better error handling:
- FlashbotsError: Base exception for all Flashbots errors
- FlashbotsTransactionError: Transaction-related errors
- InvalidTransactionError: Invalid/malformed transactions
- TransactionSignatureError: Signature verification failures
- BlockExtrapolationError: Block timestamp extrapolation errors
- FlashbotsProviderError: Provider-related errors
- FlashbotsRequestError: HTTP request failures

Also adds explicit __all__ exports in package __init__.py.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Replace assert statements with explicit validation using custom exceptions
- Replace lambda functions with list comprehensions for readability
- Add return type hints to simulate() and extrapolate_timestamp()
- Use sum() instead of reduce() for gas calculation
- Remove unused 'reduce' import

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Replace generic exception catching with specific handlers:
- requests.Timeout: Raised when request exceeds timeout
- requests.ConnectionError: Raised on connection failures
- requests.RequestException: Catch-all for other request errors

All exceptions are wrapped in FlashbotsRequestError with context.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Document new features and changes:
- Custom exception hierarchy
- Explicit __all__ exports
- Assert replacements with domain exceptions
- Lambda to list comprehension conversions
- Provider error handling improvements
- Return type hints additions

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@odysseus0 odysseus0 changed the title Feature/web3 v7 support Web3.py v7 support with code quality improvements Dec 31, 2025
- Convert pyproject.toml to PEP 621 format with hatchling backend
- Use [dependency-groups] for dev dependencies
- Replace poetry.lock with uv.lock
- Update README with uv commands
- Update linting instructions to use ruff

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@odysseus0 odysseus0 changed the title Web3.py v7 support with code quality improvements v3.0.0: Web3.py v7 support, uv migration, code quality improvements Dec 31, 2025
@zeroXbrock
zeroXbrock requested a lite review from Copilot August 12, 2026 20:03

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR delivers the v3.0.0 release work to support Web3.py v7, including breaking API renames (rawTransactionraw_transaction), a refactored v7-style middleware, a revamped FlashbotProvider, and new transaction parsing/test coverage to handle legacy and typed (EIP-2930/EIP-1559) signed transactions.

Changes:

  • Migrate packaging/dev workflow from Poetry to PEP 621 pyproject.toml + uv, and update README/example commands accordingly.
  • Refactor middleware/provider for Web3.py v7 (class-based middleware via wrap_make_request, provider HTTP request rework + new exception types).
  • Add/expand tests for simulate() block tag handling and _parse_signed_tx() across tx types.

Reviewed changes

Copilot reviewed 12 out of 14 changed files in this pull request and generated 7 comments.

Show a summary per file
File Description
tests/test_simulate.py Adds regression coverage for simulate() accepting an int block tag and producing hex tags.
tests/test_parse_signed_tx.py Adds coverage for _parse_signed_tx() across legacy, type-1, and type-2 transactions.
tests/test_flashbots_middleware.py Verifies the new v7-style middleware routes Flashbots RPC methods to the Flashbots provider.
README.md Updates developer workflow and commands for uv + ruff.
pyproject.toml Migrates to PEP 621 project metadata, hatchling build backend, and uv dependency groups.
flashbots/provider.py Reworks provider HTTP posting and error handling; adds request timeout and new exception usage.
flashbots/middleware.py Refactors middleware to a v7-compatible class-based middleware with wrap_make_request.
flashbots/flashbots.py Updates bundle signing/encoding paths for v7 naming and improves validation/errors; refines simulate/extrapolation logic.
flashbots/exceptions.py Introduces a domain-specific exception hierarchy.
flashbots/init.py Exposes new exceptions and defines explicit __all__.
examples/simple.py Updates example to use .raw_transaction.
CHANGELOG.md Adds v3.0.0 changelog describing breaking changes, additions, and fixes.
Suppressed comments (2)

flashbots/flashbots.py:346

  • signed_bundled_transactions may contain raw bytes, so calling .to_0x_hex() here can raise AttributeError. Use Web3.to_hex() to support both bytes and HexBytes.
                "txs": [tx.to_0x_hex() for tx in signed_bundled_transactions],

flashbots/flashbots.py:419

  • transaction["signed_transaction"] can be raw bytes, which don’t implement .to_0x_hex(). Use Web3.to_hex() to safely hex-encode both bytes and HexBytes.
        params = {
            "tx": signed_transaction.to_0x_hex(),
            "maxBlockNumber": max_block_number,

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread flashbots/provider.py
Comment on lines +99 to +104
data=request_data,
headers=self.get_request_headers()
| self._get_flashbots_headers(request_data),
timeout=self.request_timeout
)
response = self.decode_rpc_response(raw_response)
Comment thread flashbots/flashbots.py
return [
{
"txs": list(map(lambda x: self.to_hex(x), signed_bundled_transactions)),
"txs": [tx.to_0x_hex() for tx in signed_bundled_transactions],
Comment thread flashbots/middleware.py
Comment on lines +1 to 6
from typing import Any, Type

from web3 import Web3
from web3.middleware import Middleware
from web3.types import RPCEndpoint, RPCResponse

from .provider import FlashbotProvider
Comment thread flashbots/middleware.py
Comment on lines 21 to +23
def construct_flashbots_middleware(
flashbots_provider: FlashbotProvider,
) -> Middleware:
"""Captures Flashbots RPC requests and sends them to the Flashbots endpoint
while also injecting the required authorization headers

Keyword arguments:
flashbots_provider -- An HTTP provider instantiated with any authorization headers
required
) -> Type:
Comment thread pyproject.toml
Comment on lines +13 to +18
dependencies = [
"web3>=7.0.0",
"urllib3<2.0",
"websockets>=13.0.0,<14.0.0",
"eth-account>=0.13.7",
]
Comment thread pyproject.toml
readme = "README.md"
version = "2.0.0"
requires-python = ">=3.9"
license = "MIT"
Comment thread flashbots/flashbots.py
Comment on lines 408 to 412
signed_transaction = (
transaction["signer"]
.sign_transaction(transaction["transaction"])
.rawTransaction
.raw_transaction
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants