Nexus SDK Setup
Create a Nexus client, initialize it, and connect a wallet.
Create and connect a client
import { createNexusClient, type EthereumProvider } from "@avail-project/nexus-core";
const client = createNexusClient({ clientId: "my-app", network: "mainnet" });
await client.initialize();
const provider = (window as { ethereum?: EthereumProvider }).ethereum;
if (provider) {
await provider.request({ method: "eth_requestAccounts" });
await client.setEVMProvider(provider);
}initialize() loads chain metadata. Call it once, before any other method; otherwise calls fail with SDK_NOT_INITIALIZED.
setEVMProvider(provider) reads the connected account from any EIP-1193 provider. Connect the wallet first, or the call rejects. client.hasEvmProvider reports whether a provider is set.
Client options
| Option | Type | Description |
|---|---|---|
clientId | string | Required. Stable, non-empty identifier for your app. An empty value throws. |
network | 'mainnet' | 'canary' | 'testnet' | Default 'mainnet'. |
debug | boolean | Enables verbose SDK logging. |
analytics | { enabled?: boolean } | Set enabled: false to disable product analytics. |
Networks
| Network | Chains | Supports |
|---|---|---|
mainnet | Mainnet | Everything |
canary | Mainnet | Everything, against pre-release Nexus services |
testnet | Testnets | execute and simulateExecute only. Swaps, swapAndExecute, and async catalog methods reject with ENVIRONMENT_NOT_SUPPORTED. |
What needs a wallet
Works after initialize() | Also needs setEVMProvider() |
|---|---|
getSupportedChains, getTokens, getToken, and the other catalog methods | getBalances, listIntents |
swapWithExactIn quote previews (review only, no execution) | swapWithExactOut, swapAndExecute, and executing any swap |
execute, simulateExecute |
WALLET_NOT_CONNECTED.
Account changes and cleanup
import { createNexusClient, type EthereumProvider, type NexusClient } from "@avail-project/nexus-core";
async function connect(provider: EthereumProvider): Promise<NexusClient> {
const next = createNexusClient({ clientId: "my-app", network: "mainnet" });
await next.initialize();
await next.setEVMProvider(provider);
return next;
}
declare const provider: EthereumProvider;
let client = await connect(provider);
provider.on("accountsChanged", async () => {
client.destroy();
client = await connect(provider);
});The client keeps the account it read in
setEVMProvider. Calling setEVMProvider again with the same provider object does nothing, so after an account or provider change, create a new client. Call destroy() on the old one and on unmount.Next steps
- Connect with RainbowKit in a React app.
- Bridge tokens between chains.
How is this guide?