Ethereum Name Service 백서

Ethereum Name Service

원문

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

ead). #### Testing CCIP Read Support To test if your integration properly implements CCIP Read, try resolving `test.offchaindemo.eth`. It should return the address `0x779981590E7Ccc0CFAe8040Ce7151324747cDb97`. ### DNS Names and Name Detection ENS supports importing DNS names into ENS, allowing legacy domain names to work alongside .eth names. It's important that your application correctly also detects DNS names. #### Common Mistake: Only Matching .eth Many integrations check if the input ends with `.eth` in order to detect an ENS name: ```js if (input.endsWith('.eth') { // ... } ``` This is **incorrect** because it excludes DNS names imported into ENS (like `ensfairy.xyz`). #### Correct Pattern: Match All Valid Domains Instead, your integration should treat any dot-separated string as a potential ENS name. For example, `a.co` should be treated as a potential ENS name. ```js if (input.includes('.') && input.length > 2) { // ... } ``` This pattern correctly matches: * `.eth` names like `vitalik.eth` * DNS names like `ensfairy.xyz` * Subdomains like `ses.fkey.id` * Emoji domains like `🦇️🔊️🦇️🔊️🦇️🔊️.eth` Learn more about [DNS integration here](/learn/dns). The full specification of name normalization is defined in [ENSIP-15](/ensip/15). ### Multichain Considerations Even if your application only operates on an L2 like Base, ENS resolution always starts on Ethereum Mainnet. This means you need to configure a L1 client alongside your L2 chain. #### Configuring Both L2 and Mainnet Here's how to set up your application to use Base (or another L2) while ensuring ENS resolution works correctly by including Mainnet: :::code-group ```ts [Viem] import { createPublicClient, http, toCoinType } from 'viem' import { base, mainnet } from 'viem/chains' // Client for Base transactions const baseClient = createPublicClient({ chain: base, transport: http(), }) // Client for ENS resolution on Mainnet const mainnetClient = createPublicClient({ chain: mainnet, transport: http(), }) // Get the Base address for this ENS name const baseAddress = await mainnetClient.getEnsAddress({ name: 'test.ses.eth', coinType: toCoinType(base.id), }) ``` ```tsx [Wagmi] import { toCoinType } from 'viem' import { createConfig, http, useEnsAddress } from 'wagmi' import { base, mainnet } from 'wagmi/chains' export const config = createConfig({ chains: [base, mainnet], // Include both your L2 and Mainnet transports: { [base.id]: http(), [mainnet.id]: http(), }, }) function MyComponent() { const { data: baseAddress } = useEnsAddress({ name: 'test.ses.eth', chainId: mainnet.id, // Always use mainnet for ENS resolution coinType: toCoinType(base.id), // Always specify the coinType (chain) }) } ``` ```ts [Ethers] import { ethers } from 'ethers' // Provider for Base const baseProvider = ethers.getDefaultProvider('base') // Provider for ENS resolution on Mainnet const mainnetProvider = ethers.getDefaultProvider('mainnet') // Get the Base address for this ENS name const resolver = await mainnetProvider.getResolver('test.ses.eth') const baseAddress = await resolver?.getAddress(8453) // Base chain ID ``` ::: #### Chain-Specific Addresses It is possible to configure a different address per chain for the same name: * `test.ses.eth` resolves to `0x2B0F09F23193de2Fb66258a10886B9f06903276c` for Ethereum Mainnet, but * `test.ses.eth` resolves to `0x7d3a48269416507E6d207a9449E7800971823Ffa` for Base. From an application point of view it is important to be aware and always request the address for the correct chain, even on Ethereum Mainnet. All examples above explicitly set the `coinType` to Base, since they request the Base address for a given name. :::warning Omitting the coinType currently resolves the Ethereum Mainnet (or Sepolia on testnet) address. This address is not guaranteed to work on L2s. Always double check with your user when sending funds to such an address. ::: ### If Your Application Writes to ENS Reading ENS data is abstracted away by the libraries above. Writing is not: registering a name or setting a record is a direct contract interaction, and the write-side contracts change with ENSv2. At the time of writing, ENSv2 write support in libraries is limited to preview releases ([ENSjs v5](https://github.com/ensdomains/ensjs)), so applications that write to ENS need to update these code paths themselves. During the migration from ENSv1 to ENSv2, new registrations happen exclusively in ENSv2, while names that have not migrated yet keep their ENSv1 write paths, renewals included. Applications should support ENSv2, which every new and migrated name uses. Additionally keeping the ENSv1 write paths for unmigrated names is optional. Everything below can be tested against the [ENSv2 deployment on Sepolia](/learn/deployments#sepolia-ensv2) today. | Operation | ENSv1 | ENSv2 | | -------------------------------- | -------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | Register or renew a `.eth` name | `ETHRegistrarController`, paid in ETH | New [ETH Registrar](/ensv2/eth-registrar): commit-reveal stays, but fees are paid in stablecoins and the grace period is 28 days | | Set address, text or contenthash | Setters on the name's configured resolver | Unchanged, but the configured resolver is now typically a per-account [Permissioned Resolver](/ensv2/permissioned-resolver): see [below](#never-hardcode-a-resolver-address) | | Change a name's resolver | `setResolver(node, ...)` on the ENS registry | `setResolver(tokenId, ...)` on the [registry that holds the name](/ensv2/permissioned-registry) | | Create subnames | `setSubnodeRecord` on the registry or Name Wrapper | `register()` on the parent name's subregistry | | Transfer a name | ERC-721 (unwrapped) or ERC-1155 (wrapped) | [ERC1155Singleton](/ensv2/erc1155-singleton) transfer with [mutable token IDs](/ensv2/mutable-token-ids) | | Set a primary name | Reverse Registrar `setName` | See [Reverse Resolution](/ensv2/reverse-resolution) | Some changes deserve special attention: #### Registration Fees Are Paid in Stablecoins The new ETH Registrar keeps the commit-reveal flow, but the fee is no longer sent as ETH along with the transaction: `register` and `renew` are paid in an approved stablecoin of the caller's choice. The Sepolia deployment currently accepts USDC (both [Circle's Sepolia USDC](https://sepolia.etherscan.io/token/0x1c7D4B196Cb0C7B01d743Fbc6116a902379C7238) and a freely mintable [test USDC](https://sepolia.etherscan.io/token/0x16f95d91dba7da3aca778ec053df0ff6c6a8aa8e)) and a [test DAI](https://sepolia.etherscan.io/token/0x278053acc97888e63ec81c80fec641bf0bf19664). For a registration UI this means a token approval step before registering, and balance checks against the stablecoin instead of ETH. #### Token IDs Are Mutable If your application caches token IDs, this is a breaking change: in ENSv2 a name's [token ID can change](/ensv2/mutable-token-ids) over its lifetime. Always resolve the name to its current token ID at transaction time instead of storing it, using [`findTokenId(label)`](/ensv2/permissioned-registry#view-functions) on the registry that holds the name. #### Never Hardcode a Resolver Address When a name is resolved, only the resolver configured for that name in the registry is queried. Records written to any other resolver contract are never returned. Hardcoding a resolver address was therefore already an anti-pattern in ENSv1, but it usually worked anyway, because the configured resolver of most names is the shared Public Resolver. In ENSv2 resolvers are deployed per account, so a name's configured resolver is its owner's own deployment and a hardcoded shared address is guaranteed to be the wrong contract. Always look up the name's configured resolver at write time, and don't cache the result either: the resolver can be reconfigured at any point, for example when the name changes hands. Once found, the setter interface is the same. The same applies to registries: a name's subnames live in its individual subregistry, not in a single global registry contract, so obtain it fresh before writing. #### Name Wrapper and Fuses If your application manages names through the [Name Wrapper](/wrapper/overview) (wrapping, unwrapping or burning fuses), read the [Enhanced Access Control](/ensv2/enhanced-access-control) page: the wrapper's functionality is built into the core of ENSv2, and fuses are replaced by roles. ## Listing a Users Names In some cases you might want to show off all names that a user owns. Due to the nature of how the ENS Protocol works under the hood, this might be a slightly more difficult task than expected. Fortunately, tooling has been developed to accommodate for this and to make it easier. ### Why not all names? Not all ENS names exist onchain ([learn more about wildcard resolution](/ensip/10)), meaning we don't always know which names a user owns/controls. The notable exception is [second-level](/terminology#first-layer) [.eth names](/registry/eth). Ownership of these names are onchain and indexable through scanning events on the appropriate smart contracts. Note that this does not necessarily mean address and text records associated with the name are onchain ([read more about offchain resolvers](/resolvers/ccip-read)). ### Guidelines When using one of the methods described below it is important to keep in mind that you should always allow for a user to manually enter a name, as not all names are indexable. It is generally recommended to allow users to input a name using an [input box](/web/design#2-resolving-input-fields) and to verify it resolves to the correct address upon user-completion. ### The Graph The [ENS subgraph](/web/subgraph) indexes all events from relevant smart contracts and exposes them via a GraphQL endpoint. Note that addresses in filters must be lowercased. ENSjs makes it easy to run common queries on the subgraph with strong type safety. Docs can be found [here](https://github.com/ensdomains/ensjs/tree/main/docs/subgraph). ```graphql { domains(where: { owner: "0x225f137127d9067788314bc7fcc1f36746a3c3b5" }) { name } wrappedDomains( where: { owner: "0x225f137127d9067788314bc7fcc1f36746a3c3b5" } ) { name } } ``` import { EmbedLink } from '../../components/EmbedLink' import { Card } from '../../components/ui/Card' ## Getting Started \[Integrate ENS into your dApp] This section walks you through how to leverage the ENS open standards to improve the user experience of your app. {/* TODO: Break the following examples into a component to fetch live data */} <Card className="flex items-center justify-center gap-2"> <div className="flex flex-col gap-2 rounded-md border p-2 px-3"> <div className="flex items-center gap-2"> <object data={'https://ens-api.gregskril.com/avatar/vitalik.eth?width=64'} type="image/jpeg" className="aspect-square h-full w-8 rounded"> <img src="https://docs.ens.domains/fallback.svg" /> </object> <span>vitalik.eth</span> </div> </div> <span>➡️</span> <div className="flex flex-col justify-start gap-1 rounded-md border p-2 px-3"> <span>mi pinxe lo crino tcati</span> <span>0xd8d...6045</span> </div> </Card> <Card> <div className="flex items-stretch justify-center gap-2"> <div className="flex flex-col justify-between rounded-md border p-2 px-3"> <span>0xb8c...67d5</span> <span>0x866...5eEE</span> <span>0xd8d...6045</span> </div> <span className="flex flex-col gap-3 pt-3"> <span>➡️</span> <span>➡️</span> <span>➡️</span> </span> <div className="flex flex-col gap-2 rounded-md border p-2 px-3"> {['nick.eth', 'jefflau.eth', 'vitalik.eth'].map((name) => ( <div className="flex items-center gap-2" key={name}> <object data={'https://ens-api.gregskril.com/avatar/' + name + '?width=64'} type="image/jpeg" className="aspect-square h-full w-8 rounded" > <img src="/img/fallback-avatar.svg" /> </object> <span>{name}</span> </div> ))} </div> </div> </Card> ### Quickstart If you are looking to jumpstart your journey with ENS, or you are looking for a quick reference, visit the [Quickstart](/web/quickstart) page. <EmbedLink href="/web/quickstart" title="Quickstart" description="To jumpstart your journey with names." /> ### Tools and Libraries ENS is an integral part of the Ethereum ecosystem. Fortunately, the open-source community is to the rescue, and almost all of the tools and libraries you use today support ENS. To learn more check out the [tools & libraries section](/web/libraries). <EmbedLink href="/web/libraries" title="Tools & Libraries" description="To learn about the available tools and libraries that interact with ENS" /> ### Avatars, Addresses & Records Information about a name is fetched from its resolver. This can be done using pre-built features included in popular [web3 libraries](/web/libraries) (recommended), or by calling a resolver contract directly. If you're interested in interacting with ENS resolvers, you might find the [Resolver Reference](/resolvers/interfaces) section helpful. <EmbedLink href="/web/resolution" title="Address Resolution" description="To find guides on the address lookup features of ENS." /> ### Subnames <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> <EmbedLink href="/web/subdomains" title="Issuing Subnames" description="To an overview of the difference ways to issue subnames." /> ### Registration <Card className="flex items-center justify-center text-xl"> <div className="text-right font-bold"> {['nick', 'vitalik', 'matoken', 'jefflau', 'ens'].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">.eth</div> </Card> <EmbedLink href="/registry/eth" title="ETH Registrar" description="To an overview of the two smart contracts that make up the ETH Registrar." /> import { ConnectKits } from '../../components/ConnectKits' import { Libraries } from '../../components/Libraries' ## Tools & Libraries \[Tools to help you interface with the ENS protocol] ### Quickstart Kits There are a few plug-and-play kits that you can use to jumpstart your project. These kits will include everything you need to have users connect their wallet, have names showing, avatars, and more, right out of the box! <ConnectKits /> ### Libraries There are many ways to interface with the ENS Ethereum smart contracts, indexers, and metadata services. Whether you're building a dApp, a backend service, or interacting with ENS from your smart contract, there's a library out there to help you get started. <Libraries /> ## Multichain \[L2 & Crosschain Resolution] ### ENS L2 The ENS Labs team recently announced our plans and roadmap for scaling ENS to the entire internet and beyond. You can read more [on our blog](https://blog.ens.domains/post/ensv2), [on X](https://twitter.com/ensdomains/status/1795440186513576318), and [the forums](https://discuss.ens.domains/t/technical-feedback-thread-for-ensv2/19233). The roadmap involves migrating .eth registrations to a new system, in addition to improved support for existing L2 solutions. You can find out more on the [changelog](/changelog). ### But isn't ENS on mainnet? Yes, technically. The resolution process always starts on mainnet. There needs to be, one source of truth after all. However, the name resolution process can branch off to other chains, offchain gateways and much more. To read a more in-depth explanation of how resolution works, checkout the [section dedicated to the Resolution Process](/resolution/). ### My dapp is on X but I want ENS The ENS Protocol can be used on/for any chain! If you are building a non-mainnet dApp and want to use ENS names simply [add a Mainnet RPC to your Wagmi config](/web/libraries) and specify `chainId: 1` in your config like so: ```tsx import { useAccount, useEnsAvatar, useEnsName } from 'wagmi' const Name = () => { const { data: ensName } = useEnsAddress({ name: 'nick.eth', chainId: 1, // (1 = Ethereum, 11155111 = Sepolia) // [!code hl] }) return <div>{ensName || address}</div> } ``` And voila! You can now resolve ENS names anywhere! 🎉 ## Naming Contracts \[Learn how to name your smart contracts with ENS] While it's commonly known that regular user accounts can have [primary names](/web/reverse), it's less known that smart contracts can also have names. In order for you to manage the primary name of your smart contract, you need to own the [reverse node](/terminology#reverse-node) for the contract address. There are several ways of doing this, depending on if you are actively developing your contract or if it is already deployed. :::note To enable reverse resolution, you must set both the reverse record and the ETH address to the contract’s deployed address. ::: ### New Contracts Depending on your use case, there are a few ways to set a smart contract's primary name. If you want to be able to change the name later, you have two options: * **(Recommended)** Make the contract [Ownable](https://docs.openzeppelin.com/contracts/5.x/access-control) and set yourself as the owner. * Take ownership of the reverse node (`{address}.addr.reverse`) for the contract. This only works for contracts on Ethereum Mainnet. The Ownable method is preferred since it doesn't require any additional code in many cases, and has the best Etherscan support. For immutable smart contracts (without an owner), you can set the reverse record directly in the constructor at the time of deployment. Let's look at a few examples. #### Ownable (recommended) :::note An example of this is [ownable.contract.gtest.eth](https://etherscan.io/address/ownable.contract.gtest.eth#code) ::: If you want to be able to change the name in the future, you can make your smart contract [Ownable](https://docs.openzeppelin.com/contracts/5.x/api/access#Ownable). ```solidity import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol"; contract MyContract is Ownable { constructor(address initialOwner) Ownable(initialOwner) {} } ``` [Reverse Registrars](/registry/reverse) on all supported chains understand the Ownable interface and will let the `owner()` of a contract set its reverse record without having to add any ENS-specific code. Once this contract is deployed, call `setNameForAddr()` on a Reverse Registrar from your authorized owner account on the relevant chain. Note that the arguments are slightly different on L1 and L2s. * The first address argument should be the address of your contract (both L1 and L2s) * The second address argument should be the owner of your smart contract (only L1) * The third address argument should be the `defaultResolver()` from the Reverse Registrar (only L1) * The last argument is the ENS name to set it to (both L1 and L2s) #### Set a name in the constructor :::note An example of this [contract.gtest.eth](https://etherscan.io/address/contract.gtest.eth#code) ::: If you don't want to be able to change the name in the future, you can call `setName()` on a Reverse Registrar directly from your contract's constructor. Your contract would look something like this: ```solidity // SPDX-License-Identifier: MIT pragma solidity ^0.8.21; interface IReverseRegistrar { function setName(string memory name) external returns (bytes32); } contract MyContract { /// @param reverseRegistrar The address of the Reverse Registrar contract on the relevant chain to use. /// @param name The rever
프로젝트로 돌아가기