API Reference
React SDK — API Reference
This page documents the public API surface of @nexus-cross/crossx-sdk-react.
Components
CROSSxProvider
CROSSxProviderimport { CROSSxProvider } from '@nexus-cross/crossx-sdk-react'
<CROSSxProvider config={SDKConfig}>
{children}
</CROSSxProvider>| Prop | Type | Description |
|---|---|---|
config | SDKConfig | SDK configuration (see Core SDK Config) |
children | ReactNode | Child components |
Wraps the application (or a subtree) and provides the SDK instance via React context. Internally creates a CROSSxSDK instance, calls initialize() on mount, and keeps auth state in sync via the SDK's authChanged and addressChanged events using useSyncExternalStore. All hooks below must be used within a CROSSxProvider.
Hooks
useAuth()
useAuth()const {
isAuthenticated,
isLoading,
error,
signIn,
signInWithCreate,
signOut,
} = useAuth()| Property | Type | Description |
|---|---|---|
isAuthenticated | boolean | true if user is logged in (reactive) |
isLoading | boolean | true during sign-in/out operations |
error | string | null | Last authentication error message |
signIn | () => Promise<AuthResult> | Open OAuth sign-in (provider selector modal) |
signInWithCreate | () => Promise<SignInWithCreateResult> | Sign in + auto wallet creation + migration |
signOut | () => Promise<void> | Clear session |
Returns reactive auth state and auth action methods. isAuthenticated updates automatically when the underlying SDK emits authChanged. signIn() and signInWithCreate() do not accept options — they open the provider selector modal directly. For programmatic provider selection, access the SDK via useCROSSx().sdk.
useWallet()
useWallet()const {
address,
isLoading,
error,
signMessage,
sendTransaction,
} = useWallet()| Property | Type | Description |
|---|---|---|
address | string | null | Current wallet address (reactive) |
isLoading | boolean | Loading state |
error | string | null | Last error message |
signMessage | (chainId: string, message: string) => Promise<SignMessageResp> | Sign personal message |
sendTransaction | (chainId: string, tx: EvmTransactionRequest) => Promise<SendTxResp> | Send transaction |
Returns the current wallet address and basic wallet operation methods. address updates automatically when the SDK emits addressChanged. For advanced operations (balance, gas, typed data signing, provider access, etc.), use useCROSSx().sdk to call Core SDK methods directly.
useCROSSx()
useCROSSx()const { sdk, isInitialized, isAuthenticated, walletAddress } = useCROSSx()| Property | Type | Description |
|---|---|---|
sdk | CROSSxSDK | null | Direct SDK instance access |
isInitialized | boolean | true after initialize() completes |
isAuthenticated | boolean | Reactive auth state (synced via authChanged event) |
walletAddress | string | null | Reactive address (synced via addressChanged event) |
Provides direct access to the underlying CROSSxSDK instance and reactive state from context. Use sdk to call any method from the Core SDK API, including selectWallet(currentAddress?) for multi-wallet selection. Throws if called outside a CROSSxProvider.
Type Re-exports
All types are re-exported from @nexus-cross/crossx-sdk-core:
import type {
SDKConfig,
AuthResult,
SignMessageResp,
SendTxResp,
SignInOptions,
EvmTransactionRequest,
ChainIdValue,
} from '@nexus-cross/crossx-sdk-react'
import { ChainId } from '@nexus-cross/crossx-sdk-react'Difference from @nexus-cross/crossx-sdk-wagmi
@nexus-cross/crossx-sdk-wagmi| Feature | sdk-react | sdk-wagmi |
|---|---|---|
| wagmi dependency | None | Required |
| wagmi hooks | Not available | Full support |
| Setup complexity | Simple | Medium |
| Recommended for | Non-wagmi React apps | wagmi-based apps |