API Reference

Core SDK — API Reference

This page documents the public API surface of CROSSxSDK for JavaScript/TypeScript.

Factory

import { createCROSSxSDK } from '@nexus-cross/crossx-sdk-core'

const sdk = createCROSSxSDK(config: SDKConfig): CROSSxSDK

Configuration Types

SDKConfig

interface SDKConfig {
  projectId: string
  appName: string
  useMockWallet?: boolean
  logger?: LoggerPort
  theme?: 'light' | 'dark'
  autoDetectTheme?: boolean
  themeTokens?: SDKThemeTokens
  locale?: 'ko' | 'en'   // default: 'en'
  debug?: boolean
  receiptPolling?: {
    intervalMs?: number   // default: 2000
    timeoutMs?: number    // default: 60000
  }
  migration?: {
    allowSkip?: boolean   // default: true
  }
  showConnectOtherWallets?: boolean  // default: false
}
FieldTypeRequiredDescription
projectIdstringYesProject ID from management console
appNamestringYesApplication name displayed in confirmation modals
useMockWalletbooleanNoEnable mock wallet for testing
loggerLoggerPortNoCustom logger for routing SDK logs
theme'light' | 'dark'NoConfirmation modal theme (default: 'light')
autoDetectThemebooleanNoAuto-detect system dark mode via prefers-color-scheme (default: false)
themeTokensSDKThemeTokensNoPer-mode color overrides
locale'ko' | 'en'NoModal UI language (default: 'en')
debugbooleanNoEnable debug log output
receiptPollingobjectNo{ intervalMs?: number, timeoutMs?: number }
migrationobjectNo{ allowSkip?: boolean } — controls migration UI behavior (default: { allowSkip: true })
showConnectOtherWalletsbooleanNoShow "Connect with Other Wallets" button in login modal (default: false). Emits connectExternalWallet event and throws EXTERNAL_WALLET_REQUESTED when clicked

SDKThemeTokens

interface SDKThemeTokens {
  light?: SDKColorOverrides
  dark?: SDKColorOverrides
}

SDKColorOverrides

interface SDKColorOverrides {
  primary?: string
  secondary?: string
  onPrimary?: string
  borderDefault?: string
  borderSubtle?: string
  textIconPrimary?: string
  textIconSecondary?: string
  textIconTertiary?: string
  surfaceDefault?: string
  surfaceSubtle?: string
  bg?: string
  error?: string
}

Color format: CSS color string (e.g. '#FF6B35', 'rgba(18,18,18,0.5)').

SignInOptions

interface SignInOptions {
  provider?: 'google' | 'apple'
}

SignOptions

interface SignOptions {
  index?: number
  dappName?: string
  accountName?: string
}

Core API

  • async initialize(opts?): Promise<AuthResult | null>
    • opts?: { preferredWalletIndex?: number } — specify which wallet index to use on session restore
  • async signIn(options?: SignInOptions): Promise<AuthResult>
  • async signInWithCreate(options?: SignInOptions): Promise<SignInWithCreateResult>
  • async signInWithJWT(accessToken: string, refreshToken?: string): Promise<AuthResult>
  • async signOut(): Promise<void>
  • isAuthenticated(): boolean
  • isLoggedIn(): boolean — alias for isAuthenticated()
  • async ensureLoggedIn(): Promise<boolean>
  • async getUserInfo(): Promise<SDKUserInfo>
  • get currentAddress: string | null — synchronous getter
  • get currentUserId: string | null — synchronous getter

Return notes

  • initialize()AuthResult if restored, null if no session. Pass preferredWalletIndex to select a specific wallet on restore.
  • signIn()AuthResult
  • signInWithCreate()SignInWithCreateResult (AuthResult + addresses array). Handles wallet creation and migration automatically.
  • signInWithJWT()AuthResult. Authenticates using a pre-obtained JWT access token (e.g. from your own backend). Useful for server-side auth flows.
  • ensureLoggedIn()true if session valid, false if login needed

Address / Wallet

  • async getAddress(index?: number): Promise<{ address: string; index: number } | null>
  • async getAddresses(): Promise<Array<{ address: string; index: number }>>
  • async createWallet(): Promise<{ address: string }>
  • async selectWallet(currentAddress?: string): Promise<{ address: string; index: number } | null> — opens wallet selector modal. If currentAddress is provided, the matching wallet is highlighted with a "selected" tag.

Chain

  • async getChains(): Promise<ChainInfo[]> — all supported chains (no auth required, only initialize())
  • async getChain(chainId: string): Promise<ChainInfo> — specific chain info

Signing (UI confirm flow)

All methods display a user confirmation modal.

  • signMessage(chainId, message, opts?)
    • chainId: string — CAIP-2 chain ID
    • message: string
    • params: SignOptions
  • signTypedData(chainId, typedData, opts?)
    • typedData: unknown — EIP-712 typed data object
    • params: SignOptions
  • signTypedDataOffchain(typedData, opts?)
    • typedData: unknown — EIP-712 typed data object without domain.chainId
    • params: SignOptions
  • signTransaction(chainId, tx, opts?)
    • tx: EvmTransactionRequest
    • params: SignOptions

For signTypedData(...), pass chainId as CAIP-2 eip155:<number>. When typedData.domain.chainId is present, it should match the numeric part of the requested chain ID. For off-chain signatures (no domain.chainId), use signTypedDataOffchain().

Transactions

  • sendTransaction(chainId, tx, opts?)
    • tx: EvmTransactionRequest
    • params: SignOptions
  • sendTransactionWithWaitForReceipt(chainId, tx, opts?)
    • opts?: { intervalMs?, timeoutMs? }
  • getTransactionReceipt(txHash, chainId)TransactionReceipt | null
  • waitForTxAndGetReceipt(txHash, chainId, opts?)TransactionReceipt

For transaction sign/send flows, tx.from must be provided (non-empty).

Gas

  • async getGasPrice(chainId): Promise<string> — hex gas price (Wei)
  • async estimateGas(tx, chainId): Promise<string> — hex estimated gas limit
  • async getBaseFeePerGas(chainId): Promise<string | null> — hex base fee, null on legacy chains
  • async getMaxPriorityFeePerGas(chainId): Promise<string> — hex priority fee (tip)

Balance / Nonce / RPC

  • async getBalance(chainId): Promise<{ wei: string; formatted: string; chainId: string }>
  • async getNonce(chainId): Promise<number>
  • async walletRpc(method, params, chainId): Promise<any>

walletRpc is for read-only calls only (eth_call, eth_getBalance, etc.).

Provider

  • getProvider(chainId): CROSSxEthereumProvider

Returns an EIP-1193 compatible provider.

const provider = sdk.getProvider('eip155:612044')

// ethers.js v6
const ethersProvider = new ethers.BrowserProvider(provider)

// viem
const client = createWalletClient({ transport: custom(provider) })

Theme & Locale

  • applyTheme(themeMode?, themeTokens?): void

Changes confirmation modal theme at runtime.

  • applyLocale(locale?): void

Changes confirmation modal language at runtime. Takes effect on the next modal open.

sdk.applyLocale('ko')
sdk.applyLocale('en')

PIN Management

  • setPin(pin: string): void — cache PIN in memory for signing flows
  • clearPin(): void — clear cached PIN from memory
  • hasPin(): boolean — check if a PIN is cached
  • async changePin(oldPin: string, newPin: string): Promise<void> — change PIN on the server

When a PIN is required but not cached, the SDK displays a PIN input modal automatically.

Migration

  • async migrateWallet(pin: string): Promise<MigrateResult>

Migrates a CROSSx wallet to Embedded Wallet using a 4-digit PIN.

Events

CROSSxSDK extends TypedEventEmitter<SDKEventMap> and supports typed event subscription:

  • on(event, listener): () => void — returns unsubscribe function
  • off(event, listener): void

Event Types

EventPayloadDescription
authChanged{ isAuthenticated: boolean, address: string | null, userId: string | null }Auth state changed (sign in/out)
addressChanged{ address: string, index: number }Active wallet address changed
initialized{ restored: boolean }SDK initialization completed
connectExternalWalletRecord<string, never> (empty object)User clicked "Connect with Other Wallets" — DApp should open external wallet UI
const unsub = sdk.on('authChanged', (event) => {
  console.log(event.isAuthenticated, event.address)
})

// Cleanup
unsub()

Lifecycle

  • dispose(): void

Cleans up SDK resources. The instance cannot be used after this call.

Response Types

AuthResult

FieldTypeDescription
successbooleanAuthentication success flag
addressstring?Wallet address (if available)
userUserInfo?User profile
errorstring?Error message on failure
needsMigrationboolean?CROSSx backup found
tokenSignatureVerifiedboolean?JWT verified via JWKS

SignInWithCreateResult

Extends AuthResult with additional fields:

FieldTypeDescription
addressesArray<{ address: string; index: number }>Full wallet address list

SDKUserInfo

FieldTypeDescription
idstringUser identifier (JWT sub)
emailstring?User email
loginTypestring?'google' | 'apple'
addressesstring[]Wallet address list
tokenSignatureVerifiedbooleanJWT verified via JWKS

ChainInfo

FieldTypeDescription
chainIdstringCAIP-2 chain ID (e.g. eip155:612044)
rpcUrlstringJSON-RPC endpoint URL

EvmTransactionRequest

FieldTypeDescription
fromstringSender address
tostringRecipient address
valuestring?Hex wei value
datastring?Calldata hex
gasLimitstring?Hex gas limit
gasPricestring?Legacy gas price
maxFeePerGasstring?EIP-1559 max fee
maxPriorityFeePerGasstring?EIP-1559 priority fee
noncenumber?Nonce (number)
chainIdnumber?Numeric chain ID

SignMessageResp

FieldTypeDescription
chainIdstringCAIP-2 chain ID
signaturestringSignature hex
messagestringOriginal message
addressstringSigner address

SignTypedDataResp

FieldTypeDescription
chainIdstringCAIP-2 chain ID (on-chain) or '0' (off-chain)
signaturestringEIP-712 signature hex
addressstringSigner address

SignTxResp

FieldTypeDescription
chainIdstringCAIP-2 chain ID
signedTxstringRLP-encoded signed tx hex
txHashstringTransaction hash

SendTxResp

FieldTypeDescription
chainIdstringCAIP-2 chain ID
txHashstringBroadcasted tx hash
statusstring'pending' | 'success' | 'failed'

TransactionWithReceipt

FieldTypeDescription
chainIdstringCAIP-2 chain ID
txHashstringTransaction hash
receiptTransactionReceiptMined receipt

TransactionReceipt

FieldTypeDescription
transactionHashstringTransaction hash
blockHashstringBlock hash
blockNumberstringBlock number (hex)
fromstringSender
tostring | nullRecipient (null for contract creation)
gasUsedstringGas used (hex)
effectiveGasPricestringGas price (hex)
status'0x1' | '0x0'Success or reverted
logsany[]Event logs
transactionIndexstringIndex in block
typestringTransaction type

MigrateResult

FieldTypeDescription
addressstringMigrated wallet address

Error Handling

import { CROSSxError, ErrorCode } from '@nexus-cross/crossx-sdk-core'

try {
  await sdk.signTransaction(chainId, tx)
} catch (error) {
  if (error instanceof CROSSxError) {
    console.log(error.code)     // ErrorCode enum
    console.log(error.message)  // Human-readable message
    console.log(error.details)  // Original error
  }
}

Error Codes

CodeDescription
AUTH_NOT_INITIALIZEDSDK not initialized — call initialize() first
AUTH_FAILEDSign in failed
AUTH_TOKEN_INVALIDAuth token is invalid
AUTH_TOKEN_EXPIREDAuth token has expired
AUTH_NOT_AUTHENTICATEDNot authenticated — call signIn() first
ALREADY_AUTHENTICATEDAlready authenticated — sign out first
WALLET_NOT_FOUNDWallet not found
WALLET_CREATION_FAILEDWallet creation failed
WALLET_INCONSISTENT_STATEWallet state inconsistency detected
SIGN_FAILEDSigning failed
SIGN_REJECTEDSigning rejected
TX_FAILEDTransaction failed
TX_REJECTEDTransaction rejected
TX_INVALID_PARAMSInvalid transaction parameters
USER_REJECTEDUser rejected in confirmation modal
SIGNATURE_SIGNER_MISMATCHecrecover address mismatch
GAS_ESTIMATION_FAILEDGas estimation failed (eth_gasPrice / eth_estimateGas)
TYPED_DATA_CHAIN_ID_MISMATCHEIP-712 domain.chainId mismatch with path chainId
NETWORK_ERRORNetwork communication error
NETWORK_NOT_CONFIGUREDNetwork adapter not configured
INVALID_CHAINInvalid chain ID format
CHAIN_NOT_SUPPORTEDChain not supported / not registered
CHAIN_ADAPTER_NOT_FOUNDChain adapter not found
PREPARE_FAILEDPre-sign/send preparation failed
PREPARE_EXPIREDPrepared action expired
PREPARE_MISMATCHPrepared action mismatch
MIGRATION_FAILEDWallet migration failed
MIGRATION_BACKUP_EXISTSCROSSx backup found, migration required
MIGRATION_PIN_LOCKEDPIN locked during migration — too many attempts
PIN_NOT_SETPIN is required but not set
PIN_WRONGIncorrect PIN entered
PIN_INVALIDPIN format is invalid (sequential digits not allowed)
PIN_REPEATED_PATTERNPIN repeated digit pattern not allowed (Gateway -10032)
PIN_CANCELLEDUser cancelled PIN input
EXTERNAL_WALLET_REQUESTEDUser requested external wallet connection via "Connect with Other Wallets" button
PIN_LOCKEDPIN locked due to too many failed attempts
BROADCAST_FAILEDTransaction broadcast failed (-10007)
GATEWAY_INTERNAL_ERRORGateway internal error (-10006), retry recommended
GATEWAY_LOCK_CONFLICTLock conflict (-10008), retry recommended
PROJECT_ID_MISSINGX-Project-Id header missing (gateway -10023)
ORIGIN_NOT_ALLOWEDOrigin not in allowed list (gateway -10024)
APP_IDENTIFIER_MISSINGApp identifier missing (gateway -10024)
INVALID_APP_TYPEInvalid X-App-Type value (gateway -10025)
PROJECT_NOT_REGISTEREDProject not whitelisted (gateway -10022)
INVALID_CONFIGInvalid SDK configuration
UNKNOWN_ERRORUnknown error

Chain ID Constants

import { ChainId } from '@nexus-cross/crossx-sdk-core'
ConstantValue
ChainId.CROSS_MAINNET'eip155:612055'
ChainId.CROSS_TESTNET'eip155:612044'
ChainId.BSC_MAINNET'eip155:56'
ChainId.BSC_TESTNET'eip155:97'
ChainId.RONIN_MAINNET'eip155:2020'
ChainId.RONIN_SAIGON'eip155:202601'

Public Type Exports

import type {
  SDKConfig,
  SDKThemeTokens,
  SDKColorOverrides,
  AuthResult,
  SignInWithCreateResult,
  SignInOptions,
  SignOptions,
  SDKUserInfo,
  UserInfo,
  EvmTransactionRequest,
  SignMessageResp,
  SignTypedDataResp,
  SignTxResp,
  SendTxResp,
  TransactionWithReceipt,
  MigrateResult,
  ChainInfo,
  ChainIdValue,
  AddressInfo,
  SDKEventMap,
  AuthChangedEvent,
  AddressChangedEvent,
  InitializedEvent,
  ConnectExternalWalletEvent,
  PrepareAction,
  PrepareContext,
  PrepareResult,
} from '@nexus-cross/crossx-sdk-core'

import {
  createCROSSxSDK,
  CROSSxSDK,
  CROSSxEthereumProvider,
  ChainId,
  CROSSxError,
  ErrorCode,
} from '@nexus-cross/crossx-sdk-core'

© 2025 NEXUS Co., Ltd. All Rights Reserved.