Skip to content

Latest commit

 

History

History
51 lines (39 loc) · 1.56 KB

README.md

File metadata and controls

51 lines (39 loc) · 1.56 KB

GitHub license npm version

mns-contracts

mns-contracts is an update/port of ens-contracts made to work for the Metrix Name Service and MetrixCoin blockchain.

Installation

npm install --save @metrixnames/mns-contracts

Example Usage

// SPDX-License-Identifier: MIT

pragma solidity ^0.8.4;

import "@metrixnames/mns-contracts/contracts/registry/MNS.sol";

contract HelloRegistrar {
    MNS mns;
    bytes32 rootNode;

    modifier only_owner(bytes32 label) {
        address currentOwner = mns.owner(
            keccak256(abi.encodePacked(rootNode, label))
        );
        require(currentOwner == address(0x0) || currentOwner == msg.sender);
        _;
    }

    /**
     * Constructor.
     * @param mnsAddr The address of the MNS registry.
     * @param node The node that this registrar administers.
     */
    constructor(MNS mnsAddr, bytes32 node) {
        mns = mnsAddr;
        rootNode = node;
    }

    /**
     * Register a name, or change the owner of an existing registration.
     * @param label The hash of the label to register.
     * @param owner The address of the new owner.
     */
    function register(bytes32 label, address owner) public only_owner(label) {
        mns.setSubnodeOwner(rootNode, label, owner);
    }
}