NERO
Getting Started

Configuration

SDK configuration options, initialization flow, protocol selection, and storage setup

Configuration

SDKConfig

The NeroMpcSDK constructor accepts an SDKConfig object that controls all SDK behavior:

PropertyTypeDefaultDescription
backendUrlstringRequiredBase URL for the NERO backend API
apiKeystringProject API key sent in X-API-Key header
deviceIdstringStable device identifier
chainIdnumber689EVM chain ID (689 = NERO Testnet)
protocol"dkls" | "pedersen""dkls"MPC protocol variant
storagePrefixstring"nero"Namespace prefix for all storage keys
autoConnectbooleantrueAttempt session restoration on initialize()
wsUrlstringWebSocket URL for real-time MPC coordination (required for Pedersen)
storageStorageAdaptercreateTokenStorage()Custom storage implementation
sessionTimenumberSession lifetime override in seconds
uiConfigUIConfigVisual customization for modal components
requestMiddlewareRequestMiddleware[]Custom middleware for API requests
retryConfigRetryConfigCustom retry configuration for API requests

Initialization Flow

The SDK initializes in two distinct phases:

Phase 1 — Construction

When you call new NeroMpcSDK(config), the constructor creates core subsystems:

  • APIClient for HTTP communication
  • ChainManager for blockchain network management
  • StorageAdapter for token persistence
  • Optional WebSocketClient if wsUrl is provided

Phase 2 — initialize()

When you call await sdk.initialize(), the SDK performs asynchronous setup:

  1. Loads or generates a persistent deviceKey from storage via ClientKeyManager
  2. Instantiates ClientKeyManager with the device key
  3. Attempts to restore an existing session using stored tokens
  4. If authentication tokens are found and valid, populates the user profile and wallet information
  5. Initializes protocol-specific wallet (SmartWallet for Pedersen, DKLSClient for DKLS)

The SDK prefers IndexedDBStorage for device key storage and automatically migrates legacy keys from localStorage. The full device key loading sequence:

  1. Attempt to retrieve from IndexedDB
  2. Check for legacy key in localStorage
  3. Migrate if found in localStorage
  4. Generate a new cryptographically random key if not found
  5. Store using the best available mechanism (IndexedDB preferred, localStorage fallback)

After initialization completes, query the current state via the state getter:

const sdk = new NeroMpcSDK({
  backendUrl: "https://your-api.example.com",
  apiKey: "your-project-api-key",
});

await sdk.initialize();

console.log(sdk.state.isInitialized);    // true
console.log(sdk.state.isAuthenticated);  // true if session was restored
console.log(sdk.state.hasWallet);        // true if wallet exists
console.log(sdk.state.isConnected);      // true if provider is connected

The SDK emits an "initialized" event when this phase completes, so you can react to completion without polling:

sdk.on("initialized", () => {
  console.log("SDK ready:", sdk.state);
});

Protocol Selection

The protocol field determines the key generation algorithm, signature computation method, and wallet type.

DKLS (Default)

PropertyValue
Protocol2-party DKLS threshold ECDSA
Wallet typeEOA (Externally Owned Account)
TransportHTTP API requests
Client classDKLSClient

Best for most applications. Efficient signing with direct EOA wallets.

const sdk = new NeroMpcSDK({
  backendUrl: "https://your-api.example.com",
  apiKey: "your-project-api-key",
  protocol: "dkls",
});

Pedersen DKG

PropertyValue
ProtocolPedersen DKG version 2
Wallet typeSmart contract wallet (ERC-4337)
TransportWebSocket for real-time round coordination
Client classDKGClient

Requires a WebSocket URL for real-time protocol coordination:

const sdk = new NeroMpcSDK({
  backendUrl: "https://your-api.example.com",
  apiKey: "your-project-api-key",
  protocol: "pedersen",
  wsUrl: "wss://your-ws.example.com",
});

UIConfig

Customize the look of modal components via SDKConfig.uiConfig:

FieldTypeDescription
appNamestringApplication name displayed in modals
logoLightstringLight mode logo URL
logoDarkstringDark mode logo URL
mode"light" | "dark" | "auto"Theme mode
themeobjectCSS color overrides: primary, secondary, background, text, border

Storage Configuration

The SDK uses multiple storage mechanisms depending on data type:

Storage typeManaged byDefault backendPurpose
Token storage_tokenStorageIndexedDBStorageJWTs and session metadata
Key share storageProtocol-dependentIndexedDBStorage or MemoryStorageEncrypted MPC key shares

All storage keys use the storagePrefix (default "nero") to avoid collisions between SDK instances:

const sdk = new NeroMpcSDK({
  backendUrl: "https://your-api.example.com",
  storagePrefix: "my-app",
});

Custom Storage Adapter

You can provide your own storage implementation via the storage field. It must satisfy the StorageAdapter interface:

export interface StorageAdapter {
  get(key: string): Promise<string | null>;
  set(key: string, value: string): Promise<void>;
  delete(key: string): Promise<void>;
  clear(): Promise<void>;
}

Chain Configuration

Use the pre-defined chain configurations from the chains module:

import { NERO_TESTNET } from "@nerochain/mpc-sdk/chains";

const sdk = new NeroMpcSDK({
  backendUrl: "https://your-api.example.com",
  chainId: NERO_TESTNET.chainId,
});

Switch chains at runtime using:

await sdk.switchChain(newChainId);

Core Type Reference

User

Populated after successful login:

FieldType
idstring
emailstring | undefined
displayNamestring | undefined
walletAddressstring | undefined
createdAtDate

AuthTokens

Token bundle used for API authorization:

FieldTypeDescription
accessTokenstringShort-lived JWT for API requests
refreshTokenstringLong-lived token for access token renewal
expiresAtnumberUnix timestamp for access token expiration
dappSharestring | undefinedOpaque session portability token

WalletInfo

Describes the user's MPC wallet:

FieldTypeDescription
eoaAddressstringEthereum address derived from public key
smartWalletAddressstring | undefinedERC-4337 smart account address
publicKeystringHex-encoded public key

Signature

Final assembled Ethereum-compatible signature:

FieldType
rstring
sstring
vnumber
fullSignaturestring

On this page