How do I return ENS name in solidity?

Hi, I am currently trying to get an ENS name via wallet address using solidity code and I am struggling to make it work. Here is the code shown below:

pragma solidity ^0.8.0;

import "@ensdomains/ens-contracts/contracts/registry/ENS.sol";
import "@ensdomains/ens-contracts/contracts/reverseRegistrar/ReverseRegistrar.sol";
import "@ensdomains/ens-contracts/contracts/resolvers/PublicResolver.sol";

contract ENSLookup {
    ENS ens;
    ReverseRegistrar reverseRegistrar;

    constructor(address ensAddr, address reverseRegistrarAddr) {
        ens = ENS(ensAddr);
        reverseRegistrar = ReverseRegistrar(reverseRegistrarAddr);
    }

    function getENSName(address addr) public view returns (string memory) {
        // Get the node of the reverse ENS domain
        bytes32 node = reverseRegistrar.node(addr);

        // Use the ENS registry to get the resolver for this node
        PublicResolver resolver = PublicResolver(ens.resolver(node));

        // Use the resolver to get the name
        return resolver.name(node);
    }
}

I have attached the ens name to my address already and it displays the following error:

transact to ENSLookup.getENSName errored: Error occured: revert.

revert The transaction has been reverted to the initial state. Note: The called function should be payable if you send value and the value you send should be less than your current balance. Debug the transaction to get more information

I have attached the documentation for the registry addresses for the testnets in the link shown below. I am using goerli. https://docs.ens.domains/ens-deployments.

Is there anything that you can do to help me fix this issue? Your help would be really appreciated. Thanks

This function (getENSName) performs 3 external function calls on 3 different contracts:

  1. Calling function node on contract ReverseRegistrar
  2. Calling function resolver on contract ENS
  3. Calling function name on contract PublicResolver

In order to address your question, some more details are necessary, specifically:

  • Your contract takes the addresses of contract ENS and contract ReverseRegistrar as input upon its deployment (i.e., in the constructor); what input values have you passed to it, and are they indeed the addresses of these contracts on the goerli network?
  • Which one exact is contract ENS in the official documentation that you've linked in your question?

Your transaction hashes (contract deployment AND getENSName function call) might be useful for answering both of these questions, as well as for answering your own question.

Goerli Registry Address: 0x00000000000C2E074eC69A0dFb2997BA6C7d2e1e
Goerli Reverse Registrar Address: 0x4f7A657451358a22dc397d5eE7981FfC526cd856

These are both of the addresses I used as the variables ens and reverseRegistrar respectively in the constructor.

What about the input value passed to function getENSName? (I admit I forgot to list that as one of the missing details, but you should nevertheless post all the relevant information if you're hoping for this process to be efficient).

And by the way, you can probably find the answer to your question pretty easily yourself:

  1. Go to contract ReverseRegistrar, and call function node with your input to function getENSName
  2. Go to contract ENSRegistry, and call function resolver with the output of function node
  3. Check if the output of function resolver is indeed the address of contract PublicResolver

The input value to function getENSName is my wallet address. Cannot give you the exact value of my address.

Well, why is that? A wallet address is just a wallet address, it's not like anyone reading this thread (me included) has anything malicious that they can to with this information. Sounds like you are not very much familiar with what information in the ecosystem is safe being posted publicly and what isn't.
I can easily see your wallet address on the transaction list of those contracts, for example, on goerli.etherscan.io (along with the address of every other wallet who has ever executed a transaction on one of these contracts). In either case, you can follow my other comment and find out for yourself.