API Reference
Core SDK — API Reference
This page documents the public API surface of CROSSxSDK for JavaScript/TypeScript (current version: 2.4.0). The wallet product's display brand is ONEpocket (formerly CROSSx); the package and class names are unchanged.
Factory
import { createCROSSxSDK } from '@nexus-cross/crossx-sdk-core'
const sdk = createCROSSxSDK(config: SDKConfig): CROSSxSDKCreates and returns a CROSSxSDK instance. This is the only way to instantiate the SDK — do not use new CROSSxSDK() directly.
Rebrand alias:
createONEpocketSDKis exported as an alias ofcreateCROSSxSDK(identical behavior). See Rebrand aliases.
Configuration 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
connectOtherWallets?: ConnectOtherWalletItem[]
persistWalletPreference?: boolean // default: true
enableRNBridgeAutoLogin?: boolean // default: true
displayDecimals?: number // default: 6
pinKeyboard?: 'virtual' | 'native' | (() => 'virtual' | 'native')
}| 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 all built-in "Connect with Other Wallets" entries in the login modal (default: false). Clicking an entry emits connectExternalWallet ({ walletId }) and throws EXTERNAL_WALLET_REQUESTED |
connectOtherWallets | ConnectOtherWalletItem[] | No | External wallets to show in the login selector. A non-empty array takes precedence over showConnectOtherWallets and shows only the listed items |
persistWalletPreference | boolean | No | Auto-save the last selected wallet to storage and restore it on the next initialize() (default: true). Set false to manage wallet selection yourself via initialize({ preferredWalletIndex }) etc. |
enableRNBridgeAutoLogin | boolean | No | In the wallet in-app browser (RN Bridge), attempt auto sign-in with the wallet app's session (default: true) |
displayDecimals | number | No | Max decimal places when formatting wei/token amounts for display (default: 6). Trailing zeros are removed |
pinKeyboard | 'virtual' | 'native' | (() => 'virtual' | 'native') | No | PIN modal keyboard mode on mobile: 'virtual' (SDK numpad, default) or 'native' (OS keyboard). Pass a function to decide per modal open |
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'
}SignInWithCreateOptions
SignInWithCreateOptionsinterface SignInWithCreateOptions extends SignInOptions {
/** Wallet address to auto-select. If present in the wallet list, the selectWallet() modal is skipped. */
preferredWalletAddress?: string
}SignOptions
SignOptionsinterface SignOptions {
index?: number
dappName?: string
accountName?: string
}Core API
initialize(opts?)
initialize(opts?)async initialize(opts?: { preferredWalletIndex?: number; preferredWalletAddress?: string }): Promise<AuthResult | null>| Parameter | Type | Required | Description |
|---|---|---|---|
opts.preferredWalletIndex | number | No | Wallet derivation index to restore on session resume |
opts.preferredWalletAddress | string | No | Wallet address to restore on session resume (takes the matching wallet if it exists) |
Returns: AuthResult if a prior session is restored, null if no session exists.
Initializes the SDK and restores a prior session from persistent storage if available. Must be called once at startup before any other SDK method. When a session is restored, the returned AuthResult reflects the user's previous sign-in state.
whenReady()
whenReady()async whenReady(): Promise<boolean>Returns: true once initialization has completed, false if initialization has not been started or failed.
Waits for SDK initialization to finish. Prevents race conditions where isAuthenticated() is checked while initialize() is still in flight (e.g. frameworks that do not await connector setup). If initialization has already completed, resolves immediately with true; if it is in progress, resolves when it finishes; if it was never started, resolves immediately with false.
signIn(options?)
signIn(options?)async signIn(options?: SignInOptions): Promise<AuthResult>| Parameter | Type | Required | Description |
|---|---|---|---|
options.provider | 'google' | 'apple' | No | OAuth provider to use. If omitted, the SDK displays a provider selection modal. |
Returns: AuthResult
Opens the OAuth sign-in flow. If options.provider is not specified, a provider selection modal is displayed. On success, creates a session and returns auth state. Throws if the user cancels.
signInWithCreate(options?)
signInWithCreate(options?)async signInWithCreate(options?: SignInWithCreateOptions): Promise<SignInWithCreateResult>| Parameter | Type | Required | Description |
|---|---|---|---|
options.provider | 'google' | 'apple' | No | OAuth provider to use |
options.preferredWalletAddress | string | No | Wallet address to auto-select. If it exists in the user's wallet list, the wallet selector modal is skipped |
Returns: SignInWithCreateResult
Signs in and automatically creates an embedded wallet if the user does not already have one. Also handles legacy CROSSx wallet migration automatically. When the user has two or more wallets, the wallet selector modal is shown (unless preferredWalletAddress matches an existing wallet). Use this method for most onboarding flows.
signInWithOAuthToken(firebaseToken)
signInWithOAuthToken(firebaseToken)async signInWithOAuthToken(firebaseToken: string): Promise<SignInWithCreateResult>| Parameter | Type | Required | Description |
|---|---|---|---|
firebaseToken | string | Yes | Firebase ID token obtained externally (e.g. from a native app deeplink) |
Returns: SignInWithCreateResult
Completes sign-in with an externally obtained Firebase ID token instead of opening the OAuth popup — used when the OAuth flow is performed outside the SDK (e.g. a React Native host app passes the token via deeplink; see parseOAuthDeeplink). Behaves like signInWithCreate() afterwards: creates the wallet if needed and shows the wallet selector when the user has multiple wallets. The resulting authChanged event carries source: 'external'.
signInAgain()
signInAgain()async signInAgain(): Promise<AuthResult>Returns: AuthResult on success, { success: false } on failure.
Re-authenticates the same account after session expiry (SESSION_EXPIRED). Opens OAuth again and verifies that the same account was used; if a different account signs in, the SDK signs it out and prompts the user to retry with the original account.
signInWithJWT(accessToken, refreshToken?)
signInWithJWT(accessToken, refreshToken?)async signInWithJWT(accessToken: string, refreshToken?: string): Promise<AuthResult>| Parameter | Type | Required | Description |
|---|---|---|---|
accessToken | string | Yes | JWT access token obtained from your backend or Firebase |
refreshToken | string | No | Optional refresh token for session renewal |
Returns: AuthResult
Authenticates using a pre-obtained JWT access token. Useful for React Native WebView scenarios where Firebase Auth is handled natively and the token is passed to the JS SDK. The JWT signature is verified via JWKS.
signOut()
signOut()async signOut(): Promise<void>Signs out the current user and clears the session from persistent storage. Emits an authChanged event with isAuthenticated: false.
isAuthenticated()
isAuthenticated()isAuthenticated(): booleanReturns: true if the user has an active authenticated session, false otherwise.
Synchronous check of the current auth state. Does not trigger a network request.
isLoggedIn()
isLoggedIn()isLoggedIn(): booleanAlias for isAuthenticated(). Returns the same value.
ensureLoggedIn()
ensureLoggedIn()async ensureLoggedIn(): Promise<boolean>Returns: true if the session is valid, false if a sign-in is needed.
Verifies that the current session is still valid (e.g. token not expired). Use before operations that require authentication.
getUserInfo()
getUserInfo()async getUserInfo(): Promise<SDKUserInfo>Returns: SDKUserInfo
Retrieves the authenticated user's profile including ID, email, login type, and wallet addresses. Throws AUTH_NOT_AUTHENTICATED if not signed in.
currentAddress
currentAddressget currentAddress: string | nullSynchronous getter returning the currently active wallet address, or null if not authenticated or no wallet is selected.
currentUserId
currentUserIdget currentUserId: string | nullSynchronous getter returning the authenticated user's ID (JWT sub claim), or null if not authenticated.
Address / Wallet
getAddress(index?)
getAddress(index?)async getAddress(index?: number): Promise<{ address: string; index: number } | null>| Parameter | Type | Required | Description |
|---|---|---|---|
index | number | No | Wallet derivation index. Defaults to the currently selected wallet index. |
Returns: { address: string; index: number } or null if no wallet exists at that index.
Returns the address for a specific HD wallet derivation index. If no index is specified, returns the active wallet's address.
getAddresses()
getAddresses()async getAddresses(): Promise<Array<{ address: string; index: number; name?: string }>>Returns: Array of all wallet addresses for the current user, each with its derivation index and optional user-defined wallet name.
Retrieves all HD wallet addresses derived for this user's account.
createWallet()
createWallet()async createWallet(): Promise<{ address: string }>Returns: { address: string } — the newly created wallet address.
Derives a new HD wallet address for the current user. Requires the user to be authenticated.
selectWallet(currentAddress?)
selectWallet(currentAddress?)async selectWallet(currentAddress?: string): Promise<{ address: string; index: number; name?: string } | null>| Parameter | Type | Required | Description |
|---|---|---|---|
currentAddress | string | No | Address to mark as "currently selected" in the wallet selector modal |
Returns: { address: string; index: number; name? } for the wallet the user selected, or null if the user dismisses the modal.
Opens the wallet selector modal, allowing the user to switch between multiple HD wallets. If currentAddress is provided, the matching wallet entry is highlighted with a "selected" tag.
Chain
getChains()
getChains()async getChains(): Promise<ChainInfo[]>Returns: Array of ChainInfo for all supported chains.
Returns all chains configured for the current project. Does not require authentication — only initialize() must have been called.
getChain(chainId)
getChain(chainId)async getChain(chainId: string): Promise<ChainInfo>| Parameter | Type | Required | Description |
|---|---|---|---|
chainId | string | Yes | CAIP-2 chain ID (e.g. 'eip155:612044') |
Returns: ChainInfo for the specified chain.
Returns configuration for a specific chain. Throws INVALID_CHAIN if chainId is not in CAIP-2 format, or CHAIN_NOT_SUPPORTED if the chain is not registered.
Signing
All signing methods display a user confirmation modal before executing.
signMessage(chainId, message, opts?)
signMessage(chainId, message, opts?)async signMessage(
chainId: string,
message: string,
opts?: SignOptions
): Promise<SignMessageResp>| Parameter | Type | Required | Description |
|---|---|---|---|
chainId | string | Yes | CAIP-2 chain ID (e.g. 'eip155:612044') |
message | string | Yes | Plain-text message to sign |
opts.index | number | No | Wallet derivation index |
opts.dappName | string | No | DApp name shown in the confirmation modal |
opts.accountName | string | No | Account label shown in the confirmation modal |
Returns: SignMessageResp
Signs a UTF-8 message using EIP-191 personal sign. Displays a confirmation modal showing the message content and signer address before proceeding.
signTypedData(chainId, typedData, opts?)
signTypedData(chainId, typedData, opts?)async signTypedData(
chainId: string,
typedData: unknown,
opts?: SignOptions
): Promise<SignTypedDataResp>| Parameter | Type | Required | Description |
|---|---|---|---|
chainId | string | Yes | CAIP-2 chain ID. The numeric part must match typedData.domain.chainId. |
typedData | unknown | Yes | EIP-712 typed data object with domain.chainId |
opts | SignOptions | No | Wallet index and display options |
Returns: SignTypedDataResp
Signs EIP-712 typed structured data for on-chain use. Requires typedData.domain.chainId to match the numeric part of chainId. Throws TYPED_DATA_CHAIN_ID_MISMATCH on mismatch. For typed data without a chain ID, use signTypedDataOffchain().
signTypedDataOffchain(typedData, opts?)
signTypedDataOffchain(typedData, opts?)async signTypedDataOffchain(
typedData: unknown,
opts?: SignOptions
): Promise<SignTypedDataResp>| Parameter | Type | Required | Description |
|---|---|---|---|
typedData | unknown | Yes | EIP-712 typed data object without domain.chainId |
opts | SignOptions | No | Wallet index and display options |
Returns: SignTypedDataResp with chainId: '0'
Signs EIP-712 typed data for off-chain use cases (e.g. permit signatures, order books). Use when typedData.domain.chainId is absent or zero.
signTransaction(chainId, tx, opts?)
signTransaction(chainId, tx, opts?)async signTransaction(
chainId: string,
tx: EvmTransactionRequest,
opts?: SignOptions
): Promise<SignTxResp>| Parameter | Type | Required | Description |
|---|---|---|---|
chainId | string | Yes | CAIP-2 chain ID |
tx | EvmTransactionRequest | Yes | Transaction to sign. tx.from must be non-empty. |
opts | SignOptions | No | Wallet index and display options |
Returns: SignTxResp
Signs a transaction without broadcasting it. Gas fields (gasLimit, gasPrice / maxFeePerGas) are resolved automatically if not provided. Returns the RLP-encoded signed transaction and its hash.
Transactions
sendTransaction(chainId, tx, opts?)
sendTransaction(chainId, tx, opts?)async sendTransaction(
chainId: string,
tx: EvmTransactionRequest,
opts?: SignOptions
): Promise<SendTxResp>| Parameter | Type | Required | Description |
|---|---|---|---|
chainId | string | Yes | CAIP-2 chain ID |
tx | EvmTransactionRequest | Yes | Transaction to broadcast. tx.from must be non-empty. |
opts | SignOptions | No | Wallet index and display options |
Returns: SendTxResp
Signs and broadcasts a transaction. Displays a confirmation modal before signing. Gas fields are auto-resolved if not provided. Returns immediately after broadcast with status: 'pending'.
sendTransactionWithWaitForReceipt(chainId, tx, opts?)
sendTransactionWithWaitForReceipt(chainId, tx, opts?)async sendTransactionWithWaitForReceipt(
chainId: string,
tx: EvmTransactionRequest,
opts?: SignOptions & { intervalMs?: number; timeoutMs?: number }
): Promise<TransactionWithReceipt>| Parameter | Type | Required | Description |
|---|---|---|---|
chainId | string | Yes | CAIP-2 chain ID |
tx | EvmTransactionRequest | Yes | Transaction to broadcast |
opts.intervalMs | number | No | Receipt polling interval in ms (default: from SDKConfig.receiptPolling, fallback 2000) |
opts.timeoutMs | number | No | Polling timeout in ms (default: from SDKConfig.receiptPolling, fallback 60000) |
Returns: TransactionWithReceipt
Signs, broadcasts, and waits for the transaction receipt. Displays a transaction progress modal showing pending and mined states. Polling interval and timeout default to the values set in SDKConfig.receiptPolling.
getTransactionReceipt(txHash, chainId)
getTransactionReceipt(txHash, chainId)async getTransactionReceipt(txHash: string, chainId: string): Promise<TransactionReceipt | null>| Parameter | Type | Required | Description |
|---|---|---|---|
txHash | string | Yes | Transaction hash |
chainId | string | Yes | CAIP-2 chain ID |
Returns: TransactionReceipt if mined, null if still pending.
Fetches the receipt for a specific transaction hash. Returns null if the transaction has not been mined yet.
waitForTxAndGetReceipt(txHash, chainId, opts?)
waitForTxAndGetReceipt(txHash, chainId, opts?)async waitForTxAndGetReceipt(
txHash: string,
chainId: string,
opts?: { intervalMs?: number; timeoutMs?: number }
): Promise<TransactionReceipt>| Parameter | Type | Required | Description |
|---|---|---|---|
txHash | string | Yes | Transaction hash to poll |
chainId | string | Yes | CAIP-2 chain ID |
opts.intervalMs | number | No | Base polling interval in ms (default: 1000) |
opts.timeoutMs | number | No | Timeout in ms (default: 60000) |
Returns: TransactionReceipt
Polls for a transaction receipt until it is mined or the timeout is reached. Polling starts at the base interval (1000 ms by default) and backs off exponentially — doubling after each attempt, capped at 10000 ms. Throws if the timeout expires before the receipt is available.
Gas
getGasPrice(chainId)
getGasPrice(chainId)async getGasPrice(chainId: string): Promise<string>| Parameter | Type | Required | Description |
|---|---|---|---|
chainId | string | Yes | CAIP-2 chain ID |
Returns: Hex-encoded gas price in Wei (e.g. '0x3b9aca00').
Fetches the current gas price via eth_gasPrice. Use for legacy (pre-EIP-1559) transactions. For EIP-1559 chains, prefer getMaxPriorityFeePerGas() and getBaseFeePerGas().
estimateGas(tx, chainId)
estimateGas(tx, chainId)async estimateGas(tx: EvmTransactionRequest, chainId: string): Promise<string>| Parameter | Type | Required | Description |
|---|---|---|---|
tx | EvmTransactionRequest | Yes | Transaction to estimate |
chainId | string | Yes | CAIP-2 chain ID |
Returns: Hex-encoded estimated gas limit (e.g. '0x5208').
Calls eth_estimateGas on the specified chain. The estimate reflects gas required at the current block state. Throws GAS_ESTIMATION_FAILED if the call reverts.
getBaseFeePerGas(chainId)
getBaseFeePerGas(chainId)async getBaseFeePerGas(chainId: string): Promise<string | null>| Parameter | Type | Required | Description |
|---|---|---|---|
chainId | string | Yes | CAIP-2 chain ID |
Returns: Hex-encoded base fee in Wei, or null on chains that do not support EIP-1559.
Fetches the base fee per gas from the latest block header. Returns null on legacy chains.
getMaxPriorityFeePerGas(chainId)
getMaxPriorityFeePerGas(chainId)async getMaxPriorityFeePerGas(chainId: string): Promise<string>| Parameter | Type | Required | Description |
|---|---|---|---|
chainId | string | Yes | CAIP-2 chain ID |
Returns: Hex-encoded EIP-1559 priority fee (tip) in Wei.
Fetches the suggested miner priority fee via eth_maxPriorityFeePerGas. Use with getBaseFeePerGas() to construct EIP-1559 transaction fee fields.
Balance / Nonce / RPC
getBalance(chainId)
getBalance(chainId)async getBalance(chainId: string): Promise<{ wei: string; formatted: string; chainId: string }>| Parameter | Type | Required | Description |
|---|---|---|---|
chainId | string | Yes | CAIP-2 chain ID |
Returns:
| Field | Type | Description |
|---|---|---|
wei | string | Raw balance in Wei as a decimal string |
formatted | string | Human-readable balance in native token units (e.g. '1.5') |
chainId | string | CAIP-2 chain ID the balance was fetched from |
Fetches the native token balance for the current wallet on the specified chain.
getNonce(chainId)
getNonce(chainId)async getNonce(chainId: string): Promise<number>| Parameter | Type | Required | Description |
|---|---|---|---|
chainId | string | Yes | CAIP-2 chain ID |
Returns: Current transaction count (nonce) as a number.
Returns the number of transactions sent from the current wallet address via eth_getTransactionCount. Unlike the mobile SDKs, this returns a number rather than a hex string.
walletRpc(method, params, chainId)
walletRpc(method, params, chainId)async walletRpc(method: string, params: any[], chainId: string): Promise<any>| Parameter | Type | Required | Description |
|---|---|---|---|
method | string | Yes | JSON-RPC method name (e.g. 'eth_call') |
params | any[] | Yes | Method parameters array |
chainId | string | Yes | CAIP-2 chain ID to send the request to |
Returns: JSON-RPC result.
Sends a raw JSON-RPC read-only request to the specified chain's RPC endpoint. Intended for read operations (eth_call, eth_getBalance, eth_getCode, etc.). Do not use for signing or sending transactions.
Provider
getProvider(chainId)
getProvider(chainId)getProvider(chainId: string): CROSSxEthereumProvider| Parameter | Type | Required | Description |
|---|---|---|---|
chainId | string | Yes | CAIP-2 chain ID (e.g. 'eip155:612044') |
Returns: CROSSxEthereumProvider — an EIP-1193 compatible provider.
Returns an EIP-1193 provider bound to the specified chain. Compatible with ethers.js v6, viem, and other libraries that accept an EIP-1193 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?)
applyTheme(themeMode?, themeTokens?)applyTheme(themeMode?: 'light' | 'dark', themeTokens?: SDKThemeTokens): void| Parameter | Type | Required | Description |
|---|---|---|---|
themeMode | 'light' | 'dark' | No | Theme mode to apply |
themeTokens | SDKThemeTokens | No | Color token overrides for light/dark modes |
Changes the confirmation modal theme at runtime. Takes effect on the next modal open. Useful for responding to system dark mode changes dynamically.
applyLocale(locale?)
applyLocale(locale?)applyLocale(locale?: 'ko' | 'en'): void| Parameter | Type | Required | Description |
|---|---|---|---|
locale | 'ko' | 'en' | No | Language for modal UI text |
Changes the confirmation modal language at runtime. Takes effect on the next modal open.
sdk.applyLocale('ko')
sdk.applyLocale('en')PIN Management
setPin(pin)
setPin(pin)setPin(pin: string): void| Parameter | Type | Required | Description |
|---|---|---|---|
pin | string | Yes | PIN to cache in memory |
Caches the user's PIN in memory so that signing flows can proceed without displaying a PIN input modal. The PIN is kept only in memory and cleared on clearPin() or signOut().
clearPin()
clearPin()clearPin(): voidClears the cached PIN from memory. Subsequent signing flows that require a PIN will prompt the user via the SDK modal.
hasPin()
hasPin()hasPin(): booleanReturns: true if a PIN is currently cached in memory, false otherwise.
Checks whether a PIN is cached without exposing the PIN value.
isPinRequired()
isPinRequired()isPinRequired(): booleanReturns: true if the next sign/send operation will require PIN entry (no PIN cached in memory), false otherwise.
Use this to decide whether to show your own PIN prompt before a signing flow:
if (sdk.isPinRequired()) {
const pin = await showPinModal()
sdk.setPin(pin)
}
await sdk.signMessage(chainId, message)setPinKeyboard(mode)
setPinKeyboard(mode)setPinKeyboard(mode: 'virtual' | 'native' | (() => 'virtual' | 'native')): void| Parameter | Type | Required | Description |
|---|---|---|---|
mode | 'virtual' | 'native' | (() => 'virtual' | 'native') | Yes | Keyboard mode: 'virtual' (SDK-rendered numpad), 'native' (OS keyboard), or a function evaluated each time the PIN modal opens |
Changes the PIN input modal's keyboard mode at runtime. Takes effect on the next PIN modal open. Also configurable at creation time via SDKConfig.pinKeyboard.
changePin(oldPin, newPin)
changePin(oldPin, newPin)async changePin(oldPin: string, newPin: string): Promise<void>| Parameter | Type | Required | Description |
|---|---|---|---|
oldPin | string | Yes | Current PIN |
newPin | string | Yes | New PIN to set |
Changes the user's PIN on the server. The new PIN must satisfy format requirements (no sequential or repeated digit patterns). Throws PIN_WRONG if oldPin is incorrect, or PIN_INVALID / PIN_REPEATED_PATTERN if the new PIN is rejected.
Migration
migrateWallet(pin)
migrateWallet(pin)async migrateWallet(pin: string): Promise<MigrateResult>| Parameter | Type | Required | Description |
|---|---|---|---|
pin | string | Yes | 4-digit PIN used during original CROSSx wallet creation |
Returns: MigrateResult
Migrates a legacy CROSSx wallet to an Embedded Wallet using the original 4-digit PIN. After migration, the wallet is accessible via the standard wallet API. Throws MIGRATION_FAILED on failure or MIGRATION_PIN_LOCKED after too many incorrect PIN attempts.
Token History
registerTokenHistory(chainId, txHash, clientVersion)
registerTokenHistory(chainId, txHash, clientVersion)async registerTokenHistory(
chainId: string,
txHash: string,
clientVersion: string
): Promise<void>| Parameter | Type | Required | Description |
|---|---|---|---|
chainId | string | Yes | CAIP-2 chain ID (e.g. 'eip155:1') |
txHash | string | Yes | Transaction hash to register |
clientVersion | string | Yes | Client version string (max 64 chars, e.g. 'my-dapp/1.2.3') |
Registers a wallet-sent coin/ERC-20 transfer in the token history service. The transaction must already be indexed, have succeeded (status == 1), and be an ERC-20 transfer (0xa9059cbb) or coin transfer (0x00000000). Throws CROSSxError on validation or API errors.
getTokenHistory(options?)
getTokenHistory(options?)async getTokenHistory(options?: {
lastTimestamp?: number
lastTxIndex?: number
}): Promise<TokenHistoryItem[]>| Parameter | Type | Required | Description |
|---|---|---|---|
options.lastTimestamp | number | No | Cursor: timestamp of the last item from the previous page |
options.lastTxIndex | number | No | Cursor: tx_index of the last item from the previous page |
Returns: TokenHistoryItem[]
Fetches transactions previously registered via registerTokenHistory(). Supports cursor-based pagination:
const history = await sdk.getTokenHistory()
if (history.length > 0) {
const last = history[history.length - 1]
const nextPage = await sdk.getTokenHistory({
lastTimestamp: last.timestamp,
lastTxIndex: last.tx_index,
})
}Events
CROSSxSDK extends TypedEventEmitter<SDKEventMap> and supports typed event subscription.
on(event, listener)
on(event, listener)on(event: string, listener: Function): () => voidSubscribes to an SDK event. Returns an unsubscribe function.
off(event, listener)
off(event, listener)off(event: string, listener: Function): voidRemoves an event listener.
Event Types
| Event | Payload | Description |
|---|---|---|
authChanged | { isAuthenticated: boolean, address: string | null, userId: string | null, source?: 'external' } | Fired when auth state changes (sign in / sign out). source: 'external' marks sign-ins performed via signInWithOAuthToken() |
addressChanged | { address: string, index: number, walletName?: string } | Fired when the active wallet address changes |
initialized | { restored: boolean } | Fired when SDK initialization completes |
connectExternalWallet | { walletId: string } | Fired when the user selects an external wallet row in the login modal (walletId = ConnectOtherWalletItem value) |
const unsub = sdk.on('authChanged', (event) => {
console.log(event.isAuthenticated, event.address)
})
// Cleanup
unsub()Lifecycle
dispose()
dispose()dispose(): voidCleans up SDK resources including event listeners and internal state. The instance cannot be used after this call. Call this when unmounting an SDK host component or tearing down the application.
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; name?: string }> | Full wallet address list (with optional user-defined wallet names) |
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 |
TokenHistoryItem
TokenHistoryItem| Field | Type | Description |
|---|---|---|
tx | string | Transaction hash |
chain_id | number | Numeric chain ID |
block_number | number | Block number |
tx_index | number | Transaction index (pagination cursor) |
from / to | string | Sender / recipient address |
from_alias / to_alias | string? | Address aliases (if any) |
token | string | Token address (0x0...0 for native coin on all chains) |
amount | string | Transfer amount (wei / smallest unit) |
timestamp | number | Unix timestamp in seconds (pagination cursor) |
status | string | 'success' | 'fail' |
gas_price / gas_used / max_fee_per_gas / nonce | number? | Gas / nonce details |
method | number[] | null | Method ID bytes |
method_alias | string? | Method alias (if any) |
GetTokenHistoryResponse
GetTokenHistoryResponse| Field | Type | Description |
|---|---|---|
rows | TokenHistoryItem[] | History items |
last_data | { last_timestamp?: number; last_tx_index?: number }? | Pagination cursor |
RegisterTokenHistoryRequest
RegisterTokenHistoryRequest| Field | Type | Description |
|---|---|---|
clientVersion | string | Client version (required, max 64 chars) |
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 |
SESSION_EXPIRED | Session expired — both access and refresh tokens invalid, re-login required (see signInAgain()) |
OAUTH_POPUP_BLOCKED | OAuth popup was blocked or could not be opened |
WALLET_NOT_FOUND | Wallet not found |
WALLET_CREATION_FAILED | Wallet creation failed |
WALLET_ALREADY_EXISTS | Wallet already exists for this user (gateway -10004) |
ADDRESS_LIMIT_EXCEEDED | Derived address count exceeds the server limit (gateway -10036). The limit (MNEMONIC_ADDRESS_LIMIT = 100) is passed in error.details.limit |
WALLET_INCONSISTENT_STATE | Wallet state inconsistency detected |
SIGN_FAILED | Signing failed |
SIGN_REJECTED | Signing rejected |
SIGNATURE_FAILED | Signature operation failed |
TX_FAILED | Transaction failed |
TX_REJECTED | Transaction rejected |
TRANSACTION_FAILED | Transaction operation failed |
TX_INVALID_PARAMS | Invalid transaction parameters |
NOT_IMPLEMENTED | Feature not implemented |
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 |
PIN_ENCRYPTION_INVALID | PIN ciphertext invalid (gateway -10045) — e.g. stale cached public key. Not counted toward PIN lock; surfaces only after the SDK's automatic retry also fails |
PIN_POLICY_VIOLATION | PIN policy violation (gateway -10046) |
PIN_ENCRYPTION_FAILED | PIN encryption itself failed (public key fetch/import or WebCrypto failure); no plaintext fallback |
BROADCAST_FAILED | Transaction broadcast failed (-10007) |
GATEWAY_INTERNAL_ERROR | Gateway internal error (-10006), retry recommended |
GATEWAY_LOCK_CONFLICT | Lock conflict (-10008), retry recommended |
HMAC_REQUIRED | HMAC signature header missing (gateway -10040) |
HMAC_VERIFICATION_FAILED | HMAC signature verification failed (gateway -10041) |
WITHDRAW_FAILED | Account withdrawal failed (gateway -10013) |
USER_NOT_FOUND | User not found on gateway (-10033) — forces logout |
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 | Chain name | Native symbol |
|---|---|---|---|
ChainId.ONE_MAINNET | 'eip155:612055' | ONEchain Mainnet | ONE |
ChainId.ONE_TESTNET | 'eip155:612044' | ONEchain Testnet | tONE |
ChainId.BSC_MAINNET | 'eip155:56' | BNB Smart Chain | BNB |
ChainId.BSC_TESTNET | 'eip155:97' | BNB Smart Chain Testnet | BNB |
ChainId.RONIN_MAINNET | 'eip155:2020' | Ronin | RON |
ChainId.RONIN_SAIGON | 'eip155:202601' | Ronin Saigon | RON |
ChainId.CROSS_MAINNET/ChainId.CROSS_TESTNETwere renamed toChainId.ONE_MAINNET/ChainId.ONE_TESTNET. The CAIP-2 values are unchanged.
Public Type Exports
import type {
SDKConfig,
SDKThemeTokens,
SDKColorOverrides,
AuthResult,
SignInWithCreateResult,
SignInOptions,
SignInWithCreateOptions,
SignOptions,
SDKUserInfo,
UserInfo,
EvmTransactionRequest,
SignMessageResp,
SignTypedDataResp,
SignTxResp,
SendTxResp,
TransactionWithReceipt,
MigrateResult,
ChainInfo,
ChainIdValue,
AddressInfo,
SDKEventMap,
AuthChangedEvent,
AddressChangedEvent,
InitializedEvent,
ConnectExternalWalletEvent,
LoginSelectorResult,
TokenHistoryItem,
GetTokenHistoryResponse,
RegisterTokenHistoryRequest,
PrepareAction,
PrepareContext,
PrepareResult,
EIP1193Provider,
} from '@nexus-cross/crossx-sdk-core'
import {
createCROSSxSDK,
CROSSxSDK,
CROSSxEthereumProvider,
ChainId,
CROSSxError,
ErrorCode,
MNEMONIC_ADDRESS_LIMIT, // 100 — max derivable addresses (ADDRESS_LIMIT_EXCEEDED)
WALLET_BRAND_NAME, // 'ONEpocket' — user-facing wallet brand name
parseOAuthDeeplink, // parse OAuth deeplinks (RN WebView integration)
getWalletBrowserInfo, // detect the wallet in-app browser
isWalletInAppBrowser,
waitForWalletBrowser,
ConnectOtherWalletItem, // external wallet IDs for SDKConfig.connectOtherWallets
CONNECT_OTHER_WALLET_DISPLAY_ORDER,
getConnectOtherWalletLabel,
} from '@nexus-cross/crossx-sdk-core'Rebrand aliases
The wallet's display brand is ONEpocket (formerly CROSSx). The following exports are aliases of the CROSSx names — identical values/classes, both names remain available:
| Alias | Same as |
|---|---|
createONEpocketSDK | createCROSSxSDK |
ONEpocketSDK | CROSSxSDK |
ONEpocketError | CROSSxError |
ONEpocketEthereumProvider | CROSSxEthereumProvider |
Updated 2 days ago