PNS
  • PNS: Your Identity in Polkadot
  • Summary
  • Advanced Topics
  • Contributing
  • Core Concepts
  • FAQ & Troubleshooting
  • PNS Troubleshooting Guide
  • PNS User Guide
  • advanced-topics
    • Contract Deployments
    • Custom Resolvers
    • Custom Top-Level Domain (TLD) Registration
    • Subdomain Management
  • contributing
    • GitHub Workflow
    • Contribution Guidelines
    • Issue Reporting
  • faq
    • Common Issues
    • Technical FAQ
Powered by GitBook
On this page
  • Overview
  • Implementation Example
  • Deployment and Setup
  1. advanced-topics

Custom Resolvers

Overview

Custom resolvers allow you to implement specialized resolution logic and store additional data for domains.

Implementation Example

// Custom resolver with social media handles
contract SocialMediaResolver {
    PNS pns;
    mapping(bytes32 => string) twitter;
    mapping(bytes32 => string) github;
    
    constructor(PNS _pns) {
        pns = _pns;
    }
    
    modifier onlyOwner(bytes32 node) {
        require(pns.owner(node) == msg.sender);
        _;
    }
    
    function setTwitter(bytes32 node, string calldata handle) 
        external 
        onlyOwner(node) 
    {
        twitter[node] = handle;
    }
    
    function setGithub(bytes32 node, string calldata profile)
        external
        onlyOwner(node)
    {
        github[node] = profile;
    }
}

Deployment and Setup

  1. Deploy Custom Resolver

const customResolver = await SocialMediaResolver.deploy(
    PNS_REGISTRY_ADDRESS
);
  1. Set Resolver for Domain

// Through PNS Registry
await pnsRegistry.setResolver(
    namehash("domain.dot"), 
    customResolver.address
);
  1. Configure Records

await customResolver.setTwitter(
    namehash("domain.dot"),
    "@handle"
);
PreviousContract DeploymentsNextCustom Top-Level Domain (TLD) Registration

Last updated 3 days ago