using Solidity in a smart contract, how is the namehash computed from name ("foo.eth") ?
Asked
Active
Viewed 1,196 times
1 Answers
2
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)))
);
}
conS
- 31
- 4
-
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 '18 at 23:23
-
The question is how to calculate it on-state. Feel free to write an answer to the question. – conS Jul 18 '18 at 10:48