# Add your own Custom Resolver

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

## Step 1. Extend ResolverService class

Please see GitHub for sources [here](https://github.com/e2xlabs/redefined-name-resolver-js/blob/master/src/services/resolvers/resolver.service.ts)

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

Example:

```typescript
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:

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

Or combine it with existing built-in resolver services:

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

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

```typescript
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 [GitHub](https://github.com/e2xlabs/redefined-name-resolver-js) and help the community!


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://redefined.gitbook.io/connect/integerate-redefined/add-your-own-custom-resolver.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
