Ethereum Name Service 백서

Ethereum Name Service

원문

bitpro가 원문에서 글자만 모은 내용이에요. 표·그림·수식은 빠지거나 깨질 수 있어요. 전체 75쪽 중 7쪽

nt.getEnsName({ address: '0xb8c2C29ee19D8307cb7255e1Cd9CbDE883A267d5', }) ``` ```py [Web3.py] # https://web3py.readthedocs.io/en/latest/ens_overview.html#get-the-ens-name-for-an-address from ens.auto import ns name = ns.name('0xb8c2C29ee19D8307cb7255e1Cd9CbDE883A267d5') ``` ::: As of September 2025, Wagmi and Viem are the only libraries that support L2 Primary Names, and they can be used like this: ```tsx [Wagmi] // https://wagmi.sh/react/hooks/useEnsName import { toCoinType } from 'viem' import { useEnsName } from 'wagmi' import { base, mainnet } from 'wagmi/chains' export const Name = () => { const { data: name } = useEnsName({ address: '0xb8c2C29ee19D8307cb7255e1Cd9CbDE883A267d5', chainId: mainnet.id, // resolution always starts from L1 coinType: toCoinType(base.id), // [!code ++] }) return <div>Name: {name}</div> } ``` :::info The official implementation of L2 Primary Names has a propogation period of up to 6 hours. If you're participating in a hackathon and need to resolve a name immediately, you can use [this implementation](https://github.com/ensdomains/frontend-template/blob/main/src/hooks/useEnsNameOptimistic.tsx) instead (not recommended for production use). ::: 🎉 And that's it! Now you can turn all your pages from this, to this: <Card className="flex flex-col items-center gap-2"> <div className="flex items-center gap-2"> <Badge>0xb8c2...67d5</Badge> <span>sent 0.1 ETH to</span> <Badge>0xd8dA....6045</Badge> </div> <span className="text-grey text-sm">turns into</span> <div className="flex items-center gap-2"> <Badge>nick.eth</Badge> <span>sent 0.1 ETH to</span> <Badge>vitalik.eth</Badge> </div> </Card> :::info If you're a library developer looking to implement this functionality, we recommend using the [Universal Resolver](/resolvers/universal). It's a utility contract that greatly simplifies the process of resolving a name. ::: ### Setting Primary Names Since primary names require two-way resolution, there are technically two steps to setting it up. Let's say that user `0x1234...5678` wants to set their primary name on Base to `nick.eth`. First, the user would need to set the Base address for `nick.eth` to `0x1234...5678`. [Read more about multichain addresses](/web/resolution#multi-chain-addresses-btc-ltc-etc) to understand how this works. Next, the user would need to set the reverse record for `0x1234...5678` to `nick.eth` in the Base Reverse Registrar. [Read more about reverse records](/registry/reverse) to understand how this works. In order to avoid doing this manually for multiple chains, the user can set their default reverse record to `nick.eth` on the default reverse registrar, and their default EVM address to `0x1234...5678` on the latest [public resolver](/resolvers/public). <EmbedLink href="/registry/reverse" title="Reverse Registrars" description="Learn more about the smart contracts that manage reverse records on L1 and L2s." /> import { Card } from '../../components/ui/Card' ## Sign In With Ethereum (SIWE) \[A specification that leverages Ethereum signatures to perform authentication] [ERC-4361](https://eips.ethereum.org/EIPS/eip-4361) defines a message format that a user signs using their keys to authenticate. An example payload looks like the following: ``` localhost wants you to sign in with your Ethereum account: 0x225f137127d9067788314bc7fcc1f36746a3c3B5 This is a test statement. URI: https://localhost/login Version: 1 Chain ID: 1 Nonce: abcdef1234567890 Issued At: 2023-01-30T00:00:00.000Z ``` After authentication, an app may resolve the user's ENS name and profile, as well as other [onchain resources](https://docs.siwe.xyz/quickstart/retrieve-onchain-data). ### Resources * [ERC-4361](https://eips.ethereum.org/EIPS/eip-4361) * [Project website](https://siwe.xyz/) * [Docs](https://docs.siwe.xyz/) * [Libraries](https://docs.siwe.xyz/libraries/) import { EmbedLink } from '../../components/EmbedLink' import { Card } from '../../components/ui/Card' ## Subdomains We believe that any place an address is used, a name should be able to be used instead. The smart contracts you interact with have names, the deposit address for your favorite exchange has a name, your favorite DAO has a name, or maybe you use subnames to keep your wallets organized. <Card className="flex items-center justify-center text-xl"> <div className="text-right font-bold"> {['root', 'registrar', 'controller', 'resolver', 'registry'].map( (subname, i) => ( <div className={ ['opacity-20', 'opacity-50', '', 'opacity-50', 'opacity-20'][i] } key={subname} > {subname} </div> ) )} </div> <div className="text-blue font-bold">.ens.eth</div> </Card> Luckily, the ENS Protocol has so much to offer for you to play with. There are a variety of ways you can give out subdomains to your apps users, set them up for yourself, or more. If you are interested in naming smart contracts specifically, check out the [Naming Smart Contracts](/web/naming-contracts) page. ### Different Types of Subnames ENS subnames come in a variety of forms: L1, L2, and offchain. From a technical perspective, L2 and offchain subnames are quite similar, but there are some tradeoffs to consider when choosing which one to use. #### L1 Subnames If you own a .eth name like nick.eth and go to create a subname in [the manager app](https://app.ens.domains/nick.eth?tab=subnames), you will be creating a subname on Ethereum Mainnet (L1) by default. This is the simplest way to create a subname with the least amount of moving pieces, but ultimately you are limited by the gas fees of Ethereum Mainnet. If you'd like to issue L1 subnames to your users, read our guide on [creating an onchain subname registrar](/wrapper/creating-subname-registrar). <EmbedLink title="Creating an Onchain Subname Registrar" href="/wrapper/creating-subname-registrar" description="Issue NFTs that represent subdomains on Ethereum Mainnet." /> #### L2 Subnames Developers can connect an ENS name on L1 with their own smart contracts on any L2 network, and [depending on the implementation](/learn/ccip-read), this could be fully trustless while significantly reducing the cost of issuing subnames. [Durin](https://durin.dev/) is an opinionated approach to issuing ENS subnames on L2. It takes care of the L1 Resolver and offchain gateway parts of the [CCIP Read stack](/resolvers/ccip-read) for you, so you can focus on the business logic of your L2 smart contracts. <EmbedLink title="Durin" href="https://durin.dev/" description="An opinionated approach to issuing ENS subnames on L2." /> #### Offchain Subnames Offchain subnames are exactly what they sound like - subnames that live in a centralized database on private servers, also powered by [CCIP Read](/resolvers/ccip-read). If your goal is to name a large amount of EVM addresses quickly and cheaply, with a low barrier to entry, offchain subnames might be for you. Often times, managing offchain names is as simple as interacting with a REST API. From a user perspective, offchain subnames are hardly different than onchain subnames. They will not appear in wallet applications as NFTs like the previous two approaches, but they can resolve all the same data (addresses, text records, etc). There are API providers that offer programmatic access to offchain subnames such as [Namespace](https://namespace.ninja/), along with open-source examples like [gskril/ens-offchain-registrar](https://github.com/gskril/ens-offchain-registrar). ## Subgraph This is a page covering the graph's ENS subgraph. The ENS subgraph indexes onchain events of second-level .eth names, and DNS imported names. It allows us to build a reasonable approximation of the ENS names an address owns. To read more about why not all names (such as Offchain & Gasless Names) show up in the subgraph read the [listing names](/web/enumerate) page. ### The Graph The Graph is a protocol for indexing and querying data from blockchains. There are multiple subgraphs that you can use to query information about ENS names. These subgraphs are available for [mainnet](https://thegraph.com/explorer/subgraphs/5XqPmWe6gjyrJtFn9cLy237i4cWw2j9HcUJEXsP5qGtH), [sepolia](https://api.studio.thegraph.com/query/49574/enssepolia/version/latest) and [holesky](https://api.studio.thegraph.com/query/49574/ensholesky/version/latest). :::note Developers are welcome to use our rate limited API endpoints above for testing, but it is highly encouraged to [sign up for a free account with TheGraph](https://thegraph.com/studio/apikeys/) to get your own API key. ::: ### GraphQL Schema The schema for the ENS subgraph is defined in [/schema.graphql](https://github.com/ensdomains/ens-subgraph/blob/master/schema.graphql). ### Use Cases There are certain use cases where the graph is better for querying ENS specific information than through the resolution process. One of such use-cases is querying which NFT names are owned by a specific address. ### Terminology When using the subgraph, you may encounter `registrant` and `controller` fields. These were the old terminology for [Owner](/terminology#owner) and [Manager](/terminology#manager) respectively. The `registrant` address is the owner of a name. It's the same value that will be returned from calling `ownerOf()` on the Base Registrar Controller (registrar.ens.eth). A registrant/owner may transfer ownership and assign a controller/manager. The `controller` address is the manager of a name. It's the same value that will be returned from calling `owner()` on the ENS Registry (registry.ens.eth). A controller/manager may change the resolver of a name and set its records. ### Example Queries :::note Most of these example queries have equivalent functionality in [ENSjs](https://github.com/ensdomains/ensjs/tree/main/docs). ::: You can explore the following examples interactively via the [Graph Explorer Playground](https://thegraph.com/explorer/subgraphs/5XqPmWe6gjyrJtFn9cLy237i4cWw2j9HcUJEXsP5qGtH?view=Playground\&chain=arbitrum-one) #### Getting a list of names owned by an account Ensure the address is lowercase ```graphql query getDomainsForAccount { domains(where: { owner: "0xa508c16666c5b8981fa46eb32784fccc01942a71" }) { name } } ``` #### Getting the top domain for an account based on the longest registry ```graphql query getDomainForAccount { account(id: "0xa508c16666c5b8981fa46eb32784fccc01942a71") { registrations(first: 1, orderBy: expiryDate, orderDirection: desc) { domain { name } } id } } ``` returns ```json { "data": { "account": { "registrations": [ { "domain": { "name": "datanexus.eth" } } ], "id": "0xa508c16666c5b8981fa46eb32784fccc01942a71" } } } ``` #### Searching for a subdomain ```graphql query getSubDomains($Account: String = "messari.eth") { domains(where: { name: "messari.eth" }) { name id subdomains(first: 10) { name } subdomainCount } } ``` returns ```json { "data": { "domains": [ { "name": "messari.eth", "id": "0x498ada62251a1227664ace8d97b0de2dcc6652ddf61e6fb5d3150f43ccf599e6", "subdomains": [ { "name": "subgraphs.messari.eth" }, { "name": "bd.messari.eth" } ], "subdomainCount": 2 } ] } } ``` #### Getting the expiry of an ENS domain ```graphql query getDomainExp($Account: String = "paulieb.eth") { registrations( where: { domain_: { name: $Account } } first: 1 orderBy: expiryDate orderDirection: desc ) { expiryDate } } ``` returns ```json { "data": { "registrations": [ { "expiryDate": "1714752524" } ] } } ``` import { EmbedLink } from '../../components/EmbedLink' import { Properties } from '../../components/Properties' import { Repository } from '../../components/Repository' import { Card } from '../../components/ui/Card' ## Offchain / L2 Resolvers While ENS name resolution always starts from Ethereum Mainnet, it's possible to store almost all data associated with a name and its subdomains elsewhere. By leveraging [EIP-3668](https://eips.ethereum.org/EIPS/eip-3668) (CCIP Read) in a [Resolver](/resolvers/quickstart), developers can effectively defer resolution to an L2 or offchain API. <Card className="hidden items-center justify-center gap-4 p-4 md:flex"> <div className="space-y-1 p-2 text-center leading-none"> <div className="font-bold">Name</div> <div>greg.base.eth</div> </div> <div>➡️</div> <div className="space-y-1 p-2 text-center leading-none"> <div className="font-bold">L1 Resolver</div> <div>0xde90...4F31</div> </div> <div>➡️</div> <div className="space-y-1 p-2 text-center leading-none"> <div className="font-bold">Gateway</div> <div>api.coinbase.com</div> </div> <div>➡️</div> <div className="space-y-1 p-2 text-center leading-none"> <div className="font-bold">Address</div> <div>0x179A...9285</div> </div> </Card> ### How does CCIP Read work? CCIP Read (Cross Chain Interoperability Protocol) is a specification that defines a standard error smart contracts can throw if they want to trigger an offchain HTTP request. ```solidity error OffchainLookup( address sender, string[] urls, bytes callData, bytes4 callbackFunction, bytes extraData ) ``` When a contract reverts with the `OffchainLookup` error, clients (wagmi, viem, ethers, etc.) unwrap the error and handle it appropriately. #### How does ENS use CCIP Read? By [leveraging CCIP Read in a Resolver](/resolvers/writing#offchain-resolvers), developers can store name data beyond Ethereum Mainnet. A common use case is managing subnames on Layer 2 networks - for example, Coinbase allows users to register names like `jesse.base.eth` on Base, while the parent name `base.eth` remains on Ethereum Mainnet. This creates a seamless experience for application developers - they can resolve names like `jesse.base.eth` exactly the same way they would resolve mainnet names, without needing to know which network the data is actually stored on. The use of CCIP Read in name resolution is completely transparent to users. ![](/img/ccip-read-diagram-1.png) To resolve an offchain/L2 name using CCIP Read, the steps are as follows: 1. A user types "example.eth" into their wallet. 2. The wallet's client calls `resolve()` on example.eth's Resolver. 3. The Resolver reverts with an `OffchainLookup` error. 4. The client makes a request to the gateway URL specified in the error with the calldata from the error. 5. The gateway processes the request and returns data to the client. This is where the data is fetched from L2 or an offchain database. 6. The client calls the callback function specified in the error with the data returned from the gateway, which usually performs some sort of validation. 7. If the callback function validates the data, the client returns the result to the user. While this might sound complex, it all happens under the hood and is completely transparent to application developers. ### Offchain Subname Example An example of offchain ENS names powered by CCIP Read can be found at [offchain.ens.gregskril.com](https://offchain.ens.gregskril.com/). The name [offchaindemo.eth](https://ens.app/offchaindemo.eth) with Resolver [0x35b9...E237](https://etherscan.io/address/0x35b920d4329C5797727Af8b15358b43509e5E237#code), reverts with `OffchainLookup` and directs the client to a Gateway URL. The Gateway returns the relevant information from an offchain database, signed by a trusted private key which the smart contract can verify. This prevents a compromised Gateway from returning false information. <Repository src="gskril/ens-offchain-registrar" description="Offchain ENS Subnames" /> ### Offchain vs L2 Resolvers From the perspective of the L1 Resolver contract, the process of resolving an L2 name is exactly the same as resolving on offchain name. The differences come from the Gateway implementation and the Resolver's callback function. For names that are stored offchain like the example above, the Gateway would read from a normal web2 database and the Resolver's callback function would simply verify the Gateway operator's signature. For names that are stored on L2, the Gateway would make an RPC call to the relevant L2 and the Resolver's callback function would ideally verify the response by using the L2's state root on L1 (this assumes knowledge of how L2's work). To implement trustless L2 resolution, developers should use a solution like [Unruggable Gateways](https://gateway-docs.unruggable.com/). <Repository src="unruggable-labs/unruggable-gateways" description="Solution for fetching proofs of data from rollup chains and verifying that data on Layer 1 Ethereum." /> ### Writing a CCIP Read Gateway A gateway is an offchain API endpoint that implements the [Gateway Interface](https://eips.ethereum.org/EIPS/eip-3668#gateway-interface) specified in EIP-3668. It is responsible for decoding the calldata from an `OffchainLookup` error and returning a relevant response. #### Implementing the Endpoint Your gateway must implement either a `GET` or `POST` endpoint with `{sender}` and `{data}` parameters, and be stored in the implementing smart contract. The `OffchainLookup` error will include this URL, which is how the client knows where to send the request. :::code-group ```yaml [POST] // POST if URL does not include '{data}' parameter URL: https://example.com/gateway Method: POST Body: sender: "0x..." data: "0x..." ``` ```yaml [GET] // GET if URL includes '{data}' parameter URL: https://example.com/gateway/{sender}/{data}.json Method: GET ``` ::: <Properties> <Properties.Property name="sender" type="address"> Lowercased address of the contract reverting with the `OffchainLookup` error. </Properties.Property> <Properties.Property name="data" type="bytes"> 0x prefixed bytes of the data passed to the `OffchainLookup` error. </Properties.Property> </Properties> #### Example Gateway Implementation The most basic gateway implementation is to return a static value without doing any signing. We even have a library [@ensdomains/ccip-read-router](http://github.com/ensdomains/ccip-read-router) to abstract decoding the calldata. <EmbedLink title="Basic Gateway Implementation" href="https://github.com/ensdomains/docs/blob/master/functions/api/example/basic-gateway.ts" /> #### Trust Assumptions As explained in [Offchain vs L2 Resolvers](#offchain-vs-l2-resolvers), trust assumptions are up to the implementing developer and can range from fully trusted to full trustless. The worst case scenario of a trusted implementation is that a malicious actor gains control of the gateway and can return false information. The worst case scenario of a trustless implementation is that a malicious actor can take a gateway offline, but it can never return false data. ### Writing an Offchain/L2 Resolver See [Writing a Resolver](/resolvers/writing#offchain-resolvers) for more information on how to implement a Resolver with CCIP Read. ### Testing your offchain names To test your implementation, search the relevant name in the [ENS Manager App](https://app.ens.domains). Make sure that you've configured your test name to return a result for common data like an ETH address or common text records like `avatar` or `description`. If you set an arbitrary text record key like `test`, the manager app has no way of knowing that it exists. ## Chain Registry-Resolver (on.eth) \[An on-chain single source of truth for blockchain metadata.] ### Overview The Chain Registry-Resolver is a smart contract that acts as a **canonical, on-chain registry** for blockchain metadata. It serves as the resolver for the `on.eth` namespace and enables applications and users to retrieve metadata for *any* blockchain using a single human-readable identifier, such as `base` or `solana`. Historically, blockchain metadata has been stored in centralized, fragmented repositories maintained by third parties. The Chain Registry-Resolver brings this metadata on-chain into a single, extensible registry, where control and update authority are delegated to the relevant chain operators.
프로젝트로 돌아가기