Overview
@n1xyz/nord-ts is the
TypeScript client for Nord. It handles action signing, decimal scaling, nonce
management, and WebSocket subscriptions, and exposes typed wrappers over the
REST API.
Install
npm install @n1xyz/nord-ts @solana/web3.js
# or: yarn add @n1xyz/nord-ts @solana/web3.js
# or: bun add @n1xyz/nord-ts @solana/web3.js
Create a client
import { Connection } from "@solana/web3.js";
import { Nord } from "@n1xyz/nord-ts";
const nord = await Nord.new({
webServerUrl: "https://api-mainnet.n1.xyz",
app: process.env.APP_ADDRESS!,
solanaConnection: new Connection("https://api.mainnet-beta.solana.com"),
});
| Option | Required | Purpose |
|---|---|---|
webServerUrl | yes | Nord API base URL for the target network |
app | yes | App address you trade against |
solanaConnection | yes | Solana RPC connection, used for deposits |
protonUrl | no | Proton URL; defaults to webServerUrl |
Nord.new fetches /info, so after it resolves the client already knows the
deployment's markets and tokens:
nord.markets; // marketId, symbol, priceDecimals, sizeDecimals, mode, ...
nord.tokens; // tokenId, symbol, decimals, mintAddr, ...
Because the client holds these decimals, SDK methods take ordinary decimal prices, sizes, and amounts and scale them to wire integers for you.
Nord.initNord is a deprecated alias of Nord.new, and the initWebSockets
config flag is deprecated. New code should use Nord.new and create
subscriptions explicitly.
Two objects
Nord— connection and read paths: exchange configuration, market data, account queries, WebSocket subscriptions. No key material.NordUser— a wallet, its accounts, and its session; everything that submits a signed action.
import { NordUser } from "@n1xyz/nord-ts";
const user = NordUser.fromPrivateKey(nord, process.env.PRIVATE_KEY!);
await user.updateAccountId();
await user.fetchInfo();
await user.refreshSession();
After fetchInfo, user.balances, user.positions, user.orders, and
user.margins are populated, each keyed by account ID:
const accountId = user.accountIds![0];
user.balances[accountId]; // [{ accountId, symbol, balance }, ...]
user.positions[accountId];
user.orders[accountId]; // [{ orderId, marketId, side, size, price, ... }, ...]
This is a snapshot taken at fetch time, not a live view — refetch, or subscribe to account updates, after submitting actions.
Errors
SDK failures throw NordError, which wraps the underlying error in cause.
Order-entry calls also throw when the session is missing or expired, so
distinguish "session invalid" from "exchange rejected the order" when handling
failures.