Skip to content

Autoprovider repo template #1736

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

Closed
kclowes opened this issue Sep 11, 2020 · 3 comments · Fixed by #2706
Closed

Autoprovider repo template #1736

kclowes opened this issue Sep 11, 2020 · 3 comments · Fixed by #2706

Comments

@kclowes
Copy link
Collaborator

kclowes commented Sep 11, 2020

What was wrong?

Currently, you can access an Infura provider in web3 using from web3.auto.infura import w3. This was good at the time because Infura was the only viable provider. However, a while back someone submitted a PR to add Nodesmith as an auto provider. After some internal discussion, we decided that we didn't want to be the gatekeeper for every new node provider, and decided that we would use Infura as an example to make a new template that people can follow to implement their own auto node providers.

How can it be fixed?

On a high level, pull out the logic for Infura's auto provider, put it in a new repo, and provide a web3 API for people to use their own auto provider package.

@wolovim
Copy link
Member

wolovim commented Sep 18, 2020

Documenting remote providers we've heard interest for:

  • infura
  • quiknode
  • nodesmith
  • alchemyapi

@dbfreem
Copy link
Contributor

dbfreem commented Apr 25, 2022

What would the expected api for this look like. Something like below?

from web3.auto.external import w3
from ..... import infura

w3.auto_provider = infura

@dbfreem
Copy link
Contributor

dbfreem commented Jun 19, 2022

I have been thinking about this some more. Ideally there could be an external library that could provide enough configuration to web3.py to create a w3 instance. This external library ideally would not be dependent on the web3.py library so they are not tightly coupled.

I was thinking of creating a new web3.auto.external module. This module would take in a configuration object and then return a w3 instance. A user could pass in an object from an external library and web3 would convert that into a w3 instance. Here is just a thought what that might look like, it is totally not fully implemented just thoughts.

web3.auto.external.py

def get_w3(external_auto):

    if external_auto.scheme == 'https':
        return HTTPProvider(endpoint_uri=external_auto.endpoint_uri, 
                     request_kwargs=external_auto.request_kwargs)
    elif external_auto.scheme == 'wss':
        return WebsocketProvider(endpoint_uri=external_auto.endpoint_uri, 
                          request_kwargs=external_auto.request_kwargs)

Then an external library could provide a class that looks something like this.


    @property
    def endpoint_uri(self):
        .....
    
    @property
    def request_kwargs(self):
        .....

    @property
    def scheme(self) -> str:
        ....

This Infura class would only need to worry about generating the request_kwargs, scheme, and endpoint_uri and would not be dependent on the web3.py library aka it would have web3.py in it's setup.py. It truly doesn't even need to be a class, it could be as simple as a dictionary with request_kwargs, scheme, and endpoint_uri as keys in it.

So the final product would look something like this

from web3.auto.external import get_w3
from ........ import Infura

w3 = get_w3(Infura())

I would love some feedback on this idea as I am sure there are other options here too.

Finally, if I can get this all up and running I was also, going to create a repo external to the ethereum org with some of the auto providers in it.

@kclowes thoughts??

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 a pull request may close this issue.

3 participants