Skip to content

Instantly share code, notes, and snippets.

@developerkunal
Created May 15, 2023 18:06
Show Gist options
  • Save developerkunal/9884636cf15d998044a4f86f11079e1a to your computer and use it in GitHub Desktop.
Save developerkunal/9884636cf15d998044a4f86f11079e1a to your computer and use it in GitHub Desktop.
Revolutionizing Address Resolution: EIP 181 and ENS Support for Reverse Resolution
// SPDX-License-Identifier: GPL-3.0
pragma solidity ^0.8.0;
contract ReverseResolver {
// Mapping from Ethereum addresses to human-readable names.
mapping(address => string) private addressToName;
mapping(string => address) private nameToAddress;
// Function to set the human-readable name for an Ethereum address.
function setAddressName(address _address, string memory _name) public {
require(_address != address(0), "Invalid address");
require(bytes(_name).length > 0, "Name cannot be empty");
addressToName[_address] = _name;
nameToAddress[_name] = _address;
}
// Function to get the human-readable name for an Ethereum address.
function getAddressName(address _address) public view returns (string memory) {
return addressToName[_address];
}
// Function to get the Ethereum address for a human-readable name.
function getNameAddress(string memory _name) public view returns (address) {
return nameToAddress[_name];
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment