ENSNamehash

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;
    }
}

Tags:
addr:0x50bf7c6700082c288ce4c3179c93ea99d8dc4c52|verified:true|block:23397296|tx:0x99331ff337d756132beb1a674008f574fdf145a260bd8c9b750ad089d37b7e2b|first_check:1758290566

Submitted on: 2025-09-19 16:02:48

Comments

Log in to comment.

No comments yet.