crossx-20-js-react
CROSSx React Skill
Documentation
- Getting Started
- Authentication
- Wallet
- EIP-1193 Provider
- API Reference
- Core SDK Config — SDKConfig options
Dependency
npm install @nexus-cross/crossx-sdk-core @nexus-cross/crossx-sdk-reactInstructions
Identify the request category first, then make the smallest React/TypeScript changes that fit the existing component and hook structure.
Treat the CROSSx React documentation linked above as the primary source for SDK usage, integration flow, and hook patterns.
If the bundled React docs do not fully answer the question or the latest SDK behavior is unclear, prefer the official cross MCP server before unrelated documentation sources.
File Discovery
Before editing, find the existing integration points for provider setup, hook usage, and wallet-related actions.
Check these first when they exist:
package.json(dependency setup)- App entry point where
CROSSxProvideris or should be placed (e.g.main.tsx,index.tsx,_app.tsx) - Components using
useAuth,useWallet, oruseCROSSx - Existing auth, wallet, settings, or blockchain-related components
Prefer extending existing integration points over introducing new components or wrappers.
Request Classification
Classify each request into one or more of these categories before writing code:
- SDK setup: package install,
CROSSxProviderplacement,SDKConfigoptions - Authentication:
useAuthhook —signIn,signOut,signInWithCreate,isAuthenticated,isLoading - Wallet:
useWallethook —address,signMessage,sendTransaction - Direct SDK access:
useCROSSxhook —sdkinstance for anyCROSSxSDKmethod - Theme and locale:
SDKConfigtheme options inCROSSxProvider
If a request spans multiple categories, handle provider setup and authentication prerequisites before wallet, signing, or RPC work.
Key Types Reference
CROSSxProvider
interface CROSSxProviderProps {
config: SDKConfig;
children: React.ReactNode;
}
// Automatically calls sdk.initialize() on mount
// Subscribes to authChanged and addressChanged events
function CROSSxProvider({ config, children }: CROSSxProviderProps): JSX.Element;useCROSSx Hook
interface CROSSxContextValue {
sdk: CROSSxSDK | null;
isInitialized: boolean;
isAuthenticated: boolean;
walletAddress: string | null;
}
function useCROSSx(): CROSSxContextValue;useAuth Hook
function useAuth(): {
isAuthenticated: boolean;
isLoading: boolean;
error: string | null;
signIn: () => Promise<AuthResult>;
signInWithCreate: () => Promise<SignInWithCreateResult>;
signOut: () => Promise<void>;
};useWallet Hook
function useWallet(): {
address: string | null;
isLoading: boolean;
error: string | null;
signMessage: (chainId: string, message: string) => Promise<SignMessageResp>;
sendTransaction: (chainId: string, tx: EvmTransactionRequest) => Promise<SendTxResp>;
};SDKConfig
See the Core SDK skill for full SDKConfig interface. Key fields:
interface SDKConfig {
projectId: string; // required
appName: string; // required
theme?: 'light' | 'dark';
autoDetectTheme?: boolean;
themeTokens?: SDKThemeTokens;
locale?: SDKLocale;
// ... see Core SDK for complete list
}Core API Signatures
Provider Setup
import { CROSSxProvider } from '@nexus-cross/crossx-sdk-react';
import type { SDKConfig } from '@nexus-cross/crossx-sdk-core';
const config: SDKConfig = {
projectId: 'YOUR_PROJECT_ID',
appName: 'My DApp',
};
function App() {
return (
<CROSSxProvider config={config}>
<MyApp />
</CROSSxProvider>
);
}Authentication with useAuth
import { useAuth } from '@nexus-cross/crossx-sdk-react';
function LoginButton() {
const { isAuthenticated, isLoading, signIn, signInWithCreate, signOut } = useAuth();
if (isLoading) return <p>Loading...</p>;
if (isAuthenticated) {
return <button onClick={signOut}>Sign Out</button>;
}
return <button onClick={signInWithCreate}>Sign In</button>;
}Wallet Operations with useWallet
import { useWallet } from '@nexus-cross/crossx-sdk-react';
import { ChainId } from '@nexus-cross/crossx-sdk-core';
function WalletActions() {
const { address, signMessage, sendTransaction } = useWallet();
const handleSign = async () => {
const result = await signMessage(ChainId.CROSS_MAINNET, 'Hello CROSSx');
console.log('Signature:', result.signature);
};
const handleSend = async () => {
const result = await sendTransaction(ChainId.CROSS_MAINNET, {
to: '0xReceiverAddress',
value: '0xDE0B6B3A7640000',
});
console.log('TX Hash:', result.txHash);
};
return (
<div>
<p>Address: {address}</p>
<button onClick={handleSign}>Sign Message</button>
<button onClick={handleSend}>Send Transaction</button>
</div>
);
}Direct SDK Access with useCROSSx
import { useCROSSx } from '@nexus-cross/crossx-sdk-react';
import { ChainId } from '@nexus-cross/crossx-sdk-core';
function AdvancedComponent() {
const { sdk, isInitialized, isAuthenticated, walletAddress } = useCROSSx();
const getBalance = async () => {
if (!sdk) return;
const balance = await sdk.getBalance(ChainId.CROSS_MAINNET);
console.log('Balance:', balance.formatted);
};
const getRpcData = async () => {
if (!sdk) return;
const gasPrice = await sdk.getGasPrice(ChainId.CROSS_MAINNET);
const nonce = await sdk.getNonce(ChainId.CROSS_MAINNET);
};
if (!isInitialized) return <p>Initializing...</p>;
// ...
}Code Examples
Full App Setup
// main.tsx
import React from 'react';
import ReactDOM from 'react-dom/client';
import { CROSSxProvider } from '@nexus-cross/crossx-sdk-react';
import type { SDKConfig } from '@nexus-cross/crossx-sdk-core';
import App from './App';
const config: SDKConfig = {
projectId: 'YOUR_PROJECT_ID',
appName: 'My DApp',
theme: 'light',
autoDetectTheme: true,
};
ReactDOM.createRoot(document.getElementById('root')!).render(
<CROSSxProvider config={config}>
<App />
</CROSSxProvider>
);Auth-Gated Component
import { useAuth, useWallet } from '@nexus-cross/crossx-sdk-react';
function Dashboard() {
const { isAuthenticated, isLoading } = useAuth();
const { address } = useWallet();
if (isLoading) return <p>Loading...</p>;
if (!isAuthenticated) return <p>Please sign in</p>;
return <p>Connected: {address}</p>;
}Preconditions
Confirm the required setup before implementing a feature.
- Both
@nexus-cross/crossx-sdk-coreand@nexus-cross/crossx-sdk-reactmust be installed. CROSSxProvidermust wrap the component tree at the app root before any CROSSx hooks are used.CROSSxProvideraccepts aconfigprop with at minimumprojectIdandappName.CROSSxProviderautomatically callssdk.initialize()on mount, so no manual initialization is needed.- Wallet and signing hooks require the user to be authenticated first (
isAuthenticatedfromuseAuth). signInWithCreate()fromuseAuthhandles sign-in and wallet setup in a single call.walletRpc(accessible viauseCROSSx) is read-only; do not use it for transaction sign/send flows.- All chain IDs must use CAIP-2
eip155:<number>format orChainIdconstants.
Guardrails
- Do not place
CROSSxProviderinside a component that remounts frequently — it should be at the app root. - Do not call SDK methods directly on the SDK instance when a hook provides the same capability.
- Do not use wallet or signing features before confirming
isAuthenticatedfromuseAuth. - Do not use
walletRpcfor transaction signing or sending. - Do not add new wrappers or architectural layers when the feature can fit existing hooks or components.
- Do not guess unclear SDK behavior when the latest documentation or MCP resources should be checked first.
- Do not generate fallback values for
projectIdorappName. Ask the user if they are missing.
Implementation Workflow
- Identify the feature category and the affected components.
- Inspect the existing project structure before making changes.
- Confirm
CROSSxProvideris in place and configured before adding hook usage. - Apply the smallest code change that fits the existing component architecture and style.
- Use the correct hooks and SDK APIs, CAIP-2 chain IDs, and parameter requirements.
- Review the affected components for integration gaps before finalizing.
Validation Checklist
Before finalizing CROSSx React SDK changes, verify the following:
- The change matches the requested feature scope without unnecessary refactoring.
CROSSxProvideris present at the app root withprojectIdandappNameinconfig.- Hooks are only called inside components that are children of
CROSSxProvider. - Wallet and signing operations are gated behind
isAuthenticatedfromuseAuth. - After sign-in, wallet-dependent flows confirm a wallet exists; use
signInWithCreate()for one-step login + wallet setup. - Chain-aware APIs use CAIP-2
eip155:<number>format orChainIdconstants. walletRpcis only used for read-only scenarios.- Loading states (
isLoading/isInitialized) are handled in components to avoid rendering before session restore completes.
Updated about 19 hours ago