Skip to content

Commit 4d452b9

Browse files
committed
Updates to ENS documentation
1 parent 1ce4000 commit 4d452b9

File tree

1 file changed

+100
-64
lines changed

1 file changed

+100
-64
lines changed

docs/ens_overview.rst

Lines changed: 100 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
.. _ens_overview:
22

33
Ethereum Name Service
4-
================================
4+
=====================
55

66
The Ethereum Name Service is analogous to the Domain Name Service. It
77
enables users and developers to use human-friendly names in place of error-prone
@@ -19,138 +19,121 @@ Create an :class:`~ens.main.ENS` object (named ``ns`` below) in one of three way
1919
2. Specify an instance or list of :ref:`providers`
2020
3. From an existing :class:`web3.Web3` object
2121

22-
::
22+
.. code-block:: python
2323
2424
# automatic detection
2525
from ens.auto import ns
2626
27-
2827
# or, with a provider
2928
from web3 import IPCProvider
3029
from ens import ENS
3130
3231
provider = IPCProvider(...)
3332
ns = ENS(provider)
3433
35-
3634
# or, with a w3 instance
3735
# Note: This inherits the w3 middlewares from the w3 instance and adds a stalecheck middleware to the middleware onion
3836
from ens import ENS
39-
4037
w3 = Web3(...)
4138
ns = ENS.fromWeb3(w3)
4239
4340
4441
Usage
4542
-----
4643

47-
Name info
44+
Name Info
4845
~~~~~~~~~
4946

5047
.. _ens_get_address:
5148

52-
Look up the address for an ENS name
53-
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
49+
Get the Address for an ENS Name
50+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
5451

55-
::
52+
.. code-block:: python
5653
5754
from ens.auto import ns
58-
59-
60-
# look up the hex representation of the address for a name
61-
6255
eth_address = ns.address('jasoncarver.eth')
63-
6456
assert eth_address == '0x5B2063246F2191f18F2675ceDB8b28102e957458'
6557
66-
6758
The ``ENS`` module has no opinion as to which TLD you can use,
6859
but will not infer a TLD if it is not provided with the name.
6960

7061

71-
Get name from address
72-
^^^^^^^^^^^^^^^^^^^^^
62+
Get the Name for an ENS Address
63+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
7364

74-
::
65+
.. code-block:: python
7566
7667
domain = ns.name('0x5B2063246F2191f18F2675ceDB8b28102e957458')
7768
78-
7969
# name() also accepts the bytes version of the address
80-
8170
assert ns.name(b'[ c$o!\x91\xf1\x8f&u\xce\xdb\x8b(\x10.\x95tX') == domain
8271
83-
8472
# confirm that the name resolves back to the address that you looked up:
85-
8673
assert ns.address(domain) == '0x5B2063246F2191f18F2675ceDB8b28102e957458'
8774
88-
Get owner of name
89-
^^^^^^^^^^^^^^^^^
75+
.. note:: The ``ENS`` module verifies the forward resolution matches the address when retrieving a ``name()`` for an
76+
address as this is the only sure way to know whether the reverse resolution is correct. Anyone can claim
77+
any name, only forward resolution implies that the owner of the name gave their stamp of approval.
78+
79+
Get the Owner of a Name
80+
^^^^^^^^^^^^^^^^^^^^^^^
9081

91-
::
82+
.. code-block:: python
9283
9384
eth_address = ns.owner('exchange.eth')
9485
95-
Set up your name
96-
~~~~~~~~~~~~~~~~
9786
98-
Point your name to your address
99-
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
87+
Set Up Your Name and Address
88+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
10089

101-
Do you want to set up your name so that :meth:`~ens.main.ENS.address` will show the
102-
address it points to?
90+
Link a Name to an Address
91+
^^^^^^^^^^^^^^^^^^^^^^^^^
10392

104-
::
93+
You can set up your name so that :meth:`~ens.main.ENS.address` will show the address it points to. In order to do so,
94+
you must already be the owner of the domain (or its parent).
10595

106-
ns.setup_address('jasoncarver.eth', '0x5B2063246F2191f18F2675ceDB8b28102e957458')
96+
.. code-block:: python
10797
108-
You must already be the owner of the domain (or its parent).
98+
ns.setup_address('jasoncarver.eth', '0x5B2063246F2191f18F2675ceDB8b28102e957458')
10999
110-
In the common case where you want to point the name to the owning
111-
address, you can skip the address
100+
In the common case where you want to point the name to the owning address, you can skip the address.
112101

113-
::
102+
.. code-block:: python
114103
115104
ns.setup_address('jasoncarver.eth')
116105
117-
You can claim arbitrarily deep subdomains. *Gas costs scale up with the
118-
number of subdomains!*
106+
You can claim arbitrarily deep subdomains.
119107

120-
::
108+
.. code-block:: python
121109
122110
ns.setup_address('supreme.executive.power.derives.from.a.mandate.from.the.masses.jasoncarver.eth')
123111
124-
Wait for the transaction to be mined, then:
112+
# wait for the transaction to be mined, then:
113+
assert (
114+
ns.address('supreme.executive.power.derives.from.a.mandate.from.the.masses.jasoncarver.eth')
115+
== '0x5B2063246F2191f18F2675ceDB8b28102e957458'
116+
)
125117
126-
::
118+
.. warning:: Gas costs scale up with the number of subdomains!
127119

128-
assert ns.address('supreme.executive.power.derives.from.a.mandate.from.the.masses.jasoncarver.eth') == \
129-
'0x5B2063246F2191f18F2675ceDB8b28102e957458'
130120

131-
Allow people to find your name using your address
132-
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
121+
Link an Address to a Name
122+
^^^^^^^^^^^^^^^^^^^^^^^^^
133123

134-
Do you want to set up your address so that :meth:`~ens.main.ENS.name` will show the
135-
name that points to it?
124+
You can set up your address so that :meth:`~ens.main.ENS.name` will show the name that points to it.
136125

137-
This is like Caller ID. It enables you and others to take an account and
138-
determine what name points to it. Sometimes this is referred to as
139-
"reverse" resolution.
126+
This is like Caller ID. It enables you and others to take an account and determine what name points to it. Sometimes
127+
this is referred to as "reverse" resolution since it uses the ENS Reverse Resolver for this functionality.
140128

141-
::
129+
.. code-block:: python
142130
143131
ns.setup_name('jasoncarver.eth', '0x5B2063246F2191f18F2675ceDB8b28102e957458')
144132
145-
.. note:: Do not rely on reverse resolution for security.
146-
147-
Anyone can claim any "caller ID". Only forward resolution implies that
148-
the owner of the name gave their stamp of approval.
149-
150133
If you don't supply the address, :meth:`~ens.main.ENS.setup_name` will assume you want the
151134
address returned by :meth:`~ens.main.ENS.address`.
152135

153-
::
136+
.. code-block:: python
154137
155138
ns.setup_name('jasoncarver.eth')
156139
@@ -159,26 +142,30 @@ call :meth:`~ens.main.ENS.setup_address` for you.
159142

160143
Wait for the transaction to be mined, then:
161144

162-
::
145+
.. code-block:: python
163146
164147
assert ns.name('0x5B2063246F2191f18F2675ceDB8b28102e957458') == 'jasoncarver.eth'
165148
149+
150+
Text Records
151+
~~~~~~~~~~~~
152+
166153
Set Text Metadata for an ENS Record
167-
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
154+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
168155

169156
As the owner of an ENS record, you can add text metadata.
170157
A list of supported fields can be found in the
171158
`ENS documentation <https://docs.ens.domains/contract-api-reference/publicresolver#get-text-data>`_.
172159
You'll need to setup the address first, and then the text can be set:
173160

174-
::
161+
.. code-block:: python
175162
176163
ns.setup_address('jasoncarver.eth', 0x5B2063246F2191f18F2675ceDB8b28102e957458)
177164
ns.set_text('jasoncarver.eth', 'url', 'https://example.com')
178165
179166
A transaction dictionary can be passed as the last argument if desired:
180167

181-
::
168+
.. code-block:: python
182169
183170
transaction_dict = {'from': '0x123...'}
184171
ns.set_text('jasoncarver.eth', 'url', 'https://example.com', transaction_dict)
@@ -187,12 +174,61 @@ If the transaction dictionary is not passed, sensible defaults will be used, and
187174
a transaction dictionary is passed but does not have a ``from`` value,
188175
the default will be the ``owner``.
189176

177+
190178
Read Text Metadata for an ENS Record
191-
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
179+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
192180

193181
Anyone can read the data from an ENS Record:
194182

195-
::
183+
.. code-block:: python
196184
197185
url = ns.get_text('jasoncarver.eth', 'url')
198186
assert url == 'https://example.com'
187+
188+
189+
Working With Resolvers
190+
~~~~~~~~~~~~~~~~~~~~~~
191+
192+
Get the Resolver for an ENS Record
193+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
194+
195+
You can get the resolver for an ENS name via the :meth:`~ens.main.ENS.resolver` method.
196+
197+
.. code-block:: python
198+
199+
>>> resolver = ns.resolver('jasoncarver.eth')
200+
>>> resolver.address
201+
'0x5FfC014343cd971B7eb70732021E26C35B744cc4'
202+
203+
204+
Wildcard Resolution Support
205+
---------------------------
206+
207+
The ``ENS`` module supports Wildcard Resolution for resolvers that implement the ``ExtendedResolver`` interface
208+
as described in `ENSIP-10 <https://docs.ens.domains/ens-improvement-proposals/ensip-10-wildcard-resolution>`_.
209+
Resolvers that implement the extended resolver interface should return ``True`` when calling the
210+
``supportsInterface()`` function with the extended resolver interface id ``0x9061b923`` and should resolve subdomains
211+
to a unique address.
212+
213+
A working example of a resolver that supports wildcard resolution is the resolver for the ``hatch.eth`` record on the
214+
Ropsten testnet.
215+
216+
.. code-block:: python
217+
218+
# connect to the Ropsten testnet
219+
>>> w3 = Web3(WebsocketProvider("wss://{ropsten_provider}"))
220+
>>> ns = ENS.fromWeb3(w3)
221+
222+
# get the resolver for `hatch.eth`
223+
>>> resolver = ns.resolver('hatch.eth')
224+
>>> resolver.address
225+
'0x8fc4C380c5d539aE631daF3Ca9182b40FB21D1ae'
226+
227+
# verify extended resolver interface support
228+
>>> resolver.caller.supportsInterface('0x9061b923')
229+
True
230+
231+
>>> ns.address('random-subdomain.hatch.eth')
232+
'0x49D4c4ff230688e4A357bc057e7E35e64d271939'
233+
>>> ns.address('another-random-subdomain.hatch.eth')
234+
'0xb35359B6450B0CbC9BE15A4eE6bcb8c5b0d9fC4A'

0 commit comments

Comments
 (0)