Developers
Typescript SDK

TypeScript SDK

The TypeScript SDK lets you build browser-based applications that communicate through the Nym mixnet. Import SDK packages via NPM as you would any other TypeScript library.

⚠️

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

mixFetch

A drop-in replacement for fetch (opens in a new tab) that sends HTTP requests over the Nym mixnet

@nymproject/mix-fetch
ESM

@nymproject/mix-fetch-full-fat
ESM
pre-bundled

@nymproject/mix-fetch-commonjs
CommonJS

@nymproject/mix-fetch-full-fat-commonjs
CommonJS
pre-bundled

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

mixFetch

npm install @nymproject/mix-fetch-full-fat

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 @nymproject/mix-fetch-full-fat

Quick start

mixFetch

Use mixFetch (opens in a new tab) as a drop-in replacement for fetch to send HTTP requests over the mixnet:

import { mixFetch } from '@nymproject/mix-fetch';
 
// HTTP GET
const response = await mixFetch('https://nym.com');
const html = await response.text();
 
// HTTP POST
const apiResponse = await mixFetch('https://api.example.com', {
  method: 'POST',
  body: JSON.stringify({ foo: 'bar' }),
  headers: { 'Content-Type': 'application/json' }
});

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