Guides
NEXUS
Guides

API Reference

Wagmi SDK — API Reference

This page documents the public API surface of @nexus-cross/crossx-sdk-wagmi.

Exports

import {
  crossxConnector,         // Simple mode — SDK auto-created
  createCROSSxConnector,   // Advanced mode — inject your own SDK
  CROSSxEIP1193Provider,   // EIP-1193 Provider (rarely used directly)
} from '@nexus-cross/crossx-sdk-wagmi'

import type {
  CrossxConnectorOptions,
  CROSSxConnectorOptions,
  EIP1193RequestArguments,
} from '@nexus-cross/crossx-sdk-wagmi'

Rebrand aliases (ONEpocket)

As part of the ONEpocket rebrand, every crossx* export also ships under a ONEpocket name. The aliases are identical in behavior — pick one naming and use it consistently:

ONEpocket aliasSame as
onepocketConnectorcrossxConnector
createONEpocketConnectorcreateCROSSxConnector
ONEpocketEIP1193ProviderCROSSxEIP1193Provider
OnepocketConnectorOptions (type)CrossxConnectorOptions
ONEpocketConnectorOptions (type)CROSSxConnectorOptions

crossxConnector(options)

import { crossxConnector } from '@nexus-cross/crossx-sdk-wagmi'

const connector = crossxConnector({
  projectId: 'YOUR_PROJECT_ID',
  appName: 'My DApp',
  theme: 'dark',
})

Creates a wagmi connector with an internally managed SDK instance. Use this for most setups — the connector handles SDK creation, initialization, and lifecycle automatically. For cases where you need to share a single SDK instance across wagmi and non-wagmi code, use createCROSSxConnector() instead.

CrossxConnectorOptions

All fields from SDKConfig (except useMockWallet) plus:

OptionTypeDefaultDescription
projectIdstringRequired. Project ID from console
appNamestringRequired. App name for confirmation modals
defaultChainIdstring | number'eip155:612055'Initial chain ID (CAIP-2 or number)
theme'light' | 'dark''light'Confirmation modal theme
themeTokensSDKThemeTokens?Per-mode color overrides
debugboolean?falseEnable debug logging
receiptPollingobject?{ intervalMs, timeoutMs }
showConnectOtherWalletsboolean?falseShow "Connect with Other Wallets" button in login modal
getStoredWalletIndex() => numberlocalStorageCallback to retrieve persisted wallet index on reconnection
onWalletIndexChanged(index: number) => voidlocalStorageCallback invoked when active wallet index changes
getStoredWalletAddress() => string | nulllocalStorageCallback to retrieve the persisted active wallet address on reconnection
onWalletAddressChanged(address: string) => voidlocalStorageCallback invoked when the active wallet address changes
clearStoredWalletAddress() => voidlocalStorageCallback invoked on disconnect()/sign-out to remove the persisted wallet address
openConnectOtherWallet(() => void)?Callback invoked when the user clicks an external wallet row in the login modal. Providing it auto-enables showConnectOtherWallets (unless connectOtherWallets/showConnectOtherWallets is already set) and registers the callback on the SDK's connectExternalWallet event

defaultChainId accepts both CAIP-2 format ('eip155:612055') and numeric format (612055).

By default, the wallet index and the active wallet address are automatically persisted in localStorage (keys: crossx-wallet-index, crossx-wallet-address). Provide custom callbacks only if you need a different storage mechanism (e.g. cookies for SSR).

createCROSSxConnector(options)

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

const sdk = createCROSSxSDK({ projectId: 'YOUR_PROJECT_ID', appName: 'My DApp' })
const connector = createCROSSxConnector({ sdk })

Creates a wagmi connector using an externally created SDK instance. Use this when you need to share a single SDK instance between wagmi and other parts of your application (e.g. a React context, a React Native bridge, or server-side code).

CROSSxConnectorOptions

OptionTypeDefaultDescription
sdkCROSSxSDKRequired. Pre-created SDK instance
defaultChainIdstring | number'eip155:612055'Initial chain ID
getStoredWalletIndex() => numberlocalStorageCallback to retrieve persisted wallet index on reconnection
onWalletIndexChanged(index: number) => voidlocalStorageCallback invoked when active wallet index changes (e.g. after sign-in wallet selection)
getStoredWalletAddress() => string | nulllocalStorageCallback to retrieve the persisted active wallet address on reconnection
onWalletAddressChanged(address: string) => voidlocalStorageCallback invoked when the active wallet address changes
clearStoredWalletAddress() => voidlocalStorageCallback invoked on disconnect()/sign-out to remove the persisted wallet address
openConnectOtherWallet(() => void)?Callback registered on the SDK's connectExternalWallet event. In advanced mode the external wallet section only appears if the injected SDK was created with showConnectOtherWallets or connectOtherWallets

defaultChainId accepts both CAIP-2 format ('eip155:612055') and numeric format (612055).

By default, the wallet index and the active wallet address are automatically persisted in localStorage (keys: crossx-wallet-index, crossx-wallet-address). Provide custom callbacks only if you need a different storage mechanism.

Connector Properties

The returned connector exposes the following identity properties, used by wagmi internally to identify the connector.

PropertyValue
connector.id'crossx'
connector.name'ONEpocket'
connector.type'crossx'

connector.name follows the wallet brand name (WALLET_BRAND_NAME from @nexus-cross/crossx-sdk-core), which is 'ONEpocket' since the rebrand. connector.id remains 'crossx' for backward compatibility — keep using connectors.find(c => c.id === 'crossx').

Connector Methods

These methods conform to the wagmi connector interface. In most cases you interact with them indirectly through wagmi hooks (useConnect, useDisconnect, useSwitchChain, etc.).

MethodDescription
setup()Initializes SDK and wires events
connect()Opens OAuth sign-in via signInWithCreate() and returns account + chain. When "Connect with Other Wallets" is selected, throws UserRejectedRequestError (silent disconnect)
disconnect()Signs out and clears session
getAccounts()Returns connected addresses
getChainId()Returns current chain ID
getProvider()Returns EIP-1193 provider
isAuthorized()Awaits SDK initialization, then checks if session is valid (standard since v1.2.5)
switchChain({ chainId })Switches active chain

EIP-1193 Provider — Supported RPC Methods

The EIP-1193 provider returned by connector.getProvider() handles the following JSON-RPC methods. Signing and transaction methods route through the SDK confirmation modal flow; read methods are proxied to the chain RPC.

MethodDescription
eth_requestAccounts / eth_accountsReturns connected address
eth_chainIdReturns hex chain ID
net_versionReturns network version string
personal_signSigns a message (EIP-191)
eth_signSigns a message
eth_signTypedDataSigns typed data (EIP-712)
eth_signTypedData_v3Signs typed data v3 (EIP-712)
eth_signTypedData_v4Signs typed data v4 (EIP-712)
eth_sendTransactionSends a transaction
wallet_switchEthereumChainSwitches chain
wallet_addEthereumChainAcknowledged (no-op)
eth_call, eth_getBalance, etc.Proxied to chain RPC via SDK walletRpc

Off-chain typed data signing: when domain.chainId is absent or 0, signTypedDataOffchain() is used internally.

EIP-1193 Provider — Helper Methods

These methods are available on the provider instance returned by connector.getProvider(). They manage the active wallet index for multi-wallet scenarios and are called by the connector internally after wallet selection.

MethodDescription
setWalletIndex(index: number)Sets the active wallet derivation index
getWalletIndex(): numberReturns the current wallet index
getCurrentAccounts(): string[]Returns the currently tracked accounts
notifyAccountsChanged(accounts: string[])Updates tracked accounts and emits accountsChanged event

Chain Configuration

Use defineChain from viem to configure ONEchain for wagmi:

import { defineChain } from 'viem'

export const oneMainnet = defineChain({
  id: 612055,
  name: 'ONEchain Mainnet',
  nativeCurrency: { name: 'ONE', symbol: 'ONE', decimals: 18 },
  rpcUrls: {
    default: { http: ['https://mainnet.onechain.nexus:22001'] },
  },
})

export const oneTestnet = defineChain({
  id: 612044,
  name: 'ONEchain Testnet',
  nativeCurrency: { name: 'tONE', symbol: 'tONE', decimals: 18 },
  rpcUrls: {
    default: { http: ['https://testnet.onechain.nexus:22001'] },
  },
})

Difference from @nexus-cross/crossx-sdk-core

Featuresdk-coresdk-wagmi
wagmi hooksNot availableFull support
EIP-1193 ProviderManual via sdk.getProvider()Automatic via connector
Chain switchingManualuseSwitchChain hook
Session managementManual signIn() / signOut()useConnect / useDisconnect
Recommended forVanilla JS, custom setupsReact + wagmi apps

Connect with Other Wallets Behavior

When showConnectOtherWallets is enabled in the SDK config, the login selector modal includes a "Connect with Other Wallets" button. When clicked:

  1. SDK emits connectExternalWallet event
  2. SDK throws CROSSxError(EXTERNAL_WALLET_REQUESTED)
  3. Connector catches the error and converts it to UserRejectedRequestError
  4. wagmi's connect() fails gracefully — isConnected stays false

The DApp should register an event listener to handle external wallet connections:

sdk.on('connectExternalWallet', () => {
  // Open MetaMask, WalletConnect, or any other connector
})

See Authentication — Connect with Other Wallets for full example.

Reconnect Behavior

wagmi internally calls connector.setup() without await. In early SDK versions (before v1.2.5), this caused isAuthorized() to return false before SDK initialization completed, breaking automatic reconnection after page refresh.

Since v1.2.5 — and in every 2.x release — the connector's isAuthorized() automatically ensures SDK initialization (including session restore) before checking authentication state. This eliminates the race condition — no workaround code is needed in your DApp.

// Internal connector behavior (automatic)
async isAuthorized() {
  await ensureSdkInitialized()   // waits for initialize() to finish
  return sdk.isAuthenticated()   // returns correct state
}

See Troubleshooting for details and migration from older versions.

Related