nexus-sdk-setup
Nexus SDK Setup
Install dependency
- Install the SDK package:
npm install @avail-project/nexus-core- or
pnpm add @avail-project/nexus-core - or
yarn add @avail-project/nexus-core
Obtain an EIP-1193 provider
- Use any wallet connection stack to get a provider.
- Ensure the provider has a
requestmethod. - Use a browser fallback only when appropriate:
const provider = (window as any).ethereum
Construct the SDK instance
- Create
new NexusSDK({ network, debug, siweChain }). - Provide
network:'mainnet'or'testnet'to use default endpoints.NetworkConfigto use custom endpoints.
- Provide
debug?: booleanto enable verbose SDK logging. - Provide
siweChain?: numberto set the SIWE chain id (if you use SIWE).
Initialize once
- Create a single instance and reuse it.
- Store the instance in a module singleton or a React ref.
- Guard with
sdk.isInitialized()to avoid re-init.
Minimal example
import { NexusSDK, type EthereumProvider } from '@avail-project/nexus-core';
const sdk = new NexusSDK({ network: 'mainnet' });
export async function initNexus(provider: EthereumProvider) {
if (sdk.isInitialized()) return sdk;
if (!provider || typeof provider.request !== 'function') {
throw new Error('Invalid EIP-1193 provider');
}
await sdk.initialize(provider);
return sdk;
}
Initialize when a wallet kit is already integrated (FamilyKit / wagmi-based)
- If your kit exposes a wagmi connector, derive an EIP-1193 provider from it.
- Use the same pattern as Nexus Elements: prefer
connector.getProvider()on desktop and awalletClient.requestwrapper on mobile. - Example (adapt to your hooks and UI state):
import { NexusSDK, type EthereumProvider } from '@avail-project/nexus-core';
import { useAccount, useConnectorClient } from 'wagmi';
const sdk = new NexusSDK({ network: 'mainnet', debug: false });
async function initFromWalletKit(isMobile: boolean) {
const { connector } = useAccount();
const { data: walletClient } = useConnectorClient();
const mobileProvider =
walletClient &&
({
request: (args: unknown) => walletClient.request(args as never),
} as EthereumProvider);
const desktopProvider = await connector?.getProvider();
const effectiveProvider = isMobile ? mobileProvider : desktopProvider;
if (!effectiveProvider || typeof effectiveProvider.request !== 'function') {
throw new Error('Invalid EIP-1193 provider from wallet kit');
}
if (!sdk.isInitialized()) {
await sdk.initialize(effectiveProvider);
}
return sdk;
}
Handle disconnect / teardown
- On wallet disconnect, call
await sdk.deinit(). - Clear state (balances, hook refs, cached intents).
Use provider-only mode (optional)
- If you need balances before full init, call:
await sdk.setEVMProvider(provider)
- Check
sdk.hasEvmProviderto confirm.
Handle SSR / client-only execution
- Initialize in client-only code (
useEffector dynamic import) to avoid SSR issues.
Handle account changes
- If provider supports events, re-fetch balances on
accountsChanged. - If provider lacks
.on/.removeListener, call:sdk.triggerAccountChange()after the wallet address changes.
Handle init errors
- Wrap
sdk.initializein try/catch. - If
SDK_INIT_STATE_NOT_EXPECTED, callawait sdk.deinit()and retry. - If
WALLET_NOT_CONNECTEDorCONNECT_ACCOUNT_FAILED, prompt user to reconnect.
More from availproject/nexus-elements
nexus-elements-deposit
Integrate the Deposit element for swap-plus-execute deposit flows in React/TypeScript apps. Use when installing or debugging destination-fixed deposits, execute call builders, swap-intent confirmation UX, and `sdk.swapAndExecute` progress from quote to completion.
26nexus-elements-overview
End-to-end integration guide for Nexus Elements in any TypeScript/React codebase. Use when setting up Nexus Elements from scratch, choosing which widget to install, wiring NexusProvider + wallet initialization, or validating bridge/transfer/swap/deposit/history behavior in production-like flows.
24nexus-elements-common
Use shared Nexus Elements hooks, transaction-step helpers, and constants to build custom Nexus UX. Use when extending widgets or implementing custom bridge/transfer/swap/deposit flows that need debouncing, polling, step orchestration, or Nexus error normalization.
23nexus-elements-nexus-provider
Install and configure NexusProvider for Nexus Elements with full SDK lifecycle wiring. Use when setting up or debugging SDK initialization, wallet/provider connection, hook attachment (intent/allowance/swapIntent), balance preloads, exchange-rate support, and provider context consumption in React/TypeScript apps.
23nexus-elements-bridge-deposit
Integrate the Bridge Deposit element for bridge-plus-execute deposit flows in React/TypeScript apps. Use when installing or debugging source-chain constrained deposits, bridge+execute simulation, intent/allowance approvals, and `sdk.bridgeAndExecute` transaction execution.
22nexus-elements-fast-bridge
Integrate the FastBridge element for intent-based cross-chain bridge UX in React/TypeScript apps. Use when installing or debugging self-bridge flows, source-chain selection, allowance gating, step progress events, and `sdk.bridge` execution end-to-end.
21