I would like to create a Smart Contract that implements a name service.

It will allow anyone to register a name. Once a name is registered and associated with an address, it belongs to that address. The name can be associated with a string value, and its value can be changed by the owner. The owner can also transfer the name to a different owner. To avoid front-running, the first registration for a name follows a commit-reveal scheme.

So far I have this code in solidity.

pragma solidity >=0.5.0 < 0.6.0;
contract NameService {
   uint256 _reservePrice;

   struct addresses{
    address addr;
    bytes32 value;

   mapping(bytes32 => addresses) data;

   // constructor
   constructor(uint256 reservePrice) public {
       _reservePrice = reservePrice;

   function transferTo(bytes32 name, address newOwner) public {
        data[name].addr = newOwner;

   function setValue(bytes32 name, bytes32 value) public {
        data[name].value = value;


   function getValue(bytes32 name) public view returns (bytes32) {
        return data[name].value;

   function commitToName(bytes32 commitment) public payable {

   function registerName(bytes32 nonce, bytes32 name, bytes32 value) public {
        setValue(name, value);
        makeCommitment(nonce, name, msg.sender);

   function getOwner(bytes32 name) public view returns(address) {
        return data[name].addr;

   // Commitment utility
   function makeCommitment(bytes32 nonce, bytes32 name, address sender) public pure returns(bytes32) {
       return keccak256(abi.encodePacked(nonce, name, sender));

For now it compiles in remix, but I don't know how to use makeCommitment in commitToName. Is everything ok? And how do I continue?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.