I'm just studying about Ethereum, ENS and and and.. Actually I try to compute an ENS .eth Name to a hash. In https://app.ens.domains/name I baught a ENS .eth Name with the Ropsten Testnetwork. Now I have some things like registrant and controller (which is obviously my Ropsten ID).

So far so good. My aim is e.g. to ask in console what the hash of my .eth adress is and vice versa. I try to program this with the web3.py libary but I don't have any clue how to resolve this.

Could someone give me a hint


3 Answers 3


web3.py contains an ens module to simplify ENS lookups.

>>> from ens.auto import ns

>>> ns.address('jasoncarver.eth')

>>> from ens.auto import ns
>>> ns.name('0x5B2063246F2191f18F2675ceDB8b28102e957458')

See the web3.py ENS documentation for a more detailed explanation.

  • Hey, thanks for your advice. When I use ns.address('jasoncarver.eth') I get a error, I will show it up in buttom, Because in this Commentbox I just have about 500 chars. Dec 1, 2019 at 12:59

So when I use the command ns.address('jasoncarver.eth') I get the following error (with Python 3.6)

Traceback (most recent call last):
  File "/usr/local/lib/python3.6/dist-packages/web3/contract.py", line 1431, in call_contract_function
    output_data = web3.codec.decode_abi(output_types, return_data)
  File "/usr/local/lib/python3.6/dist-packages/eth_abi/codec.py", line 179, in decode_abi
    return decoder(stream)
  File "/usr/local/lib/python3.6/dist-packages/eth_abi/decoding.py", line 127, in __call__
    return self.decode(stream)
  File "/usr/local/lib/python3.6/dist-packages/eth_utils/functional.py", line 45, in inner
    return callback(fn(*args, **kwargs))
  File "/usr/local/lib/python3.6/dist-packages/eth_abi/decoding.py", line 173, in decode
    yield decoder(stream)
  File "/usr/local/lib/python3.6/dist-packages/eth_abi/decoding.py", line 127, in __call__
    return self.decode(stream)
  File "/usr/local/lib/python3.6/dist-packages/eth_abi/decoding.py", line 198, in decode
    raw_data = self.read_data_from_stream(stream)
  File "/usr/local/lib/python3.6/dist-packages/eth_abi/decoding.py", line 308, in read_data_from_stream
eth_abi.exceptions.InsufficientDataBytes: Tried to read 32 bytes.  Only got 0 bytes

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.6/dist-packages/ens/main.py", line 111, in address
    return cast(ChecksumAddress, self.resolve(name, 'addr'))
  File "/usr/local/lib/python3.6/dist-packages/ens/main.py", line 211, in resolve
    resolver = self.resolver(normal_name)
  File "/usr/local/lib/python3.6/dist-packages/ens/main.py", line 223, in resolver
    resolver_addr = self.ens.caller.resolver(normal_name_to_hash(normal_name))
  File "/usr/local/lib/python3.6/dist-packages/web3/contract.py", line 1373, in call_function
    return fn(*args, **kwargs).call(transaction, block_identifier)
  File "/usr/local/lib/python3.6/dist-packages/web3/contract.py", line 903, in call
  File "/usr/local/lib/python3.6/dist-packages/web3/contract.py", line 1453, in call_contract_function
    raise BadFunctionCallOutput(msg) from e
web3.exceptions.BadFunctionCallOutput: Could not transact with/call contract function, is contract deployed correctly and chain synced?

You prob fixed this already, but this works for me & could be useful for others, so I'm posting it anyway

#! /usr/bin/python3

from ens.auto import ns
from ens import ENS

# instantiate w3 instance
from web3 import Web3

w3 = Web3(Web3.HTTPProvider("https://eth-mainnet.g.alchemy.com/v2/*******"))
ns = ENS.from_web3(w3)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.