Skip to content

Conversation

@g7AzaZLO
Copy link

@g7AzaZLO g7AzaZLO commented Dec 9, 2025

  • Introduced AsyncAutoProvider for automatic detection of asynchronous providers.
  • Implemented load_async_provider_from_environment and load_async_provider_from_uri functions.
  • Updated existing provider loading functions to raise Web3ValidationError for WebSocket URIs in sync context.
  • Enhanced tests for async provider loading and validation.
  • Updated documentation for new async provider features.

What was wrong?

Related to Issue #3704

The AutoProvider lacked async support, which led to a "coroutine" bug when WebSocketProvider (which is async-only) was picked up by the default synchronous AutoProvider. This resulted in an obscure AttributeError: 'coroutine' object has no attribute 'get' when the manager attempted to process the connection check.

Additionally, there was no equivalent automatic provider detection for AsyncWeb3 users, making it harder to configure async instances via environment variables.

How was it fixed?

  1. AsyncAutoProvider Implementation:

    • Added AsyncAutoProvider class that inherits from AsyncJSONBaseProvider.
    • It automatically detects and connects to available async providers (AsyncHTTP, WebSocket, AsyncIPC).
  2. Environment Loading:

    • Added load_async_provider_from_environment and load_async_provider_from_uri.
    • Support for WEB3_PROVIDER_URI and WEB3_WS_PROVIDER_URI for async contexts.
  3. Validation & Error Handling:

    • Updated AutoProvider (sync) to explicitly check if a discovered provider is async. If so, it raises a Web3ValidationError with instructions to use AsyncAutoProvider.
    • Updated load_provider_from_uri to raise Web3ValidationError immediately if a ws:// or wss:// URI is passed to the synchronous loader.
  4. Documentation & Tests:

    • Added comprehensive tests for the new async loading logic and validations.
    • Updated docs/providers.rst to include AsyncAutoProvider usage examples.

Todo:

  • Clean up commit history
  • Add or update documentation related to these changes
  • Add entry to the release notes

- Introduced AsyncAutoProvider for automatic detection of asynchronous providers.
- Implemented load_async_provider_from_environment and load_async_provider_from_uri functions.
- Updated existing provider loading functions to raise Web3ValidationError for WebSocket URIs.
- Enhanced tests for async provider loading and validation.
- Updated documentation for new async provider features.
@g7AzaZLO g7AzaZLO force-pushed the feature/async-auto-provider branch from 9db87a8 to b5f4878 Compare December 10, 2025 15:17
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.

1 participant