Description:
Smart contract deployed on Ethereum.
Blockchain: Ethereum
Source Code: View Code On The Blockchain
Solidity Source Code:
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
contract ENSNamehash {
// Implements ENS namehash calculation
function namehash(string memory name) public pure returns (bytes32) {
bytes32 node;
if (bytes(name).length == 0) {
return 0x0;
}
node = 0x0; // initialize root node
return _namehash(name);
}
function _namehash(string memory name) internal pure returns (bytes32) {
bytes memory b = bytes(name);
uint lastDot = b.length;
bytes32 node = 0x0;
while (lastDot > 0) {
uint i = lastDot;
while (i > 0 && b[i-1] != ".") {
i--;
}
bytes memory label = new bytes(lastDot - i);
for (uint j = i; j < lastDot; j++) {
label[j - i] = b[j];
}
node = keccak256(abi.encodePacked(node, keccak256(label)));
lastDot = i > 0 ? i - 1 : 0;
}
return node;
}
}
Submitted on: 2025-09-19 16:04:10
Comments
Log in to comment.
No comments yet.