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): CROSSxSDKConfiguration Types
SDKConfig
SDKConfiginterface 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
}| Field | Type | Required | Description |
|---|---|---|---|
projectId | string | Yes | Project ID from management console |
appName | string | Yes | Application name displayed in confirmation modals |
useMockWallet | boolean | No | Enable mock wallet for testing |
logger | LoggerPort | No | Custom logger for routing SDK logs |
theme | 'light' | 'dark' | No | Confirmation modal theme (default: 'light') |
autoDetectTheme | boolean | No | Auto-detect system dark mode via prefers-color-scheme (default: false) |
themeTokens | SDKThemeTokens | No | Per-mode color overrides |
locale | 'ko' | 'en' | No | Modal UI language (default: 'en') |
debug | boolean | No | Enable debug log output |
receiptPolling | object | No | { intervalMs?: number, timeoutMs?: number } |
migration | object | No | { allowSkip?: boolean } — controls migration UI behavior (default: { allowSkip: true }) |
showConnectOtherWallets | boolean | No | Show "Connect with Other Wallets" button in login modal (default: false). Emits connectExternalWallet event and throws EXTERNAL_WALLET_REQUESTED when clicked |
SDKThemeTokens
SDKThemeTokensinterface SDKThemeTokens {
light?: SDKColorOverrides
dark?: SDKColorOverrides
}SDKColorOverrides
SDKColorOverridesinterface 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
SignInOptionsinterface SignInOptions {
provider?: 'google' | 'apple'
}SignOptions
SignOptionsinterface 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(): booleanisLoggedIn(): boolean— alias forisAuthenticated()async ensureLoggedIn(): Promise<boolean>async getUserInfo(): Promise<SDKUserInfo>get currentAddress: string | null— synchronous getterget currentUserId: string | null— synchronous getter
Return notes
initialize()→AuthResultif restored,nullif no session. PasspreferredWalletIndexto select a specific wallet on restore.signIn()→AuthResultsignInWithCreate()→SignInWithCreateResult(AuthResult +addressesarray). 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()→trueif session valid,falseif 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. IfcurrentAddressis provided, the matching wallet is highlighted with a "selected" tag.
Chain
async getChains(): Promise<ChainInfo[]>— all supported chains (no auth required, onlyinitialize())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 IDmessage: 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 withoutdomain.chainId- params:
SignOptions
signTransaction(chainId, tx, opts?)tx: EvmTransactionRequest- params:
SignOptions
For
signTypedData(...), passchainIdas CAIP-2eip155:<number>. WhentypedData.domain.chainIdis present, it should match the numeric part of the requested chain ID. For off-chain signatures (nodomain.chainId), usesignTypedDataOffchain().
Transactions
sendTransaction(chainId, tx, opts?)tx: EvmTransactionRequest- params:
SignOptions
sendTransactionWithWaitForReceipt(chainId, tx, opts?)opts?: { intervalMs?, timeoutMs? }
getTransactionReceipt(txHash, chainId)→TransactionReceipt | nullwaitForTxAndGetReceipt(txHash, chainId, opts?)→TransactionReceipt
For transaction sign/send flows,
tx.frommust be provided (non-empty).
Gas
async getGasPrice(chainId): Promise<string>— hex gas price (Wei)async estimateGas(tx, chainId): Promise<string>— hex estimated gas limitasync getBaseFeePerGas(chainId): Promise<string | null>— hex base fee,nullon legacy chainsasync 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>
walletRpcis 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 flowsclearPin(): void— clear cached PIN from memoryhasPin(): boolean— check if a PIN is cachedasync 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 functionoff(event, listener): void
Event Types
| Event | Payload | Description |
|---|---|---|
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 |
connectExternalWallet | Record<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
AuthResult| Field | Type | Description |
|---|---|---|
success | boolean | Authentication success flag |
address | string? | Wallet address (if available) |
user | UserInfo? | User profile |
error | string? | Error message on failure |
needsMigration | boolean? | CROSSx backup found |
tokenSignatureVerified | boolean? | JWT verified via JWKS |
SignInWithCreateResult
SignInWithCreateResultExtends AuthResult with additional fields:
| Field | Type | Description |
|---|---|---|
addresses | Array<{ address: string; index: number }> | Full wallet address list |
SDKUserInfo
SDKUserInfo| Field | Type | Description |
|---|---|---|
id | string | User identifier (JWT sub) |
email | string? | User email |
loginType | string? | 'google' | 'apple' |
addresses | string[] | Wallet address list |
tokenSignatureVerified | boolean | JWT verified via JWKS |
ChainInfo
ChainInfo| Field | Type | Description |
|---|---|---|
chainId | string | CAIP-2 chain ID (e.g. eip155:612044) |
rpcUrl | string | JSON-RPC endpoint URL |
EvmTransactionRequest
EvmTransactionRequest| Field | Type | Description |
|---|---|---|
from | string | Sender address |
to | string | Recipient address |
value | string? | Hex wei value |
data | string? | Calldata hex |
gasLimit | string? | Hex gas limit |
gasPrice | string? | Legacy gas price |
maxFeePerGas | string? | EIP-1559 max fee |
maxPriorityFeePerGas | string? | EIP-1559 priority fee |
nonce | number? | Nonce (number) |
chainId | number? | Numeric chain ID |
SignMessageResp
SignMessageResp| Field | Type | Description |
|---|---|---|
chainId | string | CAIP-2 chain ID |
signature | string | Signature hex |
message | string | Original message |
address | string | Signer address |
SignTypedDataResp
SignTypedDataResp| Field | Type | Description |
|---|---|---|
chainId | string | CAIP-2 chain ID (on-chain) or '0' (off-chain) |
signature | string | EIP-712 signature hex |
address | string | Signer address |
SignTxResp
SignTxResp| Field | Type | Description |
|---|---|---|
chainId | string | CAIP-2 chain ID |
signedTx | string | RLP-encoded signed tx hex |
txHash | string | Transaction hash |
SendTxResp
SendTxResp| Field | Type | Description |
|---|---|---|
chainId | string | CAIP-2 chain ID |
txHash | string | Broadcasted tx hash |
status | string | 'pending' | 'success' | 'failed' |
TransactionWithReceipt
TransactionWithReceipt| Field | Type | Description |
|---|---|---|
chainId | string | CAIP-2 chain ID |
txHash | string | Transaction hash |
receipt | TransactionReceipt | Mined receipt |
TransactionReceipt
TransactionReceipt| Field | Type | Description |
|---|---|---|
transactionHash | string | Transaction hash |
blockHash | string | Block hash |
blockNumber | string | Block number (hex) |
from | string | Sender |
to | string | null | Recipient (null for contract creation) |
gasUsed | string | Gas used (hex) |
effectiveGasPrice | string | Gas price (hex) |
status | '0x1' | '0x0' | Success or reverted |
logs | any[] | Event logs |
transactionIndex | string | Index in block |
type | string | Transaction type |
MigrateResult
MigrateResult| Field | Type | Description |
|---|---|---|
address | string | Migrated 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
| Code | Description |
|---|---|
AUTH_NOT_INITIALIZED | SDK not initialized — call initialize() first |
AUTH_FAILED | Sign in failed |
AUTH_TOKEN_INVALID | Auth token is invalid |
AUTH_TOKEN_EXPIRED | Auth token has expired |
AUTH_NOT_AUTHENTICATED | Not authenticated — call signIn() first |
ALREADY_AUTHENTICATED | Already authenticated — sign out first |
WALLET_NOT_FOUND | Wallet not found |
WALLET_CREATION_FAILED | Wallet creation failed |
WALLET_INCONSISTENT_STATE | Wallet state inconsistency detected |
SIGN_FAILED | Signing failed |
SIGN_REJECTED | Signing rejected |
TX_FAILED | Transaction failed |
TX_REJECTED | Transaction rejected |
TX_INVALID_PARAMS | Invalid transaction parameters |
USER_REJECTED | User rejected in confirmation modal |
SIGNATURE_SIGNER_MISMATCH | ecrecover address mismatch |
GAS_ESTIMATION_FAILED | Gas estimation failed (eth_gasPrice / eth_estimateGas) |
TYPED_DATA_CHAIN_ID_MISMATCH | EIP-712 domain.chainId mismatch with path chainId |
NETWORK_ERROR | Network communication error |
NETWORK_NOT_CONFIGURED | Network adapter not configured |
INVALID_CHAIN | Invalid chain ID format |
CHAIN_NOT_SUPPORTED | Chain not supported / not registered |
CHAIN_ADAPTER_NOT_FOUND | Chain adapter not found |
PREPARE_FAILED | Pre-sign/send preparation failed |
PREPARE_EXPIRED | Prepared action expired |
PREPARE_MISMATCH | Prepared action mismatch |
MIGRATION_FAILED | Wallet migration failed |
MIGRATION_BACKUP_EXISTS | CROSSx backup found, migration required |
MIGRATION_PIN_LOCKED | PIN locked during migration — too many attempts |
PIN_NOT_SET | PIN is required but not set |
PIN_WRONG | Incorrect PIN entered |
PIN_INVALID | PIN format is invalid (sequential digits not allowed) |
PIN_REPEATED_PATTERN | PIN repeated digit pattern not allowed (Gateway -10032) |
PIN_CANCELLED | User cancelled PIN input |
EXTERNAL_WALLET_REQUESTED | User requested external wallet connection via "Connect with Other Wallets" button |
PIN_LOCKED | PIN locked due to too many failed attempts |
BROADCAST_FAILED | Transaction broadcast failed (-10007) |
GATEWAY_INTERNAL_ERROR | Gateway internal error (-10006), retry recommended |
GATEWAY_LOCK_CONFLICT | Lock conflict (-10008), retry recommended |
PROJECT_ID_MISSING | X-Project-Id header missing (gateway -10023) |
ORIGIN_NOT_ALLOWED | Origin not in allowed list (gateway -10024) |
APP_IDENTIFIER_MISSING | App identifier missing (gateway -10024) |
INVALID_APP_TYPE | Invalid X-App-Type value (gateway -10025) |
PROJECT_NOT_REGISTERED | Project not whitelisted (gateway -10022) |
INVALID_CONFIG | Invalid SDK configuration |
UNKNOWN_ERROR | Unknown error |
Chain ID Constants
import { ChainId } from '@nexus-cross/crossx-sdk-core'| Constant | Value |
|---|---|
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'Updated about 24 hours ago