What if you want to use your mainnet ENS address on other chains?
In this example, we fetch data from mainnet to resolve an ENS address on chain, then store the results into a mapping. We deploy a custom ENSUtil contract on mainnet that combines registry.resolver(namehash).addr(namehash) into a single function, so we only need one cross chain call.
Extra logic could be added to the callback handler, to interact with the resolved address in some way.
pragmasolidity ^0.8.14;import {IERC721} from"openzeppelin/token/ERC721/IERC721.sol";import {TelepathyOracle} from"src/oracle/TelepathyOracle.sol";import {OracleCallbackBase} from"src/oracle/OracleCallbackBase.sol";import {ENSUtil} from"src/examples/ens/ENSUtil.sol";structRequest {address sender;bytes32 node;}structResolvedAddress {bool success;address addr;uint88 timestamp;}/// @title ENSQueryExample/// @notice Example contract that queries mainnet to resolve an ENS name on chaincontractENSQueryExampleisOracleCallbackBase {address ensUtil; TelepathyOracle oracle;/// @notice Maps oracle nonce to the address that requested the claim and the requested nodemapping(uint256=> Request) public requests;/// @notice Maps resolved ENS names to their addresses (could be outdated)mapping(bytes32=> ResolvedAddress) public addresses;constructor(address_oracle,address_ensUtil) OracleCallbackBase(_oracle) { oracle =TelepathyOracle(_oracle); ensUtil = _ensUtil; }functionsendQuery(bytes32_node) externalreturns (uint256) {uint256 nonce = oracle.requestCrossChain(address(ensUtil), abi.encodeWithSelector(ENSUtil.resolve.selector, _node),address(this) ); requests[nonce] =Request(msg.sender, _node);return nonce; }functionhandleOracleResponse(uint256_nonce,bytesmemory_responseData,bool_responseSuccess ) internaloverride {address resolved;if (_responseSuccess) { resolved = abi.decode(_responseData, (address)); }bytes32 node = requests[_nonce].node;delete requests[_nonce];// node => resolved addresses[node] =ResolvedAddress( _responseSuccess, resolved,uint88(block.timestamp) );// we can add extra effects here if desired }}