Developers
TypeScript SDK

TypeScript SDK

The TypeScript SDK lets you build browser-based applications that communicate through the Nym mixnet.

┌──────────────────────────────────────────────────────────────┐
│  Your browser app                                            │
│       └─ Nym Mixnet Client (WASM, runs in a Web Worker)      │
│            └─ WebSocket to entry gateway                     │
│                 └─ Nym mixnet (entry → 3 mix layers → exit)  │
│                      └─ Peer MixnetClient (e.g. nym-sdk)     │
└──────────────────────────────────────────────────────────────┘

The Mixnet Client operates in messaging mode (text or binary payloads) and runs in a Web Worker to keep the UI thread free. For HTTP requests, use mix-fetch instead.

For an HTTP-over-mixnet fetch() replacement, see mix-fetch. This page covers the Mixnet Client (send / receive raw messages) and Smart Contracts (interact with the Nyx chain).

⚠️

The Nym Mixnet routes traffic through multiple nodes with no persistent connections or guaranteed ordering. The SDK abstracts the complexity, but understanding the underlying model helps when debugging.

Packages

Mixnet Client

Send and receive text and binary messages over the Nym mixnet

@nymproject/sdk
ESM

@nymproject/sdk-full-fat
ESM
pre-bundled

@nymproject/sdk-commonjs
CommonJS

@nymproject/sdk-full-fat-commonjs
CommonJS
pre-bundled

Nym Smart Contracts

Query and execute methods on the smart contracts that run the Nym mixnet

@nymproject/contract-clients
ESM

Which variant should I use?

All packages (except Contract Clients) come in four variants:

  • ESM: For new projects with current tooling. You may need to configure your bundler to handle WASM and web worker components.
  • ESM full-fat: Pre-bundled with inline WASM and web workers. No bundler config needed.
  • CommonJS: For older projects using CommonJS. WASM and web workers need to be bundled.
  • CommonJS full-fat: Pre-bundled, works without additional configuration.
⚠️

All *-full-fat variants have large bundle sizes because they include WASM and web workers as inline Base64 strings. Use the standard ESM variant if bundle size matters.

Installation

Mixnet Client

npm install @nymproject/sdk-full-fat

Nym Smart Contracts

npm install @nymproject/contract-clients @cosmjs/cosmwasm-stargate @cosmjs/proto-signing

Install everything

npm install @nymproject/contract-clients @cosmjs/cosmwasm-stargate @cosmjs/proto-signing @nymproject/sdk-full-fat

Quick start

Mixnet Client

Create a Mixnet Client (opens in a new tab) to send and receive messages through the mixnet:

import { createNymMixnetClient } from '@nymproject/sdk';
 
const nym = await createNymMixnetClient();
const nymApiUrl = 'https://validator.nymtech.net/api';
 
// Subscribe to incoming messages
nym.events.subscribeToTextMessageReceivedEvent((e) => {
  console.log('Got a message: ', e.args.payload);
});
 
// Connect to the mixnet
await nym.client.start({ clientId: 'my-app', nymApiUrl });
 
// Send a message to yourself
const recipient = nym.client.selfAddress();
nym.client.send({ payload: 'Hello mixnet', recipient });

Nym Smart Contracts

Use the Contract Clients (opens in a new tab) to query or execute on Nym smart contracts:

import { contracts } from '@nymproject/contract-clients';
import { SigningCosmWasmClient } from "@cosmjs/cosmwasm-stargate";
import { DirectSecp256k1HdWallet } from "@cosmjs/proto-signing";
 
const signer = await DirectSecp256k1HdWallet.fromMnemonic("...");
const accounts = await signer.getAccounts();
 
const cosmWasmSigningClient = await SigningCosmWasmClient.connectWithSigner(
  "https://rpc.nymtech.net:443", signer
);
const client = new contracts.Mixnet.MixnetClient(
  cosmWasmSigningClient,
  accounts[0].address,
  'n17srjznxl9dvzdkpwpw24gg668wc73val88a6m5ajg6ankwvz9wtst0cznr'
);
 
// Delegate 1 NYM to mixnode with id 100
const result = await client.delegateToMixnode(
  { mixId: 100 }, 'auto', undefined,
  [{ amount: `${1_000_000}`, denom: 'unym' }]
);
console.log(`Tx Hash = ${result.transactionHash}`);

Next steps