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 alias | Same as |
|---|---|
onepocketConnector | crossxConnector |
createONEpocketConnector | createCROSSxConnector |
ONEpocketEIP1193Provider | CROSSxEIP1193Provider |
OnepocketConnectorOptions (type) | CrossxConnectorOptions |
ONEpocketConnectorOptions (type) | CROSSxConnectorOptions |
crossxConnector(options)
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
CrossxConnectorOptionsAll fields from SDKConfig (except useMockWallet) plus:
| Option | Type | Default | Description |
|---|---|---|---|
projectId | string | — | Required. Project ID from console |
appName | string | — | Required. App name for confirmation modals |
defaultChainId | string | number | 'eip155:612055' | Initial chain ID (CAIP-2 or number) |
theme | 'light' | 'dark' | 'light' | Confirmation modal theme |
themeTokens | SDKThemeTokens? | — | Per-mode color overrides |
debug | boolean? | false | Enable debug logging |
receiptPolling | object? | — | { intervalMs, timeoutMs } |
showConnectOtherWallets | boolean? | false | Show "Connect with Other Wallets" button in login modal |
getStoredWalletIndex | () => number | localStorage | Callback to retrieve persisted wallet index on reconnection |
onWalletIndexChanged | (index: number) => void | localStorage | Callback invoked when active wallet index changes |
getStoredWalletAddress | () => string | null | localStorage | Callback to retrieve the persisted active wallet address on reconnection |
onWalletAddressChanged | (address: string) => void | localStorage | Callback invoked when the active wallet address changes |
clearStoredWalletAddress | () => void | localStorage | Callback 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 |
defaultChainIdaccepts 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)
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
CROSSxConnectorOptions| Option | Type | Default | Description |
|---|---|---|---|
sdk | CROSSxSDK | — | Required. Pre-created SDK instance |
defaultChainId | string | number | 'eip155:612055' | Initial chain ID |
getStoredWalletIndex | () => number | localStorage | Callback to retrieve persisted wallet index on reconnection |
onWalletIndexChanged | (index: number) => void | localStorage | Callback invoked when active wallet index changes (e.g. after sign-in wallet selection) |
getStoredWalletAddress | () => string | null | localStorage | Callback to retrieve the persisted active wallet address on reconnection |
onWalletAddressChanged | (address: string) => void | localStorage | Callback invoked when the active wallet address changes |
clearStoredWalletAddress | () => void | localStorage | Callback 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 |
defaultChainIdaccepts 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.
| Property | Value |
|---|---|
connector.id | 'crossx' |
connector.name | 'ONEpocket' |
connector.type | 'crossx' |
connector.namefollows the wallet brand name (WALLET_BRAND_NAMEfrom@nexus-cross/crossx-sdk-core), which is'ONEpocket'since the rebrand.connector.idremains'crossx'for backward compatibility — keep usingconnectors.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.).
| Method | Description |
|---|---|
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.
| Method | Description |
|---|---|
eth_requestAccounts / eth_accounts | Returns connected address |
eth_chainId | Returns hex chain ID |
net_version | Returns network version string |
personal_sign | Signs a message (EIP-191) |
eth_sign | Signs a message |
eth_signTypedData | Signs typed data (EIP-712) |
eth_signTypedData_v3 | Signs typed data v3 (EIP-712) |
eth_signTypedData_v4 | Signs typed data v4 (EIP-712) |
eth_sendTransaction | Sends a transaction |
wallet_switchEthereumChain | Switches chain |
wallet_addEthereumChain | Acknowledged (no-op) |
eth_call, eth_getBalance, etc. | Proxied to chain RPC via SDK walletRpc |
Off-chain typed data signing: when
domain.chainIdis absent or0,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.
| Method | Description |
|---|---|
setWalletIndex(index: number) | Sets the active wallet derivation index |
getWalletIndex(): number | Returns 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
@nexus-cross/crossx-sdk-core| Feature | sdk-core | sdk-wagmi |
|---|---|---|
| wagmi hooks | Not available | Full support |
| EIP-1193 Provider | Manual via sdk.getProvider() | Automatic via connector |
| Chain switching | Manual | useSwitchChain hook |
| Session management | Manual signIn() / signOut() | useConnect / useDisconnect |
| Recommended for | Vanilla JS, custom setups | React + 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:
- SDK emits
connectExternalWalletevent - SDK throws
CROSSxError(EXTERNAL_WALLET_REQUESTED) - Connector catches the error and converts it to
UserRejectedRequestError - wagmi's
connect()fails gracefully —isConnectedstaysfalse
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
Updated 2 days ago