Skip to main content
The TestRegistrar is a registrar contract designed for testing ENS functionality on Ethereum test networks. It allocates subdomains to the first person to claim them, with automatic expiration after a fixed period.

Overview

TestRegistrar provides:
  • First-come-first-served subdomain registration for testing
  • Automatic expiration after 4 weeks (28 days)
  • Re-registration capability after expiration by anyone
  • Simple registration without payment or complex logic
  • Currently deployed on test networks under the .test TLD

Import

import '@ensdomains/ens-contracts/contracts/registry/TestRegistrar.sol';

Constructor

constructor(ENS ensAddr, bytes32 node)
Creates a new test registrar.
ensAddr
ENS
required
The address of the ENS registry
node
bytes32
required
The node that this registrar administers (typically the .test TLD)

Constants

registrationPeriod

uint256 constant registrationPeriod = 4 weeks
The fixed period for which registrations are valid (28 days).

State Variables

ens

ENS public immutable ens
Reference to the ENS registry contract.

rootNode

bytes32 public immutable rootNode
The parent node that this registrar has authority over.

expiryTimes

mapping(bytes32 => uint256) public expiryTimes
Maps label hashes to their expiration timestamps.

Functions

register

function register(bytes32 label, address owner) public
Registers a name that’s not currently registered or has expired.
label
bytes32
required
The hash of the label to register (e.g., keccak256(‘testname’))
owner
address
required
The address of the new owner
This function will revert if the name is currently registered and hasn’t expired yet (expiryTimes[label] >= block.timestamp).
Behavior:
  1. Checks if the current timestamp is greater than or equal to the expiry time
  2. Sets a new expiry time to block.timestamp + 4 weeks
  3. Creates the subdomain with the specified owner via ens.setSubnodeOwner()

How It Works

  1. Anyone can register an available subdomain by calling register()
  2. The registration is valid for exactly 4 weeks from the registration timestamp
  3. After expiration, anyone can re-register the name (including the previous owner)
  4. There’s no mechanism to extend registration - names must be re-registered after expiration

Usage Examples

import '@ensdomains/ens-contracts/contracts/registry/TestRegistrar.sol';

contract TestRegistrarExample {
    TestRegistrar public registrar;

    constructor(TestRegistrar _registrar) {
        registrar = _registrar;
    }

    function claimTestName(string memory label) public {
        bytes32 labelHash = keccak256(bytes(label));
        
        // Register the name for the caller
        // Will expire in 4 weeks
        registrar.register(labelHash, msg.sender);
        
        // Caller now owns label.test for 4 weeks
    }
}

Deployment Information

The TestRegistrar is currently deployed on Ethereum test networks to facilitate testing:
  • Manages the .test TLD
  • Allows developers to easily claim test names
  • Automatic expiration prevents name squatting on test networks
  • No cost beyond gas fees

Use Cases

Development Testing

Quickly claim test names for development:
// Register myproject.test for testing
const label = ethers.utils.keccak256(ethers.utils.toUtf8Bytes('myproject'));
await testRegistrar.register(label, myAddress);

Integration Tests

Claim temporary names in your test suite:
it('should register a test name', async () => {
  const label = ethers.utils.keccak256(ethers.utils.toUtf8Bytes('testname'));
  await testRegistrar.register(label, owner.address);
  
  const subnode = ethers.utils.namehash('testname.test');
  expect(await ens.owner(subnode)).to.equal(owner.address);
});

Temporary Demo Names

Create temporary names for demos that automatically expire:
  • demo.test - expires in 4 weeks
  • prototype.test - expires in 4 weeks
  • showcase.test - expires in 4 weeks

Comparison with FIFSRegistrar

Unlike the FIFSRegistrar:
  • TestRegistrar includes automatic expiration (4 weeks)
  • TestRegistrar allows anyone to re-register expired names
  • TestRegistrar tracks expiry times in a public mapping
  • FIFSRegistrar provides permanent registration

Limitations

  • Names expire after exactly 4 weeks - no extension mechanism
  • Anyone can claim your name after it expires
  • Not suitable for production use - designed for test networks only
  • No ownership protection after expiration
  • Vulnerable to frontrunning on re-registration

Best Practices

  • Only use on test networks, never in production
  • Monitor expiry times if you need to maintain control of a name
  • Re-register before expiration if you need to keep the name
  • Remember that test names are temporary by design

Build docs developers (and LLMs) love