ENS + NFT + Emoji!!! 🤯🤯🤯

makoto_inoue
May 17 · 5 min read

The permanent registrar migration successfully completed on May the 4th and people started registering new names and migrating existing names.

There is no hurry to use the new registrar as the migration deadline is another year away but I would like to introduce a new feature so that you may be tempted to try out our new registrar as well as hack a new service which takes advantage of it.

ENS is now ERC721 compatible

From our doc page,

In addition, the registrar is an ERC721 compliant nonfungable token contract, meaning that .eth registrations can be transferred in the same fashion as other NFTs.

This brief description not only made some people very excited but fast moving service to jump onto the feature.

So how do you actually see your new shiny ENS name as NFT?

Some wallet (such as Balance Manager) supports NFT via OpenSea so it should appear in your wallet.

Here is my NFT collection on Balance Manager

You can also search ENS names from OpenSea directly which is very cool!

💩💩💩💩.eth

Kevin Owocki from Gitcoin recently tweeted that emoji is vital in meme campaign.

We got this, Kevin!

You can register unicode which means you can have emoji as ENS name.

Some savvy users already registered their killer emojis.

Emoji ENS name is NFT? This is a mind blowing combo!

One of the benefits of ENS being ERC721 compatible is that you can use your existing NFT dev knowledge. However, there are a few things which are unique to ENS based NFT (plus Emoji unicode quirks) you have to be aware of when hacking.

Developer FAQ

Q: How do you figure out the new ENS registrar address?

You can find it as a controller of eth domain at ENS manager. Rather than hard coding the address, I suggest fetching programatically. After instantiating an ENS registry object, you can ask the owner of .eth domain as follows in most ENS supported js libraries.

ens.owner('eth') 

Q: How do you find out if a given ENS name is ERC721 compatible?

The easiest way is to enquire the ENS registrar if the given name is available on the registrar as oppose to the old registrar which does not support ERC721. You can do so by calling Registrar.ownerOf(uint256 tokenId) (here is the exact line of the code).

If you are writing a service which handles both old and new registrar, then you can also use EIP-165 to introspect to the contract if it supports ERC 721 interfaces as follows.

Registrar.supportsInterface('0x6ccb2df4')

NOTE: These functions are less likely be supported by the ENS libraries, hence you may want to access to these smart contract directly.

Q: How do you find out tokenId ?

To transfer any tokens (and to lookup if the given ENS is ERC721 compatible), you need to specify tokenid. In our doc, it explains as follows.

The registrar works exclusively with label hashes — the keccak256 of the first component of the label (eg, keccak256('ens') for ens.eth). For compatibility with ERC721, these are expressed as uint256 values rather than bytes32, but can be cast backwards and forwards transparently.

Converting into labelhash iskeccak256('matoken') in Solidity and web3.utils.soliditySha3('matoken') in web3.js

That is usually enough to call the contract but if you need to convert to uint256 as used in OpenSea url structure, then you can use toBN.

web3.utils.toBN(bytes32).toString()
// returns 69845409642262400928105080645461410625829953013136762866921256534530425483455

NOTE: It is sometimes confusing whether you should pass label (eg: matoken) or full ENS name (eg: matoken.eth) as function arguments. When you interact with registry or resolver, you are more likely to pass ENS name as these contract is in charge of the whole ENS namespace. The registrar, however, is only in charge of the domain which the contract is the owner of, hence you can just pass a label.

Q: Can you register any emojis?

In theory yes, but in reality depends.

From our FAQ page,

Since the ENS contracts only deal with hashes, they have no direct way to enforce limits on what can be registered; character length restrictions are implemented by allowing users to challenge a short name by providing its preimage to prove it’s too short.

This means that you can in theory register both ‘foo.eth’ and ‘FOO.eth’, or even <picture of my cat>.eth. However, resolvers such as browsers and wallets should apply the nameprep algorithm to any names users enter before resolving; as a result, names that are not valid outputs of nameprep will not be resolvable by standard resolvers, making them effectively useless.

Got it 🤯 ? Let’s digest this sentence with an example.

For example, 👩‍❤️‍👨 is 6 characters . 👩‍❤‍👨 with 3 ZWJ characters (Zero Width Joiner, a Unicode character that joins two or more other characters together in sequence to create a new emoji) between them like following.

However, when we convert the character into namehash (a recursive process that can generate a unique hash for any valid domain name) before registering into ENS, normalise function will truncate one ZWJ character that creates the combined emoji hence will be treated as just 👩‍❤‍👨with 5 chars.

NOTE: Normalise does not seem to decompose all combined emojis. For example, rainbow flag is still intact after normalisation

With all being said, counting emoji length is as easy as the following

import { normalize } from ‘eth-ens-namehash’
[…normalize(“👩‍❤️‍👨”)].length // should return 5

Summary

In this blog post, I introduced how to interact with and develop ENS as NFT (+ encouraging the use of more emojis).

ETHGlobal ‘s next hackathon http://ethnewyork.com is coming up soon and I can’t wait to see some amazing hacks there! I will be giving ENS integration workshop on the first night so please come along if you are going to participate.

12:00am, not 12:00pm , not for faint hearted

The Ethereum Name Service

The official source for news related to the Ethereum Name Service (ENS). Follow this publication for the latest ENS developments.

makoto_inoue

Written by

http://makoto.github.io/me

The Ethereum Name Service

The official source for news related to the Ethereum Name Service (ENS). Follow this publication for the latest ENS developments.