using Solidity in a smart contract, how is the namehash computed from name ("foo.eth") ?


1 Answer 1


formal specifications on https://eips.ethereum.org/EIPS/eip-137

function computeNamehash(string _name) public pure returns (bytes32 namehash) {
  namehash = 0x0000000000000000000000000000000000000000000000000000000000000000;
  namehash = keccak256(
  abi.encodePacked(namehash, keccak256(abi.encodePacked('eth')))
  namehash = keccak256(
  abi.encodePacked(namehash, keccak256(abi.encodePacked(_name)))
  • It's almost certainly best to calculate this off-chain and pass in a namehash instead. But if you must take this approach, do not forget the normalization step from the EIP: "Each label must be a valid normalised label as described in UTS46 with the options transitional=false and useSTD3AsciiRules=true. For Javascript implementations, a library is available that normalises and checks names."
    – carver
    Jul 17, 2018 at 23:23
  • The question is how to calculate it on-state. Feel free to write an answer to the question.
    – conS
    Jul 18, 2018 at 10:48

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