HomeCoinsChainlink (LINK)How the Ethereum Name Service (ENS) Works With Chainlink Data Feeds

How the Ethereum Name Service (ENS) Works With Chainlink Data Feeds

- Advertisement -

The Ethereum Name Service or ENS provides human-readable names for Ethereum addresses, offering Ethereum users and developers alike a simplified experience. With legible addresses, users can interact with smart contracts without the hassle of using long character hashes, which can be confusing and lead to mistakes.

Chainlink is moving toward using ENS as the source of truth for Data Feeds addresses. With this in mind, it is important to understand what ENS is and how it works.

What Is ENS?

ENS is a service that enables distributed, open, and extensible naming on the Ethereum blockchain. Or, to put it simply, it is a lookup service. ENS has a simple job: It maps human-readable names to machine-readable addresses. In this sense, it is similar to the Domain Name Service, or DNS, which replaces IP addresses with domain names. But rather than IP addresses, ENS replaces Ethereum addresses with human-readable names.

ENS provides a naming service for addresses, hashes, and other identifiers. Without ENS, users need to know the full 64-character address of a contract or wallet on the Ethereum blockchain in order to interact with it. 

ENS provides the ability to use human-readable addresses. These addresses can be used as domains, which enables domain hierarchy, meaning subdomains can be assigned to an ENS address.

What Does ENS Mean for Chainlink?

Top-level ENS domains are owned by smart contracts called registrars. These registrars supply the rules governing the allocation of subdomains. On the `.eth` top-level domain, Chainlink has collaborated extensively with ENS to provide the `data.eth` domain, which contains an identifiable index of Chainlink Price Feed addresses, making it easier to discover Chainlink oracle networks. This means developers are able to use human-readable addresses like `eth-usd.data.eth` in place of contract addresses such as `0x5f4eC3Df9cbd43714FE2740f5E3616155c5b8419`.

Using ENS in Javascript

Using ENS to resolve domain names is straightforward in Javascript libraries that support Web3. Using web3.js, this is as simple as

var address = ens.getAddress('eth-usd.data.eth');

Other libraries that support ENS can be found in the ENS documentation.

Crafting a Node Hash

​Things get more interesting when ENS addresses are used on-chain. 

The ENS documentation makes reference to node hashes. A node hash is constructed with a recursive algorithm that takes each component of the domain, separated by `.`s, and hashes them together. Based on the specifications for EIP-137 the pseudo-code for this algorithm is:

def namehash(name):
 if name == '':
   return '' * 32
 else:
   label, _, remainder = name.partition('.')
   return sha3(namehash(remainder) + sha3(label))

The name is split into its components, then, starting with the last component, concatenated together. The resulting node hash for `eth-usd.data.eth` would be created through the following steps.

node = '' * 32
node = sha3(node + sha3('eth'))
node = sha3(node + sha3('data'))
node = sha3(node + sha3('eth-usd'))

It is important to note that in order to produce the correct output from the hashing algorithm, the name must first be normalized. ENS requires that anyone using it must follow UTS46 for normalization and validation.

Given the complexity of this process, it is recommended to pass the node hash to a contract rather than computing it on-chain. The eth-ens-namehash npm package performs both the normalization and hashing for you.

Additionally, The Graph has an API available for finding data about ENS domains; `labelhash` is the specific field that contains this information, but there is also much more information available.

Resolving On-Chain

​Once the node hash for an ENS address has been defined, it can be used to resolve the contract address on-chain. Again, this is useful as, to the resolver, the node hash and the human-readable address are the same. The resolver acts as the source of truth for the address of the entity we are resolving. In this case, that would be one of the Chainlink Data Feeds.

In the on-chain Solidity contract, you would need to implement a couple of interfaces for the ENS contract and resolver.

abstract contract ENS {
   function resolver(bytes32 node) public virtual view returns (Resolver);
}

abstract contract Resolver {
   function addr(bytes32 node) public virtual view returns (address);
}

Once those interfaces have been defined, a simple resolver can be created to convert the node hash to an address.

contract MyContract {
   // This is the ENS registry address
   // It is the same address for Mainet, Ropsten, Rinkerby, Gorli and other networks;
   ENS ens = ENS(0x00000000000C2E074eC69A0dFb2997BA6C7d2e1e);

   function resolve(bytes32 node) public view returns(address) {
       Resolver resolver = ens.resolver(node);
       return resolver.addr(node);
   }
}

Wrapping Up

Chainlink has chosen to use ENS to act as a source of truth for Data Feeds addresses. ENS eliminates the need to use long addresses and helps ensure interactions occur with the correct blockchain address. To learn more about ENS and Chainlink, head to the Chainlink documentation.

Learn more about Chainlink by visiting chain.link or read the documentation at docs.chain.link. To discuss an integration, reach out to an expert.

Source link

- Advertisement -
Mr Bitcointehttps://www.bitcointe.com/
“Fact You Need To Know About Cryptocurrency - The first Bitcoin purchase was for pizza.” ― Mohsin Jameel
462FansLike
76FollowersFollow
4,567FollowersFollow
5,261FollowersFollow
1,583FollowersFollow
2,230SubscribersSubscribe

Most Popular

bitcoin
Bitcoin (BTC) $ 42,954.00
ethereum
Ethereum (ETH) $ 3,098.53
tether
Tether (USDT) $ 1.00
bitcoin-cash
Bitcoin Cash (BCH) $ 339.22
litecoin
Litecoin (LTC) $ 129.87
eos
EOS (EOS) $ 2.62
okb
OKB (OKB) $ 22.80
tezos
Tezos (XTZ) $ 4.01
leo-token
LEO Token (LEO) $ 5.02
cardano
Cardano (ADA) $ 1.19
monero
Monero (XMR) $ 176.95
stellar
Stellar (XLM) $ 0.234415
chainlink
Chainlink (LINK) $ 18.63
huobi-token
Huobi Token (HT) $ 10.15
tron
TRON (TRX) $ 0.068055
usd-coin
USD Coin (USDC) $ 1.00
dash
Dash (DASH) $ 112.13
neo
NEO (NEO) $ 23.53
iota
IOTA (MIOTA) $ 0.968277
nem
NEM (XEM) $ 0.116884
zcash
Zcash (ZEC) $ 126.75
maker
Maker (MKR) $ 2,213.30
paxos-standard
Pax Dollar (USDP) $ 1.00
ethereum-classic
Ethereum Classic (ETC) $ 32.78
vechain
VeChain (VET) $ 0.064376
true-usd
TrueUSD (TUSD) $ 1.00
ftx-token
FTX Token (FTT) $ 47.30
kucoin-shares
KuCoin Token (KCS) $ 20.53
waves
Waves (WAVES) $ 11.36