I am using kornrunner/php-keccak and I am attempting to do a "reverse lookup" on an ENS name, essentially the same as this question which was never answered. Any thoughts?

Here's my attempt thus far(just trying to hardcode values for now until I can get the right output and then make it dynamic):

    error_reporting(E_ALL ^ E_WARNING);
    require __DIR__ . '/vendor/autoload.php';

    use kornrunner\Keccak;

    function namehash(){
        $address = Keccak::hash(Keccak::hash('eth', 256) . Keccak::hash('0x0000000000000000000000000000000000000000000000000000000000000000' . Keccak::hash('vitailk', 256), 256), 256);

        return '0x' . $address;

    echo namehash();

This results in: 0x267da6af1e43febb9f45470d33bc49a1226840a1f63d387caa402ba7a298a0be

But what I am expecting is: 0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045

1 Answer 1


The namehash for vitalik.eth is 0xee6c4522aab0003e8d14cd40a6af439055fd2577951148c14b6cea9a53475835

In your code example there is a typo. The namehash for vitailk.eth is 0xc44dedd48981fda973d391cc14414c3a0cafd3aa6c9ba4d43ba78fa1039789db.

You can generate namehashes (and other ENS related hashes) here. Disclaimer: EthTools.com is my site.

To generate a namehash in PHP using php-keccak (as in your question) your code would look like the following:

    //The base namehash for '' - 0000000000000000000000000000000000000000000000000000000000000000
    $baseNamehash = hex2bin("0000000000000000000000000000000000000000000000000000000000000000");

    //The labelhash for 'eth' - 4f5b812789fc606be1b3b16908db13fc7a9adf7ca72641f84d75b47069d3d7f0
    $ethLabelhash = hex2bin(\kornrunner\Keccak::hash("eth", 256));

    //The namehash for 'eth' - 93cdeb708b7545dc668eb9280176169d1c33cfd8ed6f04690a0bcc88a93fc4ae
    $ethNamehash = \kornrunner\Keccak::hash($baseNamehash . $ethLabelhash, 256); 

    //The labelhash for vitalik - af2caa1c2ca1d027f1ac823b529d0a67cd144264b2789fa2ea4d63a67c7103cc
    $vitalikLabelhash = hex2bin(\kornrunner\Keccak::hash("vitalik", 256));

    //The namehash for vitalik.eth - ee6c4522aab0003e8d14cd40a6af439055fd2577951148c14b6cea9a53475835
    $vitalikNamehash = \kornrunner\Keccak::hash(hex2bin($ethNamehash) . $vitalikLabelhash, 256);

Your question is not clear though - your function is named namehash and it looks like you are trying to generate a namehash, but your question implies that you want to do a reverse lookup on a name. Reverse resolution requires interfacing with the ENS contracts on the blockchain. I'd recommend you read the documentation on reverse resolution to learn how to do that.

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.