Skip to content

Instantly share code, notes, and snippets.

@JonasLoos
Created March 7, 2022 11:59
Show Gist options
  • Save JonasLoos/7efa759eec5984445d19275bf9a91638 to your computer and use it in GitHub Desktop.
Save JonasLoos/7efa759eec5984445d19275bf9a91638 to your computer and use it in GitHub Desktop.
exemplary implementation of a fully decentralized ENS alternative
// SPDX-License-Identifier: MIT
// exemplary implementation of a fully decentralized ENS alternative
// The ENS was described as partly centralized (root node controlled by ENS founders), while there is no fully decentralized solution yet.
// Couldn't we simply create a smart contract for the registry which has no owners and provides name-register functionality via a public function?
// To avoid spam and cluttering of the namespace, name-registrations have an expiration date and a cost depending on the duration (e.g. fixed 0.01Eth per month or dynamically adjusting with count of exiting registrations).
// If we want to have a separation between "TLD"s and "subdomains", we can just have one of these smart contracts for each TLD and one for the root (which is read only).
pragma solidity ^0.8.10;
contract ENS_alternative {
mapping (string => address) public destinations;
mapping (string => uint) public expiration_times;
mapping (string => address) public owners;
uint constant costMultiplyer = 42;
function register(string calldata name, address destination) external payable {
// only register if the name wasn't registered before or is expired or the owner want to change it
if (expiration_times[name] == 0 || expiration_times[name] < block.timestamp || owners[name] == msg.sender) {
destinations[name] = destination;
expiration_times[name] = block.timestamp + msg.value * costMultiplyer;
owners[name] = msg.sender;
}
}
// TODO
// * adjust costMultiplyer to some sane value or e.g. dynamically based on count of existing registrations
// * use a read-one version of this contract for the root contract, where all "TLD"s are predefined. Each TLD is managed by one instance of this contract.
// * don't void existing paid expiration_time when a name is updated by its owner.
// * maybe remove old expired mappings
// * maybe rather use a hash of the name for mapping instead of the name itself
// * maybe more functionality
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment