LogoLogo
  • Introduction
    • Terminology
  • Frequently Asked Questions
  • Domains Deployments
  • Registrar Frequently Asked Questions
  • Deploying Domains on a Private Chain
  • DNS Registrar guide
  • Domains Improvement Proposals
    • DomainsIP-1: Domains
    • DomainsIP-2: Initial Hash Registrar
    • DomainsIP-3: Reverse Resolution
    • DomainsIP-4: Support for contract ABIs
    • DomainsIP-5: Text Records
    • DomainsIP-6: DNS-in-Domains
    • DomainsIP-7: Interface Discovery
    • DomainsIP-8: Multichain Address Resolution
    • DomainsIP-9: Wildcard Resolution
    • DomainsIP-10: EVM compatible Chain Address Resolution
    • DomainsIP-11: Avatar Text Records
    • DomainsIP-12: SAFE Authentication for Domains
    • DomainsIP-13: On-chain Source Parameter
  • DAPP DEVELOPER GUIDE
    • Domains Enabling your DApp
    • Domains Libraries
    • Working with Domains
    • Resolving Names
    • Managing Names
    • Registering & Renewing Names
    • Domains Front-End Design Guidelines
    • Domains AS NFT
    • Domains Layer2 and offchain data support
    • Domains Data guide
  • CONTRACT API REFERENCE
    • Name Processing
  • Registry
  • ReverseRegistrar
  • TestRegistrar
  • PublicResolver
  • .tomi Permanent Registrar
    • Registrar
    • Controller
  • DNS Registrar
  • Subgraph
    • Query Examples
  • CONTRACT DEVELOPER GUIDE
    • Resolving Names On-chain
    • Writing a Resolver
    • Writing a Registrar
    • TOMI DISCUSSION FORUM
    • TOMI SUPPORT CHAT
  • TOMI MIGRATION (FEBRUARY 2020)
    • Guide for DApp Developers
    • Technical Description
Powered by GitBook
On this page
  1. CONTRACT DEVELOPER GUIDE

Writing a Registrar

A registrar in Domains is simply any contract that owns a name, and allocates subdomains of it according to some set of rules defined in the contract code. A trivial first in first served contract is demonstrated below:

contract FIFSRegistrar {
    ENS ens;
    bytes32 rootNode;

    function FIFSRegistrar(address ensAddr, bytes32 node) {
        ens = ENS(ensAddr);
        rootNode = node;
    }

    function register(bytes32 subnode, address owner) {
        var node = sha3(rootNode, subnode);
        var currentOwner = ens.owner(node);

        if (currentOwner != 0 && currentOwner != msg.sender) throw;

        ens.setSubnodeOwner(rootNode, subnode, owner);
    }
}

You may wish to set custom rules for the allocation of new names to your users; the rules you set are entirely up to you.

You should also bear in mind that as long as you retain ownership of the parent name - either directly or through another contract - your users have no guarantee that you will not take back ownership of their names and change what they resolve to. You may wish to consider committing ownership of the name to a contract that restricts your ability to control it.

PreviousWriting a ResolverNextGuide for DApp Developers

Last updated 1 year ago