[Go to site: main page, start]

Skip to content

Nostrify with Welshman

Welshman is a Nostr library by Coracle.

It uses a powerful relay selection algorithm to choose the best relays for each request, enabling outbox support and more.

WARNING

Welshman is still in development and may not be stable.

Installation

You will need the @nostrify/welshman package.

sh
npm install @nostrify/welshman
sh
yarn add @nostrify/welshman
sh
pnpm add @nostrify/welshman
sh
bun add @nostrify/welshman

Usage

The NWelshman class is a relay pool that accepts a Welshman Router object.

ts
import { NWelshman } from '@nostrify/welshman';

const pool = new NWelshman(router);

Router

The Router class comes from Welshman itself. Here is a template to get you started:

ts
import { RelayMode, Router } from '@welshman/util';

const router = new Router({
  getUserPubkey: (): string | null => null,
  getGroupRelays: (address: string): string[] => [],
  getCommunityRelays: (address: string): string[] => [],
  getPubkeyRelays: (pubkey: string, mode?: RelayMode): string[] => [],
  getStaticRelays: (): string[] => [],
  getIndexerRelays: (): string[] => [],
  getSearchRelays: (): string[] => [],
  getRelayQuality: (url: string): number => 1,
  getRedundancy: (): number => 2,
  getLimit: (): number => 10,
});

See a detailed explanation of each option here.

Soapbox