Subaccounts
Subaccounts let you run isolated trading environments under a single wallet. Each subaccount has its own balance, positions, orders, and margin — but they all share the same public key.
[!TIP] See NordUser Reference for the full API signature of
transferOwnedandtransferUnowned.
How Subaccounts Work
A wallet maps to one or more account IDs. The GET /user/{pubkey} endpoint returns all of them:
const resp = await fetch(`${NORD_URL}/user/${pubkey}`);
const { accountIds } = await resp.json();
// accountIds: [1001, 1002, 1003] ← one per subaccountPass any of your account IDs when placing orders to target that subaccount:
await user.placeOrder({
marketId: 0,
side: Side.Bid,
fillMode: FillMode.Limit,
isReduceOnly: false,
size: 0.1,
price: 50000,
accountId: 1002,
});Creating a Subaccount
Call transferOwned without a toAccountId. This creates a new subaccount and seeds it with the specified amount.
const result = await user.transferOwned({
tokenId: 0, // USDC
amount: 500,
fromAccountId: 1001,
});
console.log("New subaccount ID:", result.newAccountId);Funding an Existing Subaccount
Provide both fromAccountId and toAccountId to move funds between your own subaccounts.
await user.transferOwned({
tokenId: 0,
amount: 200,
fromAccountId: 1001,
toAccountId: 1002,
});Transferring to Another User
Use transferUnowned to send funds to an account belonging to a different public key. You’ll need to resolve their account IDs first.
const resp = await fetch(`${NORD_URL}/user/${recipientPubkey}`);
const { accountIds } = await resp.json();
await user.transferUnowned({
tokenId: 0,
amount: 100,
fromAccountId: 1001,
toAccountId: accountIds[0],
});Full Example
import { Nord, NordUser, Side, FillMode } from "@n1xyz/nord-ts";
const NORD_URL = "https://zo-mainnet.n1.xyz";
// 1. Initialize user (see Creating a User)
const nord = new Nord({ url: NORD_URL });
const user = await NordUser.create(nord, wallet);
// 2. Check existing subaccounts
const resp = await fetch(`${NORD_URL}/user/${user.pubkey}`);
const { accountIds } = await resp.json();
console.log("Subaccounts:", accountIds);
// e.g. [1001]
// 3. Create a second subaccount seeded with 500 USDC
const { newAccountId } = await user.transferOwned({
tokenId: 0,
amount: 500,
fromAccountId: accountIds[0],
});
console.log("Created subaccount:", newAccountId);
// 4. Trade from the new subaccount
await user.placeOrder({
marketId: 0,
side: Side.Bid,
fillMode: FillMode.Limit,
isReduceOnly: false,
size: 0.1,
price: 50000,
accountId: newAccountId,
});
// 5. Move funds back when done
await user.transferOwned({
tokenId: 0,
amount: 300,
fromAccountId: newAccountId,
toAccountId: accountIds[0],
});