v3.0.0: Web3.py v7 support, uv migration, code quality improvements - #104
Open
kais92 wants to merge 12 commits into
Open
v3.0.0: Web3.py v7 support, uv migration, code quality improvements#104kais92 wants to merge 12 commits into
kais92 wants to merge 12 commits into
Conversation
oppastoppa31
approved these changes
Nov 22, 2025
Contributor
|
Pushed latest updates to this branch: added simulation test coverage and refreshed dependency/lockfile updates. |
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>
- 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>
There was a problem hiding this comment.
Pull request overview
This PR delivers the v3.0.0 release work to support Web3.py v7, including breaking API renames (rawTransaction → raw_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_transactionsmay contain rawbytes, so calling.to_0x_hex()here can raiseAttributeError. UseWeb3.to_hex()to support bothbytesandHexBytes.
"txs": [tx.to_0x_hex() for tx in signed_bundled_transactions],
flashbots/flashbots.py:419
transaction["signed_transaction"]can be rawbytes, which don’t implement.to_0x_hex(). UseWeb3.to_hex()to safely hex-encode bothbytesandHexBytes.
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 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) |
| 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 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 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 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", | ||
| ] |
| readme = "README.md" | ||
| version = "2.0.0" | ||
| requires-python = ">=3.9" | ||
| license = "MIT" |
Comment on lines
408
to
412
| signed_transaction = ( | ||
| transaction["signer"] | ||
| .sign_transaction(transaction["transaction"]) | ||
| .rawTransaction | ||
| .raw_transaction | ||
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Breaking Changes
.rawTransactionproperties to.raw_transaction(Web3.py v7 naming).wrap_make_request.FlashbotProvider:requests.post.eth_account._utils.Added
get_transaction_type()to detect legacy, access list, and EIP-1559 tx types._parse_signed_txfor legacy, EIP-2930 (type=1), and EIP-1559 (type=2) transactions.Fixed
int.chainIdfor legacy transactions signed under EIP-155.examples/simple.py) to use.raw_transactionand new middleware/provider APIs.