Index of every page on this site: llms.txt
All skills
availproject avatar

/nexus-sdk-setup

@8f83d92
Run it yourself

Set up and initialize Nexus SDK in any JS/TS frontend project. Use when configuring wallet provider, SDK instance lifecycle, network selection, or adding a minimal wallet connection path.

Use this Skill: https://skilld.dev/gh/availproject/widgets/nexus-sdk-setup

Nothing lands on disk. Nothing to clean up.

Fork this Skill

Edit a local copy. It keeps the author and licence.

SKILL.md

≈51 tokens for metadata: the name and description. ≈998 when used: this file.

Description uses 2.6% of example budget

Before choosing a Skill, your Agent reads its name and description. All available Skills share that space.

  • A shorter description leaves more room for other Skills. This entry exceeds our 1% size suggestion.

In our Claude Code example, all Skill names and descriptions share 8,000 characters. This Skill uses ≈205 characters, or 2.6%.

The 1% threshold is a size suggestion. Longer descriptions can still fit.

Your model, settings, and other Skills decide how much text your Agent can read.

Example settings and source

The example uses a 200k-token context and default Claude Code settings. The count includes the name, description, separators, and when_to_use when present. Codex also counts local file paths.

Skit's source and limits: Codex 0.160.1, Claude Code 2.1.292.

Nexus SDK Setup

Install dependency

Recommended (pre-compiled widget + SDK):

npm install @avail-project/widgets viem wagmi @tanstack/react-query

SDK-only (for custom UI / headless use):

npm install @avail-project/nexus-core
  • or pnpm add @avail-project/nexus-core
  • or yarn add @avail-project/nexus-core

Import paths

When using @avail-project/widgets (npm package):

import { NexusWidget, NexusProvider, useNexus } from "@avail-project/widgets";

When using the shadcn path (source files copied locally):

import { NexusWidget } from "@/components/nexus/nexus";
import NexusProvider, { useNexus } from "@/components/nexus/NexusProvider";

Obtain an EIP-1193 provider

  • Use any wallet connection stack to get a provider.
  • Ensure the provider has a request method.
  • Use a browser fallback only when appropriate:
    • const provider = (window as any).ethereum

Construct the SDK client

  • Create createNexusClient({ network, debug, siweChain }).
  • Provide network:
    • 'mainnet' or 'testnet' to use default endpoints.
    • NetworkConfig to use custom endpoints.
  • Provide debug?: boolean to enable verbose SDK logging.
  • Provide siweChain?: number to set the SIWE chain id (if you use SIWE).

Initialize once

  • Create a single client and reuse it.
  • Store the client in a module singleton or a React ref.
  • Guard with sdk.isInitialized() to avoid re-init.

Minimal example

import { createNexusClient, type EthereumProvider } from '@avail-project/nexus-core';

const sdk = createNexusClient({ 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 Avail Widgets: prefer connector.getProvider() on desktop and a walletClient.request wrapper on mobile.
  • Example (adapt to your hooks and UI state):
import { createNexusClient, type EthereumProvider } from '@avail-project/nexus-core';
import { useAccount, useConnectorClient } from 'wagmi';

const sdk = createNexusClient({ 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.hasEvmProvider to confirm.

Handle SSR / client-only execution

  • Initialize in client-only code (useEffect or 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.initialize in try/catch.
  • If SDK_INIT_STATE_NOT_EXPECTED, call await sdk.deinit() and retry.
  • If WALLET_NOT_CONNECTED or CONNECT_ACCOUNT_FAILED, prompt user to reconnect.

Source: SKILL.md on GitHub

skilld matched fixed text patterns in SKILL.md and file names. Patterns miss obfuscated code.

skilld run checks every file with the same patterns. It asks for approval before it loads a Skill with a behavior marked Needs approval.

1 warning8mo3 checks · Risk SAFE
  • Gen Agent Trust Hub9mo

    This skill provides instructions and boilerplate code for integrating the Nexus SDK into a JavaScript or TypeScript project. It includes standard dependency installation and initialization patterns for Ethereum-compatible wallet providers. No malicious behavior or security risks were identified.

  • Socket8mo

    No alerts

  • Snyk9mo

    Risk: MEDIUM · No issues

Signed by skilld at 8f83d92. This ties the file your Agent reads to that commit on GitHub. It does not review the instructions.

Last checked against GitHub last week.

Activeupdated 4 months ago

README badge

README badge for availproject/widgets/nexus-sdk-setup