Ethereum Name Service 백서

Ethereum Name Service

원문

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

### Architecture #### Authorization Model The Chain Registry-Resolver uses a two-tier authorization model: ##### Contract Owner The contract owner can: * Register new chains * Update existing chain registrations * Upgrade the contract implementation * Set the default contenthash for the namespace ##### Chain Admin When an address is registered by the contract owner, an administrator address is specified. This is an address provided by the chain operators. The chain admin address can: * Modify text, data, contenthash, and address records for their chain * Transfer admin rights to another address #### Upgrades The Chain Registry-Resolver is deployed behind a [UUPS](https://docs.openzeppelin.com/contracts-stylus/uups-proxy) (Universal Upgradeable Proxy Standard) proxy. This allows the contract logic to be upgraded while preserving all stored chain data and maintaining a consistent contract address. #### Namespace Structure ``` on.eth (root namespace) ├── optimism.on.eth → Chain record storage ├── base.on.eth → Chain record storage ├── arbitrum.on.eth → Chain record storage ├── ... → Any number of chains can be registered └── reverse.on.eth → Reserved for reverse resolution ``` :::note The `reverse.on.eth` name is reserved to allow for the conversion of an [ERC-7930](https://eips.ethereum.org/EIPS/eip-7930) *Interoperable Address* to a chain label. ::: #### Resolver Profiles All established ENS Resolver profiles are implemented by the contract to allow for the resolution of: * Text Records ([ENSIP-5](/ensip/5)) * Contenthash ([ENSIP-7](/ensip/7)) * Addresses ([ENSIP-9](/ensip/9) / [ENSIP-11](/ensip/11)) * Arbitrary Data ([ENSIP-24](/ensip/24)) #### Immutable Records For a given chain, the `interoperable-address` data key is set upon chain registration, and is immutable. It references the [ERC-7930](https://eips.ethereum.org/EIPS/eip-7930) *Interoperable Address* for the chain in question. As an example, for `optimism.on.eth` the value is set to `0x00010000010a00`. #### Aliasing Chains can have multiple aliases that point to the canonical label. Aliases are transparent - resolution through an alias returns the same underlying data as the canonical label. For example: * `op.on.eth` → resolves the same underlying metadata as `optimism.on.eth` * `arb.on.eth` → resolves the same underlying metadata as `arbitrum.on.eth` ### Usage Guide #### Chain Discovery The registry is fully enumerable, allowing applications to discover all registered chains. :::note Enumerating all chains is an O(n) operation, which may become expensive as the registry grows to hundreds or thousands of chains. Applications are expected to perform a full enumeration once, cache the results locally, and then use `chainCount()` to detect new registrations for incremental updates. ::: :::code-group ```solidity [Solidity] interface IChainResolver { function chainCount() external view returns (uint256); function getChainAtIndex(uint256 index) external view returns ( string memory label, string memory name, bytes memory interoperableAddress ); } ``` ```ts [Typescript (viem)] const discoveryAbi = [ { name: 'chainCount', type: 'function', stateMutability: 'view', inputs: [], outputs: [{ name: '', type: 'uint256' }], }, { name: 'getChainAtIndex', type: 'function', stateMutability: 'view', inputs: [{ name: 'index', type: 'uint256' }], outputs: [ { name: 'label', type: 'string' }, { name: 'name', type: 'string' }, { name: 'interoperableAddress', type: 'bytes' }, ], }, ] as const // Get total number of registered chains const count = await client.readContract({ address: '0x...', abi: discoveryAbi, functionName: 'chainCount', }) // Enumerate all chains for (let i = 0; i < count; i++) { const [label, name, interopAddr] = await client.readContract({ address: '0x...', abi: discoveryAbi, functionName: 'getChainAtIndex', args: [BigInt(i)], }) console.log(`${label}: ${name} (${interopAddr})`) } ``` ::: #### Chain Metadata Discovery ##### Data Records The resolver implements the optional discoverability mechanism outlined in [ENSIP-24](/ensip/24). ```solidity /// @dev Interface selector: `0x29fb1892` interface ISupportedDataKeys { /// @notice For a specific `node`, get an array of supported data keys. /// @param node The node (namehash). /// @return The keys for which we have associated data. function supportedDataKeys(bytes32 node) external view returns (string[] memory); } ``` Calling `supportedDataKeys` for a given chain e.g. `optimism.on.eth` will return an array of keys for which data is defined. ##### Text Records The resolver also implements the discoverability mechanism for text records: ```solidity interface ISupportedTextKeys { /// @notice For a specific `node`, get an array of supported text keys. /// @param node The node (namehash). /// @return The keys for which we have associated text records. function supportedTextKeys(bytes32 node) external view returns (string[] memory); } ``` Calling `supportedTextKeys` for a given chain e.g. `optimism.on.eth` will return an array of keys for which text records are set. #### Resolving Chain Metadata As the resolver is set on the `on.eth` name, resolution for subnames is subject to the resolution process outlined in [ENSIP-10: Wildcard Resolution](/ensip/10). The calldata that you will pass to the `resolve` method of the `IExtendedResolver` interface is dependent on whether the metadata that you are fetching is stored as a data record or a text record. For data records (e.g. fetching an [ERC-7930](https://eips.ethereum.org/EIPS/eip-7930) *Interoperable Address*), use the `data(bytes32 node, string calldata key)` getter function defined in [ENSIP-24](/ensip/24). ```ts import { createPublicClient, http, encodeFunctionData, decodeFunctionResult, parseAbi, toHex } from 'viem' import { mainnet } from 'viem/chains' import { namehash, packetToBytes } from 'viem/ens' const client = createPublicClient({ chain: mainnet, transport: http(), }) const dataAbi = parseAbi([ 'function data(bytes32 node, string key) view returns (bytes)', ]) const resolveAbi = parseAbi([ 'function resolve(bytes name, bytes data) view returns (bytes)', ]) const name = 'optimism.on.eth' const dnsEncodedName = toHex(packetToBytes(name)) const node = namehash(name) // Encode the data() call for the interoperable-address key const calldata = encodeFunctionData({ abi: dataAbi, functionName: 'data', args: [node, 'interoperable-address'], }) // Call resolve() const result = await client.readContract({ address: '0x...', // Chain Registry-Resolver address abi: resolveAbi, functionName: 'resolve', args: [dnsEncodedName, calldata], }) // Decode the result const interopAddr = decodeFunctionResult({ abi: dataAbi, functionName: 'data', data: result, }) // Returns: 0x00010000010a00 ``` For text records (e.g. fetching an X handle), use the `text(bytes32 node, string key)` function defined in [ENSIP-5](/ensip/5) instead: ```ts const textAbi = parseAbi([ 'function text(bytes32 node, string key) view returns (string)', ]) const resolveAbi = parseAbi([ 'function resolve(bytes name, bytes data) view returns (bytes)', ]) const name = 'optimism.on.eth' const dnsEncodedName = toHex(packetToBytes(name)) const node = namehash(name) // Encode the text() call for the com.x key const calldata = encodeFunctionData({ abi: textAbi, functionName: 'text', args: [node, 'com.x'], }) // Call resolve() const result = await client.readContract({ address: '0x...', // Chain Registry-Resolver address abi: resolveAbi, functionName: 'resolve', args: [dnsEncodedName, calldata], }) // Decode the result const xHandle = decodeFunctionResult({ abi: textAbi, functionName: 'text', data: result, }) // Returns: "https://x.com/optimism" ``` ##### Using Direct Getters The resolver exposes helper functions that allow you to fetch frequently accessed chain metadata directly using the chain label, without needing to go through the ENSIP-10 resolution process. ```solidity interface IChainResolver { function interoperableAddress(string calldata label) external view returns (bytes memory); function chainName(string calldata label) external view returns (string memory); } ``` For other record types, use the generic getters: :::code-group ```solidity [Solidity] interface IChainResolver { function getText(string calldata label, string calldata key) external view returns (string memory); function getData(string calldata label, string calldata key) external view returns (bytes memory); function getAddr(string calldata label, uint256 coinType) external view returns (bytes memory); function getContenthash(string calldata label) external view returns (bytes memory); } ``` ```ts [Typescript (viem)] const directGetterAbi = [ { name: 'interoperableAddress', type: 'function', stateMutability: 'view', inputs: [{ name: 'label', type: 'string' }], outputs: [{ name: '', type: 'bytes' }], }, { name: 'chainName', type: 'function', stateMutability: 'view', inputs: [{ name: 'label', type: 'string' }], outputs: [{ name: '', type: 'string' }], }, { name: 'getText', type: 'function', stateMutability: 'view', inputs: [ { name: 'label', type: 'string' }, { name: 'key', type: 'string' }, ], outputs: [{ name: '', type: 'string' }], }, ] as const // Fetch the interoperable address for Optimism const interopAddr = await client.readContract({ address: '0x...', // Chain Registry-Resolver address abi: directGetterAbi, functionName: 'interoperableAddress', args: ['optimism'], }) // Returns: 0x00010000010a // Fetch the chain name for Optimism const name = await client.readContract({ address: '0x...', // Chain Registry-Resolver address abi: directGetterAbi, functionName: 'chainName', args: ['optimism'], }) // Returns: "Optimism" // Fetch the X handle for Optimism const xHandle = await client.readContract({ address: '0x...', // Chain Registry-Resolver address abi: directGetterAbi, functionName: 'getText', args: ['optimism', 'com.x'], }) // Returns: "https://x.com/optimism" ``` ::: #### Reverse Resolution Reverse resolution maps an [ERC-7930](https://eips.ethereum.org/EIPS/eip-7930) *Interoperable Address* back to its human-readable chain label. Reverse resolution data is stored as text records on the special subdomain, `reverse.on.eth`. The key format is `chain-label:` appended with the *Interoperable Address* you want to reverse. ```ts const textAbi = parseAbi([ 'function text(bytes32 node, string key) view returns (string)', ]) const reverseName = 'reverse.on.eth' const dnsEncodedReverse = toHex(packetToBytes(reverseName)) const reverseNode = namehash(reverseName) // The key is "chain-label:" + Interoperable Address without 0x prefix const textKey = 'chain-label:00010000010a00' const calldata = encodeFunctionData({ abi: textAbi, functionName: 'text', args: [reverseNode, textKey], }) const result = await client.readContract({ address: '0x...', abi: resolveAbi, functionName: 'resolve', args: [dnsEncodedReverse, calldata], }) const label = decodeFunctionResult({ abi: textAbi, functionName: 'text', data: result, }) // Returns: "optimism" ``` ##### Using Direct Getters The resolver exposes a helper function to achieve the same result. :::code-group ```solidity [Solidity] interface IChainResolver { function chainLabel(bytes calldata interoperableAddress) external view returns (string memory); } ``` ```ts [Typescript (viem)] const chainLabelAbi = [ { name: 'chainLabel', type: 'function', stateMutability: 'view', inputs: [{ name: 'interoperableAddress', type: 'bytes' }], outputs: [{ name: '', type: 'string' }], }, ] as const // Reverse resolve an interoperable address const label = await client.readContract({ address: '0x...', // Chain Registry-Resolver address abi: chainLabelAbi, functionName: 'chainLabel', args: ['0x00010000010a00'], }) // Returns: "optimism" ``` ::: ### Interface Reference #### Core Resolution ```solidity interface IChainResolver { // Container for canonical label information struct CanonicalLabelInfo { string label; bytes32 labelhash; } // Forward resolution function interoperableAddress(string calldata label) external view returns (bytes memory); function chainName(string calldata label) external view returns (string memory); // Reverse resolution function chainLabel(bytes calldata interoperableAddress) external view returns (string memory); // Discovery function chainCount() external view returns (uint256); function getChainAtIndex(uint256 index) external view returns ( string memory label, string memory name, bytes memory interoperableAddress ); // Record getters function getText(string calldata label, string calldata key) external view returns (string memory); function getData(string calldata label, string calldata key) external view returns (bytes memory); function getAddr(string calldata label, uint256 coinType) external view returns (bytes memory); function getContenthash(string calldata label) external view returns (bytes memory); // Alias resolution function getCanonicalLabel(string calldata _label) external view returns (CanonicalLabelInfo memory info); // ENSIP-10 wildcard resolution function resolve(bytes calldata name, bytes calldata data) external view returns (bytes memory); // Interface detection function supportsInterface(bytes4 interfaceId) external view returns (bool); } ``` #### Record management These functions are available to the respective chain operators for setting metadata about their blockchain. ```solidity interface IChainResolverAdmin { // Text records function setText(bytes32 labelhash, string calldata key, string calldata value) external; function batchSetText(bytes32 labelhash, string[] calldata keys, string[] calldata values) external; // Data records function setData(bytes32 labelhash, string calldata key, bytes calldata value) external; function batchSetData(bytes32 labelhash, string[] calldata keys, bytes[] calldata values) external; // Address records function setAddr(bytes32 labelhash, uint256 coinType, bytes calldata value) external; // Contenthash function setContenthash(bytes32 labelhash, bytes calldata contenthash) external; // Admin transfer function setChainAdmin(bytes32 labelhash, address newAdmin) external; } ``` ### Browsing Chain Metadata The default contenthash for the `on.eth` namespace references a simple decentralized website that resolves data from the on-chain registry-resolver. Using a service like eth.limo, you can interface with the registry by visiting [on.eth.limo](https://on.eth.limo). The metadata for a specific chain can be viewed through this user interface by accessing the specific subname directly. For example [base.on.eth.limo](https://base.on.eth.limo), or [optimism.on.eth.limo](https://optimism.on.eth.limo). ![Optimism Chain Metadata](/img/optimism-on-eth-contenthash-website.png) Metadata that is supported by the ENS App will also be displayed when the domain is looked up. For example: [https://app.ens.domains/optimism.on.eth](https://app.ens.domains/optimism.on.eth) ### Source Code The Chain Registry-Resolver source code is available on [GitHub](https://github.com/unruggable-labs/chain-resolver). ## Interacting with a Resolver \[Set Addresses, Text Records, and more] Some apps may want to allow for users to edit, update, or modify their name and its behaviour at a more advanced level. This is possible by interacting with the resolver contract of a name directly. ### Checking Interface Support Before you start sending transactions to users resolvers, you should check if they support the interface you want to use. This is done by calling the `supportsInterface` (see [EIP-165](https://eips.ethereum.org/EIPS/eip-165)) function on the resolver contract. ```solidity function supportsInterface(bytes4 interfaceID) external pure returns (bool) ``` In order to ensure that resolvers we interact with are compatible with specific standards you can call the above function on contracts with an interfaceID and then check the boolean it returns. Interface IDs are calculated according to solidity ABI and stored in a four-byte value. ### Updating a User's Record If you want to help a user set their avatar, specify a preferred color scheme, or set any other record on their ENS name you can do so in specific cases. First we need to <b>check if the user's resolver supports the interface</b> we want to use (see [setText](/resolvers/interfaces#0x10f13a8c)). Afterwhich you can call the `setText()` function on the user's resolver contract. :::code-group ```solidity [Solidity] interface Resolver { function setText(bytes32 node, string calldata key, string calldata value) external; } ``` ```typescript [ENSjs] // https://github.com/ensdomains/ensjs/blob/main/docs/wallet/function.setRecords.md import { addEnsContracts } from '@ensdomains/ensjs' import { setRecords } from '@ensdomains/ensjs/wallet' import { createWalletClient, custom } from 'viem' import { mainnet } from 'viem/chains' const wallet = createWalletClient({ chain: addEnsContracts(mainnet), transport: custom(window.ethereum), }) const hash = await setRecords(wallet, { name: 'ens.eth', coins: [ { coin: 'ETH', value: '0xFe89cc7aBB2C4183683ab71653C4cdc9B02D44b7', }, ], texts: [{ key: 'foo', value: 'bar' }], resolverAddress: '0x4976fb03C32e5B8cfe2b6cCB31c09Ba78EBaBa41', }) // 0x... ``` ::: Note that only the [Manager](/terminology#manager) of a name can set records on the resolver. For unwrapped names, the manager can be found by calling `owner()` on the ENS Registry. For wrapped names, the manager can be found by calling `ownerOf()` on the Name Wrapper. You can find the contract addresses [here](/learn/deployments#mainnet). ### Update a User's Resolver Overwriting a user's resolver involves overwriting the behaviour of their ENS name. To change the resolver of a name, the Manager must call `setResolver()` on either the ENS Registry or the Name Wrapper, depending on whether the name is wrapped or not. To figure out if a name is wrapped, call `owner()` on the ENS Registry. If this returns the address of the Name Wrapper, that indicates the name is wrapped and you should call `ownerOf()` on the Name Wrapper to get the effective owner of the name. You can find the contract addresses [here](/learn/deployments#mainnet). :::code-group ```solidity [Solidity] // Both the ENS Registry and the Name Wrapper implement this interface interface ENS { function setResolver(bytes32 node, address resolver) external; } ``` ```typescript [ENSjs] // https://github.com/ensdomains/ensjs/blob/main/docs/wallet/function.setResolver.md import { addEnsContracts } from '@ensdomains/ensjs' import { setResolver } from '@ensdomains/ensjs/wallet' import { createWalletClient, custom } from 'viem' import { mainnet } from 'viem/chains' const wallet = createWalletClient({ chain: addEnsContracts(mainnet), transport: custom(window.ethereum), }) const hash = await setResolver(wallet, { name: 'ens.eth', contract: 'registry', resolverAddress: '0x4976fb03C32e5B8cfe2b6cCB31c09Ba78EBaBa41', }) // 0x... ``` ::: Please do not change the resolver for a user without their permission. Overwriting the resolver is a destructive action and will overwrite any existing resolution logic. ### Layer 2 & Offchain Resolvers At the time of writing this the ecosystem around multichain and "writing" to layer 2 & offchain resolvers has yet to be standardized and is still under active development. Please check back at a later date. import { InterfaceDetails } from '../../components/InterfaceDetails' import { resolver_methods } from '../../data/resolver' ## Resolver Interface Standards This page is a collection of methods that a resolver MAY implement. <InterfaceDetails methods={resolver_methods} /> ## Public Resolver :::info Find the address of the latest public resolver on the [de
프로젝트로 돌아가기