A TypeScript/JavaScript SDK for interacting with the Zenon Network of Momentum (NoM).
- 🚀 Modern ESM-first architecture – Optimized for tree-shaking and modern JavaScript
- 🔌 Dual protocol support – HTTP and WebSocket connections
- 💼 Wallet management – Create, import, and manage wallets with BIP39 mnemonic support
- 🔐 Transaction signing – Sign and send transactions with automatic PoW generation
- ⌨️ CLI Included – CLI for wallet management and sending transactions
- 📡 Real-time subscriptions – Subscribe to momentums and account blocks via WebSocket
- 🌐 Universal – Works in Node.js and browsers (ESM & UMD)
- 📝 TypeScript native – Full type definitions included
npm install znn-typescript-sdkimport { Zenon } from 'znn-typescript-sdk';
const zenon = Zenon.getInstance();
await zenon.initialize('wss://node.zenonhub.io:35998');npm create vite@latest my-zenon-app -- --template vanilla
cd my-zenon-app
npm install znn-typescript-sdk
npm run devimport { Zenon } from 'znn-typescript-sdk';
const zenon = Zenon.getInstance();
await zenon.initialize('wss://node.zenonhub.io:35998');The SDK ships two browser bundles:
- ESM (
dist/browser/bundle.browser.mjs): Modern module build for Vite/Rollup/Webpack. Import fromznn-typescript-sdkor the.mjsbundle. - UMD (
dist/browser/bundle.browser.js): Legacy global build that exposeswindow.ZnnSDKfor script-tag usage.
Use ESM when possible. Use UMD only if you must load the SDK via a <script> tag without a bundler.
The Proof of Work (PoW) module requires two external files in browser environments: pow.js and pow.wasm. These files must be accessible at runtime.
Setup:
- The PoW files are located in
node_modules/znn-typescript-sdk/dist/browser - Set the base path before any operations that require PoW:
import { Zenon } from 'znn-typescript-sdk';
// Point to where pow.js and pow.wasm are located
Zenon.setPowBasePath('node_modules/znn-typescript-sdk/dist/browser');
// Now you can send transactions (which use PoW)
const zenon = Zenon.getInstance();
await zenon.initialize('wss://node.zenonhub.io:35998');
const tx = await zenon.send(blockTemplate, keyPair);For UMD:
window.ZnnSDK.Zenon.setPowBasePath('node_modules/znn-typescript-sdk/dist/browser');Alternative – Copy to Public Folder:
For production apps, copy the PoW files to your public/static folder:
cp node_modules/znn-typescript-sdk/dist/browser/pow.* public/Then set the path:
Zenon.setPowBasePath('/'); // or 'assets' for relative pathsNote: Node.js environments don't need this configuration – PoW files are loaded automatically from the installation directory.
- HTTP:
https://node.zenonhub.io:35997- For simple API calls - WebSocket:
wss://node.zenonhub.io:35998- For real-time subscriptions and transactions
The main entry point is the Zenon singleton.
import { Zenon } from 'znn-typescript-sdk';
const zenon = Zenon.getInstance();These methods configure SDK-level settings and should be called before initializing the Zenon instance.
Set the network ID for transaction signing. Default is 1.
Zenon.setNetworkID(3); // Set to testnetGet the current network ID.
const networkId = Zenon.getNetworkID();Set the chain ID for transaction signing. Default is 1.
Zenon.setChainID(100); // Set to custom chainGet the current chain ID.
const chainId = Zenon.getChainIdentifier();Set the base path for loading PoW files in browser environments. Only needed for browser usage. The path is automatically normalized to meet browser module specifier requirements (adding ./ prefix and / suffix as needed).
// Before initialization in browser
// These are all valid and will be normalized automatically:
Zenon.setPowBasePath('node_modules/znn-typescript-sdk/dist/browser');
Zenon.setPowBasePath('/assets');
Zenon.setPowBasePath('./public');Get the current PoW base path.
const path = Zenon.getPowBasePath();Connect to a Zenon node via HTTP or WebSocket.
// WebSocket (for subscriptions and transactions)
await zenon.initialize('wss://node.zenonhub.io:35998');
// HTTP (for simple requests)
await zenon.initialize('https://node.zenonhub.io:35997');Note: WebSocket connections automatically reconnect if dropped during long-running operations (e.g., PoW generation). The default settings are suitable for most use cases.
Disconnect and clean up resources.
zenon.clearConnection();Sign and send a transaction. Automatically generates PoW if needed.
const tx = await zenon.send(blockTemplate, keyPair);
console.log('Hash:', tx.hash.toString());- Examples – Complete working examples
- API Overview – All API methods and embedded contract calls
- Embedded Contracts – Detailed documentation for embedded contracts
- Utilities – Utilities and constants for common tasks
- CLI Tool – Command-line interface
- Wallet Management – Creating and managing wallets
- Building WASM – Rebuilding the PoW module from source
git clone https://github.com/digitalSloth/znn-typescript-sdk.git
cd znn-typescript-sdk
npm install
npm run build
npm test- Node.js 18+ (ESM support)
- Modern browser with WebAssembly support
- Bundler for browser production apps (Vite, Webpack, etc.)
BSD-3-Clause
Contributions are welcome! Please feel free to submit a Pull Request.