Skip to content
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

Document how to set up ENS for non-mainnet addresses #425

Open
carver opened this issue Nov 14, 2017 · 11 comments
Open

Document how to set up ENS for non-mainnet addresses #425

carver opened this issue Nov 14, 2017 · 11 comments

Comments

@carver
Copy link
Collaborator

carver commented Nov 14, 2017

What was wrong?

No documentation available on using ENS names on non-mainnet. From #342

How can it be fixed?

Write docs showing how to set up ENS for other networks.

Bonus: Get the chain ID from the client and infer the appropriate ENS registry address.

@carver carver added this to the Version 4 Stable milestone Nov 14, 2017
@carver carver removed this from the Version 4 Stable milestone Jan 23, 2018
@boxydog
Copy link

boxydog commented Dec 6, 2021

I am having this same problem.

Below is some code that works on mainnet but not rinkeby.

The documentation of how to set up geth is not sufficiently detailed to get it to work. The docs describe what I think is a local server, and I don't know how to run one.

#!/usr/bin/env python

from web3 import Web3
from web3.auto.infura import (
    INFURA_MAINNET_DOMAIN, build_http_headers, build_infura_url)
from web3.auto.infura.endpoints import INFURA_RINKEBY_DOMAIN
from web3.providers.auto import load_provider_from_uri

from ens import ENS
from eth_typing import ChecksumAddress

_headers = build_http_headers()

# NOTE: build_infura_url requires WEB3_INFURA_PROJECT_ID
# and WEB3_INFURA_API_SECRET environment variables set.
if True:
    # Works with mainnet
    _infura_url = build_infura_url(INFURA_MAINNET_DOMAIN)
else:
    # Doesn't work with Rinkeby
    #
    # "web3.exceptions.ExtraDataLengthError: The field extraData is 97 bytes,
    #  but should be 32. It is quite likely that you are connected to a POA chain.
    #  Refer to http://web3py.readthedocs.io/en/stable/middleware.html#geth-style-proof-of-authority
    #  for more details."
    _infura_url = build_infura_url(INFURA_RINKEBY_DOMAIN)

w3 = Web3(load_provider_from_uri(_infura_url, _headers))
ens = ENS.fromWeb3(w3)

the_ens = ens.name(
    ChecksumAddress('0x5B2063246F2191f18F2675ceDB8b28102e957458'))
print(the_ens)  # jasoncarver.eth

@fselmo
Copy link
Collaborator

fselmo commented Dec 6, 2021

Hey @boxydog. The docs could be a bit more clear for other cases but the important piece here is that if you are seeing the extradata error, injecting the geth_poa_middleware is the way to resolve it. See the second example in that link for how to import it and inject it into the middleware onion so that you do not see the error you are seeing with the extraData.

Please update here if that resolves it for you or if you run into any other issues.

@boxydog
Copy link

boxydog commented Dec 6, 2021

I appreciate your response. I have been unable to get this to work.

If I look at https://web3py.readthedocs.io/en/stable/middleware.html#geth-style-proof-of-authority, it says:

from web3.middleware import geth_poa_middleware
w3.middleware_onion.inject(geth_poa_middleware, layer=0)

If I add those two lines after w3 = .. in my code above, it has no impact (same error).

The doc I linked additionally has:

# connect to the IPC location started with 'geth --dev --datadir ~/mynode'

But I don't want to run a geth node.

So, I am still stuck.

@boxydog
Copy link

boxydog commented Dec 6, 2021

This issue hints that there may be an ENS registry somewhere for Rinkeby, but I don't know what that means or how to configure it.

I am saying that a complete and working example documented somewhere would really help, instead of just fragments.

@boxydog
Copy link

boxydog commented Dec 6, 2021

Additionally, if I try

from web3.auto.gethdev import w3
print(w3.clientVersion)

I just get an error.

FileNotFoundError: cannot connect to IPC socket at path: None

Pretty sure it's expecting something running and configured. We want to run our web3.py on Heroku, it's not clear to me how to even run a geth server at all, let alone on Heroku.

cc @fselmo

@boxydog
Copy link

boxydog commented Dec 6, 2021

Can ENS lookups even differ between mainnet and rinkeby? Perhaps I should be doing ENS lookups on mainnet even when our app is using rinkeby for everything else.

@fselmo
Copy link
Collaborator

fselmo commented Dec 6, 2021

Hey @boxydog thanks for the updates. It looks like ENS.fromWeb3() injects another middleware so the geth_poa_middlewre needs to be injected after that line as well like this:

ens = ENS.fromWeb3(w3)
ens.web3.middleware_onion.inject(geth_poa_middleware, layer=0)

the_ens = ens.name(
    ChecksumAddress('0x5B206324...')
)

This should get you unstuck for now but we can definitely use a documentation improvement around some of this. I will take this into account when we update the docs.

Thanks again.

@boxydog
Copy link

boxydog commented Dec 6, 2021

Thanks very much for your response. I still get the same error.

Here is all the code (that still throws the error) after the if just to double-check:

w3 = Web3(load_provider_from_uri(_infura_url, _headers))

ens = ENS.fromWeb3(w3)

from web3.middleware import geth_poa_middleware
w3.middleware_onion.inject(geth_poa_middleware, layer=0)

the_ens = ens.name(
    ChecksumAddress('0x5B2063246F2191f18F2675ceDB8b28102e957458'))
print(the_ens)  # error

@boxydog
Copy link

boxydog commented Dec 6, 2021

Also, here is my version:

$ python -c "import web3; print(web3.__version__)"
5.25.0

@fselmo
Copy link
Collaborator

fselmo commented Dec 6, 2021

@boxydog yes please copy exactly what I wrote. You need ens.web3.middleware_onion.inject(....) (or, alternatively, inject the middleware into w3 before instantiating ENS.from_web3(w3)).

@boxydog
Copy link

boxydog commented Dec 6, 2021

My apologies, I didn't see that difference.

Yes, now it doesn't throw an error. It returns None, but that may well be correct. Perhaps that address is not mapped in Rinkeby ENS space, whatever that means. :)

Thanks for your help!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants