Skip to content

Remove auto provider except for local geth dev #2706

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 21, 2022
Merged
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
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ output/*/index.html
# Sphinx
docs/_build
docs/modules.rst
docs/web3.auto.infura.rst
docs/web3.auto.rst
docs/web3.gas_strategies.rst
docs/web3.middleware.rst
Expand Down
1 change: 0 additions & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@
"web3.rst",
"modules.rst",
"web3.auto.rst",
"web3.auto.infura.rst",
"web3.gas_strategies.rst",
"web3.middleware.rst",
"web3.providers.rst",
Expand Down
3 changes: 2 additions & 1 deletion docs/contributing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,8 @@ virtualenv for smoke testing:
# smoke test the release
$ pip install ipython
$ ipython
>>> from web3.auto import w3
>>> from web3 import Web3, IPCProvider
>>> w3 = Web3(IPCProvider(provider_url))
>>> w3.is_connected()
>>> ...

Expand Down
7 changes: 3 additions & 4 deletions docs/examples.rst
Original file line number Diff line number Diff line change
Expand Up @@ -422,10 +422,10 @@ it as a ``Package`` instance.

.. code-block:: python3

from web3.auto.infura import w3

# Note. To use the web3.pm module, you will need to instantiate your w3 instance
# with a web3 provider connected to the chain on which your registry lives.
from web3 import Web3, IPCProvider
w3 = Web3(IPCProvider(...))

# The ethPM module is still experimental and subject to change,
# so for now we need to enable it via a temporary flag.
Expand Down Expand Up @@ -471,8 +471,7 @@ within an ethPM package.
# connected to your provider of choice. Now your factories will automatically
# deploy to this new chain, and the deployments available on a package will
# be automatically filtered to those located on the new chain.
from web3.auto.infura.goerli import w3 as goerli_w3
goerli_registrar = ens_package.update_w3(goerli_w3)
goerli_registrar = ens_package.update_w3(goerli_w3_instance)


Working with an ERC20 Token Contract
Expand Down
26 changes: 14 additions & 12 deletions docs/filters.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,21 @@ Filtering

.. note ::

Most one-liners below assume ``w3`` to be a :class:`web3.Web3` instance;
obtainable, for example, with:

.. code-block:: python

from web3.auto import w3
Most one-liners below assume ``w3`` to be a :class:`web3.Web3` instance.

The :meth:`web3.eth.Eth.filter` method can be used to set up filters for:

* Pending Transactions: ``web3.eth.filter('pending')``
* Pending Transactions: ``w3.eth.filter("pending")``

* New Blocks ``web3.eth.filter('latest')``
* New Blocks ``w3.eth.filter("latest")``

* Event Logs

Through the contract instance api:

.. code-block:: python

event_filter = mycontract.events.myEvent.create_filter(fromBlock='latest', argument_filters={'arg1':10})
event_filter = mycontract.events.myEvent.create_filter(fromBlock="latest", argument_filters={"arg1":10})

Or built manually by supplying `valid filter params <https://github.com/ethereum/execution-apis/blob/bea0266c42919a2fb3ee524fb91e624a23bc17c5/src/schemas/filter.json#L28>`_:

Expand Down Expand Up @@ -203,9 +198,12 @@ Synchronous

.. code-block:: python

from web3.auto import w3
from web3 import Web3, IPCProvider
import time

# instantiate Web3 instance
w3 = Web3(IPCProvider(...))

def handle_event(event):
print(event)

Expand Down Expand Up @@ -242,9 +240,11 @@ entries to a handler.

.. code-block:: python

from web3.auto import w3
from web3 import Web3, IPCProvider
import asyncio

# instantiate Web3 instance
w3 = Web3(IPCProvider(...))

def handle_event(event):
print(event)
Expand Down Expand Up @@ -281,10 +281,12 @@ releasing the ``main`` function for other tasks.

.. code-block:: python

from web3.auto import w3
from web3 import Web3, IPCProvider
from threading import Thread
import time

# instantiate Web3 instance
w3 = Web3(IPCProvider(...))

def handle_event(event):
print(event)
Expand Down
107 changes: 0 additions & 107 deletions docs/providers.rst
Original file line number Diff line number Diff line change
Expand Up @@ -65,86 +65,6 @@ Then you are ready to initialize your Web3 instance, like so:

Finally, you are ready to :ref:`get started with Web3.py<first_w3_use>`.

.. _automatic_provider:

Automatic vs Manual Providers
-----------------------------

The ``Web3`` object will look for the Ethereum node in a few
standard locations if no providers are specified. Auto-detection happens
when you initialize like so:

.. code-block:: python

from web3.auto import w3

# which is equivalent to:

from web3 import Web3
w3 = Web3()

Sometimes, web3 cannot automatically detect where your node is.

- If you are not sure which kind of connection method to use, see
:ref:`choosing_provider`.
- If you know the connection method, but not the other information
needed to connect (like the path to the IPC file), you will need to look up
that information in your node's configuration.
- If you're not sure which node you are using, see :ref:`choosing_node`

For a deeper dive into how automated detection works, see:

.. _automatic_provider_detection:

How Automated Detection Works
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Web3 attempts to connect to nodes in the following order, using the first
successful connection it can make:

1. The connection specified by an environment variable, see :ref:`provider_uri`
2. :class:`~web3.providers.ipc.IPCProvider`, which looks for several IPC file locations.
``IPCProvider`` will not automatically detect a testnet connection, it is suggested that the
user instead uses a ``w3`` instance from ``web3.auto.infura`` (e.g.
``from web3.auto.infura.goerli import w3``) if they want to auto-detect a testnet.
3. :class:`~web3.providers.rpc.HTTPProvider`, which attempts to connect to "http://localhost:8545"
4. ``None`` - if no providers are successful, you can still use Web3 APIs
that do not require a connection, like:

- :ref:`overview_type_conversions`
- :ref:`overview_currency_conversions`
- :ref:`overview_addresses`
- :ref:`eth-account`
- etc.

.. _automatic_provider_detection_examples:

Examples Using Automated Detection
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Some nodes provide APIs beyond the standards. Sometimes the same information is provided
in different ways across nodes. If you want to write code that works
across multiple nodes, you may want to look up the node type you are connected to.

For example, the following retrieves the client enode endpoint for both geth and parity:

.. code-block:: python

from web3.auto import w3

connected = w3.is_connected()

if connected and w3.client_version.startswith('Parity'):
enode = w3.parity.enode

elif connected and w3.client_version.startswith('Geth'):
enode = w3.geth.admin.node_info['enode']

else:
enode = None

.. _provider_uri:

Provider via Environment Variable
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Expand All @@ -159,36 +79,9 @@ Valid formats for this environment variable are:
- ``ws://127.0.0.1:8546``


.. _custom_auto_providers:

Auto-initialization Provider Shortcuts
--------------------------------------

There are a couple auto-initialization shortcuts for common providers.

Infura Mainnet
~~~~~~~~~~~~~~

To easily connect to the Infura Mainnet remote node, first register for a free
project ID if you don't have one at https://infura.io/register .

Then set the environment variable ``WEB3_INFURA_PROJECT_ID`` with your Project ID::

$ export WEB3_INFURA_PROJECT_ID=YourProjectID

If you have checked the box in the Infura UI indicating that requests need
an optional secret key, set the environment variable ``WEB3_INFURA_API_SECRET``::

$ export WEB3_INFURA_API_SECRET=YourProjectSecret

.. code-block:: python

>>> from web3.auto.infura import w3

# confirm that the connection succeeded
>>> w3.is_connected()
True

Geth dev Proof of Authority
~~~~~~~~~~~~~~~~~~~~~~~~~~~

Expand Down
10 changes: 0 additions & 10 deletions docs/quickstart.rst
Original file line number Diff line number Diff line change
Expand Up @@ -76,16 +76,6 @@ to this local node can be done as follows:
>>> w3.is_connected()
True

If you stick to the default ports or IPC file locations, you can utilize a
:ref:`convenience method <automatic_provider>` to automatically detect the provider
and save a few keystrokes:

.. code-block:: python

>>> from web3.auto import w3
>>> w3.is_connected()
True


Remote Providers
****************
Expand Down
2 changes: 1 addition & 1 deletion docs/releases.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2272,7 +2272,7 @@ Released June 29, 2018

- :class:`~web3.providers.ipc.IPCProvider` now accepts a :class:`pathlib.Path`
argument for the IPC path
- Docs explaining the :ref:`new custom autoproviders in web3 <custom_auto_providers>`
- Docs explaining the new custom autoproviders in web3

v4.4.0
--------
Expand Down
3 changes: 1 addition & 2 deletions docs/v5_migration.rst
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,7 @@ Testnet Changes
~~~~~~~~~~~~~~~

Web3.py will no longer automatically look up a testnet connection
in IPCProvider. Something like ``from web3.auto.infura.ropsten import w3``
should be used instead.
in IPCProvider.

ENS
---
Expand Down
10 changes: 7 additions & 3 deletions docs/web3.eth.account.rst
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,11 @@ Example ``account_test_script.py``
import os
from eth_account import Account
from eth_account.signers.local import LocalAccount
from web3.auto import w3
from web3 import Web3, EthereumTesterProvider
from web3.middleware import construct_sign_and_send_raw_middleware

w3 = Web3(EthereumTesterProvider())

private_key = os.environ.get("PRIVATE_KEY")
assert private_key is not None, "You must set PRIVATE_KEY environment variable"
assert private_key.startswith("0x"), "Private key must start with 0x hex prefix"
Expand Down Expand Up @@ -143,9 +145,10 @@ is provided by :meth:`w3.eth.sign() <web3.eth.Eth.sign>`.

.. doctest::

>>> from web3.auto import w3
>>> from web3 import Web3, EthereumTesterProvider
>>> from eth_account.messages import encode_defunct

>>> w3 = Web3(EthereumTesterProvider())
>>> msg = "I♥SF"
>>> private_key = b"\xb2\\}\xb3\x1f\xee\xd9\x12''\xbf\t9\xdcv\x9a\x96VK-\xe4\xc4rm\x03[6\xec\xf1\xe5\xb3d"
>>> message = encode_defunct(text=msg)
Expand Down Expand Up @@ -334,7 +337,8 @@ To sign a transaction locally that will invoke a smart contract:
# When running locally, execute the statements found in the file linked below to load the EIP20_ABI variable.
# See: https://github.com/carver/ethtoken.py/blob/v0.0.1-alpha.4/ethtoken/abi.py

>>> from web3.auto import w3
>>> from web3 import Web3, EthereumTesterProvider
>>> w3 = Web3(EthereumTesterProvider())

>>> unicorns = w3.eth.contract(address="0xfB6916095ca1df60bB79Ce92cE3Ea74c37c5d359", abi=EIP20_ABI)

Expand Down
3 changes: 2 additions & 1 deletion docs/web3.pm.rst
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ The ``web3.pm`` object exposes methods to interact with Packages as defined by `

.. code-block:: python

>>> from web3.auto import w3
>>> from web3 import Web3, IPCProvider
>>> w3 = Web3(IPCProvider(...))
>>> w3.pm
...
AttributeError: The Package Management feature is disabled by default ...
Expand Down
8 changes: 6 additions & 2 deletions ethpm/backends/registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@ class RegistryURIBackend(BaseURIBackend):
"""

def __init__(self) -> None:
from web3.auto.infura import w3
from web3 import Web3, WebsocketProvider

w3 = Web3(WebsocketProvider())

self.w3 = w3

Expand Down Expand Up @@ -88,7 +90,9 @@ def parse_registry_uri(uri: str) -> RegistryURI:
Validate and return (authority, chain_id, pkg_name, version)
from a valid registry URI.
"""
from web3.auto.infura import w3
from web3 import Web3, WebsocketProvider

w3 = Web3(WebsocketProvider())

validate_registry_uri(uri)
parsed_uri = parse.urlparse(uri)
Expand Down
1 change: 1 addition & 0 deletions newsfragments/2706.removal.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Removal of Infura auto provider support.
Loading