bitpro가 원문에서 글자만 모은 내용이에요. 표·그림·수식은 빠지거나 깨질 수 있어요. 전체 75쪽 중 6쪽
se name to set for this contract's address.
constructor(address reverseRegistrar, string memory name) {
IReverseRegistrar(reverseRegistrar).setName(name);
}
}
```
You can find the Reverse Registrar addresses [here](/registry/reverse#supported-chains).
#### ReverseClaimer.sol (L1 only)
:::note
While this method works perfectly at the ENS protocol level, Etherscan does not index the contract events correctly so it may not appear in their UI.
:::
This is a simple drop-in module that transfers ownership of the reverse node to an address of your choice, which can then update the reverse name at any time.
```solidity
import "@ensdomains/ens-contracts/contracts/registry/ENS.sol";
import "@ensdomains/ens-contracts/contracts/reverseRegistrar/ReverseClaimer.sol";
contract MyContract is ReverseClaimer {
constructor (
ENS ens
) ReverseClaimer(ens, msg.sender) {}
}
```
When you deploy your contract, the deployer account (`msg.sender`) will be given ownership of the reverse node for that contract address. This gives you authorization to call `setName(node, newName)` on the latest public resolver ([resolver.ens.eth](https://etherscan.io/address/resolver.ens.eth)), where `node` is the reverse node for the contract address and `newName` is the name you want to set it to.
To find the reverse node for your contract address, you can use the following viem script:
```ts
import { namehash } from 'viem/ens'
const myContractAddress = '0x...' // replace with your contract address
const node = namehash(
`${myContractAddress.slice(2).toLowerCase()}.addr.reverse`
)
console.log(node)
```
### Existing Contracts
If your contract is already deployed you might still be able to set a name for it.
If your contract supports the [Ownable](https://docs.openzeppelin.com/contracts/5.x/api/access#Ownable) interface from OpenZeppelin, [read the section above](#ownable-recommended).
#### Safe, Multisig & DAO
If your contract is a Safe, Multisig, DAO or otherwise has the ability to execute arbitrary calldata, you can use a [Reverse Registrar](/registry/reverse) contract directly to set a name for it.
You might even be able to use the [ENS Manager App](https://app.ens.domains/) inside of your safe app to set a primary name.
import { AddressRecords } from '../../components/AddressRecords'
import { ConnectKits } from '../../components/ConnectKits'
import { EnsProfile } from '../../components/EnsProfile'
import { TextRecords } from '../../components/TextRecords'
import { Card } from '../../components/ui/Card'
## Quickstart
Hey there 👋, this is the quickstart guide. If you want to learn the process checkout [everything about ENS in dApps](/web/).
If you would rather just clone an example repository checkout these:
### Starter Kits
<ConnectKits />
### Add to your dApp
This quickstart guide assumes you have a basic understanding of React.
#### Installation
```bash [Terminal]
npm install wagmi viem @tanstack/react-query
```
#### Showing the User Profile
The below codesnippet demonstrates how you can create a basic user profile section that shows the users ENS name and avatar.
The snippet leverages the [useAccount](https://wagmi.sh/react/hooks/useAccount), [useEnsName](https://wagmi.sh/react/hooks/useEnsName), and [useEnsAvatar](https://wagmi.sh/react/hooks/useEnsAvatar) hooks from wagmi.
<Card className="flex flex-col items-center justify-center gap-2 sm:flex-row">
<EnsProfile name="nick.eth" />
<EnsProfile name="jefflau.eth" />
<EnsProfile name="vitalik.eth" />
</Card>
```tsx
import { useAccount, useEnsAvatar, useEnsName } from 'wagmi'
export const EnsProfile = () => {
const { address } = useAccount()
const { data: name } = useEnsName({ address, chainId: 1 })
const { data: avatar } = useEnsAvatar({ name, chainId: 1 })
return (
<div className="flex items-center gap-2">
<img src={avatar} className="h-8 w-8 rounded-full" />
<div className="flex flex-col leading-none">
<span className="font-semibold">{name}</span>
<span className="text-grey text-sm">{address}</span>
</div>
</div>
)
}
```
:::info
ENS resolution always starts from L1 regardless of the chain the user is connected to. This is why we specify `chainId: 1` for Ethereum Mainnet in the wagmi hooks above.
:::
#### Text Record Lookups
<Card>
<TextRecords name="nick.eth" keys={['url', 'com.github', 'com.twitter', 'description']} />
</Card>
:::code-group
```tsx [TextRecords.tsx]
// [!include ~/components/TextRecords.tsx]
```
```ts [useEnsTexts.ts]
// [!include ~/hooks/useEnsTexts.ts]
```
:::
#### Address Record Lookups
While ENS resolution always starts from Ethereum L1, you can store addresses for other chains in ENS records.
<Card>
<AddressRecords name="gregskril.eth" coinTypes={[60, 2147483658, 2147492101, 2147525809]} />
</Card>
:::code-group
```tsx [AddressRecords.tsx]
// [!include ~/components/AddressRecords.tsx]
```
```ts [useEnsAddresses.ts]
// [!include ~/hooks/useEnsAddresses.ts]
```
:::
import { EmbedLink } from '../../components/EmbedLink'
import { TextRecords } from '../../components/TextRecords'
import { Card } from '../../components/ui/Card'
## Text Records
Text records are key-value pairs that can be used to store any arbitrary data associated with a name.
Think of this as a user's **digital backpack** utilized for the storage of preferences, public details, and more.
<Card>
<TextRecords name="nick.eth" keys={['description', 'com.twitter', 'com.github']} />
</Card>
The most popular records have been standardised.
One example of a standardised record is the [avatar record](/web/avatars) which is used to store a user's profile picture.
### Getting Records
To fetch the record for a specific name, you can use one of the following methods:
:::code-group
```tsx [Wagmi]
// https://wagmi.sh/react/api/hooks/useEnsText
import { normalize } from 'viem/ens'
import { useEnsText } from 'wagmi'
export const MyProfile: FC<{ name: string }> = ({ name }) => {
const { data } = useEnsText({
name: normalize('nick.eth'),
key: 'com.twitter',
})
return (
<div>
<span>Twitter: {data}</span>
</div>
)
}
```
```tsx [Ethers]
// https://docs.ethers.org/v5/api/providers/provider/#EnsResolver
const provider = new ethers.providers.JsonRpcProvider()
const resolver = await provider.getResolver('nick.eth')
const twitter = await resolver.getText('com.twitter')
```
```tsx [Viem]
// https://viem.sh/docs/ens/actions/getEnsText.html
import { createPublicClient, http } from 'viem'
import { mainnet } from 'viem/chains'
import { normalize } from 'viem/ens'
const publicClient = createPublicClient({
chain: mainnet,
transport: http(),
})
const ensText = await publicClient.getEnsText({
name: normalize('nick.eth'),
key: 'com.twitter',
})
```
```python [web3.py]
# https://web3py.readthedocs.io/en/latest/ens_overview.html#text-records
from ens.auto import ns
# set text
ns.set_text('alice.eth', 'url', 'https://example.com')
# get text
url = ns.get_text('alice.eth', 'url')
assert url == 'https://example.com'
```
:::
### Types of Records
[ENSIP-5](/ensip/5) and [ENSIP-18](/ensip/18) specify two sets of records that are considered standardized. Below are some of the most commonly ones:
| Name | Usage | Reference | Example |
| ----------- | --------------------------------------- | --------------------- | ------------------------------------------ |
| avatar | [Avatar](/web/avatars) | [ENSIP-5](/ensip/5) | eip155:1/erc1155:0x495f... |
| description | Bio or description of the profile | [ENSIP-5](/ensip/5) | Lead developer of ENS |
| com.twitter | Twitter/X handle | [ENSIP-5](/ensip/5) | nicksdjohnson |
| com.github | GitHub handle | [ENSIP-5](/ensip/5) | arachnid |
| url | Website URL | [ENSIP-5](/ensip/5) | [https://ens.domains](https://ens.domains) |
| header | Image URL to be used as a header/banner | [ENSIP-18](/ensip/18) | ipfs\://QmNtHN7WE... |
#### Custom Records
While standardized records are expected to have the best ecosystem support, it's possible to store any key-value pair you desire. We generally recommend to stick to a pattern, or prefix things with your app or protocol (eg. `com.discord`, or `org.reddit`), as such to avoid collisions.
### Setting Records
Text records are controlled by the resolver associated with a given name. Read more about [interacting with a resolver](/resolvers/interacting).
<EmbedLink href="/resolvers/interacting" title="Interacting with a Resolver" tag="Advanced" description="To learn more about interacting with a resolver." />
import { EmbedLink } from '../../components/EmbedLink'
import { EnsProfile } from '../../components/EnsProfile'
import { Card } from '../../components/ui/Card'
## Address Lookup \[Learn how to resolve blockchain addresses from human-readable names with ENS.]
The ENS Protocol aims to make it easy to use Ethereum.
It does this by providing a simple way to use human-readable names instead of long machine-readable addresses.
### Getting the users Ethereum Address
The goal here is to take a name, such as `nick.eth`, and convert it to an address, such as `0x225f137127d9067788314bc7fcc1f36746a3c3B5`.
<Card className="flex justify-center">
<EnsProfile name="nick.eth" />
</Card>
The simplest thing you can do is start with a name, and resolve it to an address.
We call this a "forward lookup".
Think of places where users can enter names, such as sending transactions, chatting, etc.
Note that all dot-separated strings should be treated as potential ENS names, since ENS supports [many TLDs](/dns/tlds). A common mistake is to only treat strings that end in `.eth` as ENS names.
:::code-group
```tsx [Wagmi]
import { useAccount, useEnsAvatar, useEnsName } from 'wagmi'
export const Name = () => {
const { data: ensName } = useEnsAddress({
address: 'nick.eth', // The name to lookup
chainId: 1, // The chain to start resolution on (Ethereum Mainnet or a testnet)
})
return <div>{ensName || address}</div>
}
```
```ts [Ethers.js]
const address = await provider.lookupAddress('nick.eth')
```
```ts [Viem]
import { normalize } from 'viem/ens'
import { publicClient } from './client'
const ensAddress = await publicClient.getEnsAddress({
name: normalize('nick.eth'),
})
```
```py [web3.py]
from ens.auto import ns
address = ns.address('alice.eth')
```
```rust [ethers-rs]
let provider = Provider::<Http>::try_from("https://mainnet.infura.io/v3/...")?;
let address = provider.lookup_address("nick.eth").await?;
```
```ts [ensjs]
import { createEnsPublicClient } from '@ensdomains/ensjs'
import { http } from 'viem'
import { mainnet } from 'viem/chains'
const client = createEnsPublicClient({
chain: mainnet,
transport: http(),
})
const subgraphRecords = client.getSubgraphRecords({ name: 'ens.eth' })
const records = client.getRecords({
name: 'ens.eth',
records: {
coins: [...(subgraphRecords?.coins || []), 'BTC', 'ETH', 'ETC', 'SOL'],
texts: [
...(subgraphRecords?.texts || []),
'avatar',
'email',
'description',
],
contentHash: true,
abi: true,
},
})
```
```csharp [nethereum]
var ensService = new Nethereum.ENS.ENSService(web3)
var address = await ensService.ResolveAddressAsync('alice.eth')
```
:::
To learn what happens under the hood when you do a forward lookup, read the [resolution](/resolution) section.
### Multichain Addresses
ENS Names aren't just limited to storing Ethereum addresses.
Any blockchain address (BTC, LTC, SOL, etc.) can be queried by [SLIP-0044](https://github.com/satoshilabs/slips/blob/master/slip-0044.md) coin type or a value derived from an EVM Chain ID (specified in [ENSIP-11](/ensip/11)). This includes Ethereum L2 networks such as OP Mainnet and Base.
For EVM Chains besides Ethereum Mainnet, always use its [ENSIP-11](/ensip/11) coin type, irrespective of being included in SLIP-0044 (like Ether Classic).
The standardization of multichain addresses was first introduced in [ENSIP-9](/ensip/9), and also [EIP-2304](https://eips.ethereum.org/EIPS/eip-2304).
:::note
Regardless of the chain you're resolving an address for, ENS resolution always starts from Ethereum L1.
:::
:::code-group
```tsx [Wagmi]
// https://wagmi.sh/react/api/hooks/useEnsAddress
import { toCoinType } from 'viem'
import { useEnsAddress } from 'wagmi'
import { arbitrum, base } from 'wagmi/chains'
const name = 'gregskril.eth'
export const MyAddresses = () => {
// SLIP-0044 Coin Types (see ENSIP-9)
const { data: bitcoinAddr } = useEnsAddress({ name, coinType: 0, chainId: 1 })
const { data: solanaAddr } = useEnsAddress({
name,
coinType: 501,
chainId: 1,
})
// EVM Chain IDs (see ENSIP-11)
const { data: baseAddr } = useEnsAddress({
name,
coinType: toCoinType(base.id),
chainId: 1,
})
const { data: arbitrumAddr } = useEnsAddress({
name,
coinType: toCoinType(arbitrum.id),
chainId: 1,
})
return (
<div>
{JSON.stringify({ bitcoinAddr, solanaAddr, baseAddr, arbitrumAddr })}
</div>
)
}
```
```ts [Viem]
// https://viem.sh/docs/ens/actions/getEnsAddress.html#cointype-optional
const ensName = await publicClient.getEnsAddress({
name: normalize('wagmi-dev.eth'),
coinType: 0, // BTC
})
```
```ts [Ethers.js]
// https://docs.ethers.org/v5/api/providers/provider/#EnsResolver
const resolver = await provider.getResolver('ricmoo.eth')
const btcAddress = await resolver?.getAddress(0)
```
```py [web3.py (Python)]
# https://web3py.readthedocs.io/en/latest/ens_overview.html#multichain-address-resolution
from ens.auto import ns
eth_address = ns.address('alice.eth', coin_type=60)
```
:::
| Network | Coin Type |
| ------------ | ---------- |
| Bitcoin | 0 |
| Litecoin | 2 |
| Dogecoin | 3 |
| Ethereum | 60 |
| Solana | 501 |
| OP Mainnet | 2147483658 |
| Polygon | 2147483785 |
| Base | 2147492101 |
| Arbitrum One | 2147525809 |
... and many many more following [SLIP-0044](https://github.com/satoshilabs/slips/blob/master/slip-0044.md) and [ENSIP-11](/ensip/11)
#### Decoding Address Hashes
ENS resolvers store all addresses in bytes, which may have to be encoded to their respective address formats. To do this, we recommend using the [@ensdomains/address-encoder](https://www.npmjs.com/package/@ensdomains/address-encoder) package.
### Advanced
<EmbedLink href="/resolution" title="In-Depth Resolution" tag="Advanced" description="To learn more about the resolution process, please read the Resolution section." />
import { EmbedLink } from '../../components/EmbedLink'
import { EnsProfile } from '../../components/EnsProfile'
import { QandA } from '../../components/QandA'
import { Badge } from '../../components/ui/Badge'
import { Card } from '../../components/ui/Card'
## Primary Names
:::info
Primary names are now supported on both Ethereum Mainnet and popular L2s (Base, OP Mainnet, Arbitrum One, Scroll, and Linea). This enables users to have an end-to-end experience with ENS on their preferred L2!
:::
A "primary name" is the result of a bi-directional relationship between an EVM address and a human-readable ENS name. The two directions are:
1. Name -> Address (forward resolution)
2. Address -> Name (reverse resolution)
The outcome of this relationship makes it safe for applications to display ENS names instead of EVM addresses, leading to a better user experience.
<Card className="flex items-center justify-center gap-2">
<span className="font-medium">0xb8c...67d5</span>
<span>to</span>
<EnsProfile name="nick.eth" hideAddress />
</Card>
While forward resolution is configured in [Resolvers](/resolvers/quickstart), reverse records are typically set via smart contracts called Reverse Registrars which you can [read more about below](#setting-primary-names).
### L2 Primary Names
Before we dive into code examples, let's first understand why things work the way they do.
Prior to August 2025, ENS users had to make a transaction on Ethereum Mainnet (L1) to set a primary name. More specifically, they had to set a reverse record on the [Reverse Registrar](/registry/reverse) contract which was only available on L1.
<QandA open question="What is the difference between a reverse record and a primary name?" answer="A reverse record is a mapping from an EVM address to an ENS name, which is only part of a primary name. In order for a primary name to be valid, the name must also forward resolve to the same address on the respective chain." />
Since a majority of user activity is now on L2s, we've added the ability to set a reverse record on the following Ethereum Rollups:
* Arbitrum
* Base
* Linea
* OP Mainnet
* Scroll
In addition to these chains, we've also added the ability to set a default reverse record on Ethereum Mainnet (L1) that serves as a fallback when no chain-specific primary name is set. This is the simplest way to set a universal primary name for users who have a wallet that supports all EVM chains.
While this may sound simple in theory, it's easy to get tripped on the details in practice. Let's look at an example.
#### Understanding the Verification Process
The key thing to understand is that the forward address *for a given chain* must match the reverse record on the respective chain's reverse registrar.
Say I own `nick.eth`. The name resolves to `0x1234...5678` because I've set the ETH address for that name. I call `setName("nick.eth")` on the Base reverse registrar, and I expect that my primary name is now `nick.eth` on Base. But that's actually not the case.
ENS names can resolve to [different addresses on different chains](/web/resolution), and since `nick.eth` in the example above has only specified an Ethereum Mainnet address, the verification process will fail. In order to fix this, I need to set the Base address for `nick.eth` which is on L1 in this case. This is done by calling the following function on the resolver for the name.
```solidity
setAddr(
namehash("nick.eth"), // node (see Name Processing)
convertEVMChainIdToCoinType(8453), // coinType (see ENSIP-11)
0x1234...5678 // the address to set
)
```
Now that `nick.eth` resolves to `0x1234...5678` via the Base cointype, and `name(0x1234...5678)` on the Base reverse registrar returns `nick.eth`, my primary name is fully set.
An alternative approach, which would be more efficient in this case, is to set the default EVM address for `nick.eth` on the latest [public resolver](/resolvers/public), and the default reverse record to `nick.eth` on the default reverse registrar. This would allow the name to resolve to the correct address on all chains.
### Getting a Primary Name
:::info
**Important**: After retrieving a name from reverse resolution, you **must** verify it by performing a forward resolution on that name to confirm it still resolves to the original address. This prevents spoofing or misconfiguration. If the addresses don't match, display the original address instead of the name. Most libraries will handle this for you.
:::
Looking up a users L1 primary name is very simple. In most web3 libraries (wagmi, viem, ethers, web3py, etc.), you will find a built-in function to do a lookup by address as shown below. In most cases, the library will handle the verification for you.
Remember that in all cases, ENS resolution always starts from Ethereum Mainnet.
:::code-group
```tsx [Wagmi]
// https://wagmi.sh/react/hooks/useEnsName
import { useEnsName } from 'wagmi'
import { mainnet } from 'wagmi/chains'
export const Name = () => {
const { data: name } = useEnsName({
address: '0xb8c2C29ee19D8307cb7255e1Cd9CbDE883A267d5',
chainId: mainnet.id, // resolution always starts from L1
})
return <div>Name: {name}</div>
}
```
```ts [Ethers v5]
const address = '0xb8c2C29ee19D8307cb7255e1Cd9CbDE883A267d5';
const name = await provider.lookupAddress(address);
// Always verify the forward resolution
if (name) {
const resolvedAddress = await provider.resolveName(name);
if (resolvedAddress !== address) {
// If verification fails, use the original address
return address;
}
}
```
```ts [Viem]
// https://viem.sh/docs/ens/actions/getEnsName.html
import { publicClient } from './client'
const ensName = await publicClie프로젝트로 돌아가기