I am curious how you would implement a smart contract which registers a (sub)domain on ens. The documentations I have found all specify that ENS uses SHA3 to hash the domains. I thought Keecak256 was supposed to be the equivalent to SHA3. However, there are several questions in this forum (here, here and here) that prove the contrary. Also looking at the output from online hashes for keecak256 and sha3 I see different outputs for the same inputs.

Some pseudocode of how to implement the namehash algorithm I found here looks like this:

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

My understanding was so far, that Keecak256 in Solidity is supposed to have the same results as SHA3. So I would have implemented this namehash algorithm in Solidity like this but with Keecak256 instead of SHA3. Since this does not seem to yield the correct results though, what would be the proper implementation of this algorithm in Solidity?

1 Answer 1


SHA3 and Keccak256 are different hash algorithms. You can use the keccak256 function to hash labels in ENS. I believe the proper implementation of the namehash algorithm in Solidity is as follows:

ENS: how to compute namehash from name in a smart contract?


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.