redefined : Connect
WebsiteSupport
  • >_ introduction
    • Overview
      • Why redefined?
      • Use Cases
      • FAQ
  • >_ User Starter Guide
    • How does it work ?
      • Interact from any chain
      • Username registration
      • Email registration
      • Manage
      • Send
      • Referral
  • >_ Dev Integration Guide
    • Showcase
    • redefined API
      • Introduction
      • Resolve Usage
      • Reverse Resolve Usage
      • Migration from expiresAt to fetchedAt (optimistic results)
    • redefined SDK
      • Usage
      • Customization
      • Set your own Node URLs
    • redefined Widget
      • Usage
      • Customization
    • Supported networks
    • Supported providers
    • Add your own Custom Resolver
  • >_ Links
    • Website
    • Brand Kit
    • Medium
    • Substack
    • Audit
    • Discord
    • Twitter
    • Telegram
Powered by GitBook
On this page
  • Step 1. Extend ResolverService class
  • Step 2. Register your ResolverService in RedefinedResolver
  • Step 3. Implement SupportReverse interface if your resolver is capable of domain lookup by address
  • Contribute!
  1. >_ Dev Integration Guide

Add your own Custom Resolver

We are committed to continuous improvement

PreviousSupported providers

Last updated 1 year ago

You can implement your resolver service and add pass it to RedefinedResolver.

Step 1. Extend ResolverService class

Please see GitHub for sources

export abstract class ResolverService {
    abstract vendor: ResolverVendor;
    abstract resolve(domain: string, options?: ResolverServiceOptions, networks?: string[]): Promise<Account[]>;
}

Example:

export class KeyValueResolverService extends ResolverService {

    vendor: ResolverVendor = "keyvalue"
    
    registry = {
        "ivan": "0x1",
        "stepan": "0x2",
        "andrey": "0x3",
    }

    async resolve(domain: string, { throwErrorOnInvalidDomain }: ResolverServiceOptions = defaultResolverServiceOptions): Promise<Account[]> {
        const address = registry[domain];
        return address ? [{ address, network: "evm", from: this.vendor }] : [];
    }
}

Step 2. Register your ResolverService in RedefinedResolver

Initialize RedefinedResolver with your ResolverService only:

const resolver = new RedefinedResolver({
      resolvers: [new KeyValueResolverService()]
});

Or combine it with existing built-in resolver services:

const resolver = new RedefinedResolver({
      resolvers: [
            ...RedefinedResolver.createRedefinedResolvers(),
            new KeyValueResolverService(),
      ]
});

Step 3. Implement SupportReverse interface if your resolver is capable of domain lookup by address

export class KeyValueResolverService extends ResolverService implements SupportReverse {

    get vendor(): ResolverVendor {
        return "keyvalue";
    }

    async reverse(address: string): Promise<ReverseAccount[]> {
        try {
            return [{
                domain: "example",
                from: this.vendor
            }]
        } catch (e: any) {
            throw Error(`KeyValue Error: ${e.message}`);
        }
    }
}

Contribute!

Open a pull request with your new ResolverService in our and help the community!

here
GitHub