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'crossxConnector(options)
crossxConnector(options)Creates a wagmi connector with an internally managed SDK instance.
import { crossxConnector } from '@nexus-cross/crossx-sdk-wagmi'
const connector = crossxConnector({
projectId: 'YOUR_PROJECT_ID',
appName: 'My DApp',
theme: 'dark',
})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 |
defaultChainIdaccepts both CAIP-2 format ('eip155:612055') and numeric format (612055).By default, wallet index is automatically persisted in
localStorage(key:crossx-wallet-index). Provide custom callbacks only if you need a different storage mechanism (e.g. cookies for SSR).
createCROSSxConnector(options)
createCROSSxConnector(options)Creates a wagmi connector using an externally created SDK instance.
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 })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) |
defaultChainIdaccepts both CAIP-2 format ('eip155:612055') and numeric format (612055).By default, wallet index is automatically persisted in
localStorage(key:crossx-wallet-index). Provide custom callbacks only if you need a different storage mechanism.
Connector Properties
| Property | Value |
|---|---|
connector.id | 'crossx' |
connector.name | 'CROSSx Wallet' |
connector.type | 'crossx' |
Connector Methods
| 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 (v1.2.5+) |
switchChain({ chainId }) | Switches active chain |
EIP-1193 Provider — Supported RPC Methods
| 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 are used to manage the active wallet index for multi-wallet scenarios.
| 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
import { defineChain } from 'viem'
export const crossMainnet = defineChain({
id: 612055,
name: 'CROSS Mainnet',
nativeCurrency: { name: 'CROSS', symbol: 'CROSS', decimals: 18 },
rpcUrls: {
default: { http: ['https://mainnet.crosstoken.io:22001'] },
},
})
export const crossTestnet = defineChain({
id: 612044,
name: 'CROSS Testnet',
nativeCurrency: { name: 'tCROSS', symbol: 'tCROSS', decimals: 18 },
rpcUrls: {
default: { http: ['https://testnet.crosstoken.io: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 (v1.2.5+)
wagmi internally calls connector.setup() without await. In earlier SDK versions, this caused isAuthorized() to return false before SDK initialization completed, breaking automatic reconnection after page refresh.
Since v1.2.5, the connector's isAuthorized() automatically awaits sdk.whenReady() before checking authentication state. This eliminates the race condition — no workaround code is needed in your DApp.
// Internal connector behavior (automatic)
async isAuthorized() {
await sdk.whenReady() // waits for setup() → initialize() to finish
return sdk.isAuthenticated() // returns correct state
}See Troubleshooting for details and migration from older versions.
Related
Updated 7 days ago