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

/avail-widgets-nexus-provider

@8f83d92
Run it yourself

Install and configure NexusProvider for Avail Widgets with full SDK lifecycle wiring. NexusProvider is required by Nexus Widget — the single unified element for all swap, send, and deposit flows.

  • 1 file
  • 4.9 KB
  • Updated 4 months ago
  • GitHub
Use this Skill: https://skilld.dev/gh/availproject/widgets/avail-widgets-nexus-provider

Nothing lands on disk. Nothing to clean up.

Fork this Skill

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

SKILL.md

≈57 tokens for metadata: the name and description. ≈1.2k when used: this file.

Description uses 2.8% 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 ≈226 characters, or 2.8%.

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.

Avail Widgets - NexusProvider

Note: NexusProvider is the foundation required by Nexus Widget — the single unified element for all flows.

Install and wire provider

npm (recommended):

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

shadcn (source files):

npx shadcn@latest add availproject/widgets/nexus-provider

Wrap your app

npm:

"use client";
import { NexusProvider } from "@avail-project/widgets";

export function AppNexusProvider({ children }: { children: React.ReactNode }) {
  return (
    <NexusProvider config={{ network: "mainnet", debug: false }}>
      {children}
    </NexusProvider>
  );
}

shadcn:

"use client";
import NexusProvider from "@/components/nexus/NexusProvider";

export function AppNexusProvider({ children }: { children: React.ReactNode }) {
  return (
    <NexusProvider config={{ network: "mainnet", debug: false }}>
      {children}
    </NexusProvider>
  );
}

Initialize SDK on wallet connect

  • Resolve an EIP-1193 provider from your wallet stack.
  • Call handleInit(provider) after wallet status becomes connected.
  • Pass only providers with request().
"use client";

import { useEffect } from "react";
import { useAccount, useConnectorClient } from "wagmi";
import type { EthereumProvider } from "@avail-project/nexus-core";
// npm path:
import { useNexus } from "@avail-project/widgets";
// shadcn path: import { useNexus } from "@/components/nexus/NexusProvider";

export function InitNexusOnConnect() {
  const { status, connector } = useAccount();
  const { data: walletClient } = useConnectorClient();
  const { handleInit } = useNexus();

  useEffect(() => {
    if (status !== "connected") return;

    void (async () => {
      const mobileProvider = walletClient
        ? ({
            request: (args: unknown) => walletClient.request(args as never),
          } as EthereumProvider)
        : undefined;
      const desktopProvider = await connector?.getProvider();
      const provider =
        mobileProvider ?? (desktopProvider as EthereumProvider | undefined);
      if (!provider || typeof provider.request !== "function") return;
      await handleInit(provider);
    })();
  }, [status, connector, walletClient, handleInit]);

  return null;
}

Understand provider lifecycle (current implementation)

  • handleInit(provider):
    • guard: skips if already initialized or loading.
    • validate provider shape.
    • call initializeNexus(provider).
    • call setup preload (supported chains/tokens, bridge balances, Coinbase rates).
    • attach hooks (intent, allowance, swapIntent).
  • initializeNexus(provider):
    • calls sdk.initialize(provider) once.
    • sets nexusSDK state.
  • deinitializeNexus():
    • calls sdk.deinit().
    • clears balances, rates, supported chains/tokens, and hook refs.
  • Auto-disconnect behavior:
    • provider uses useAccountEffect from wagmi to deinit on disconnect.

SDK functions NexusProvider relies on

  • Init/lifecycle:
    • sdk.initialize(provider)
    • sdk.deinit()
    • sdk.isInitialized()
  • Metadata and balances:
    • sdk.utils.getSupportedChains(...)
    • sdk.utils.getSwapSupportedChainsAndTokens()
    • sdk.getBalancesForBridge()
    • sdk.getBalancesForSwap()
    • sdk.utils.getCoinbaseRates()
  • Hook wiring:
    • sdk.setOnIntentHook(...)
    • sdk.setOnAllowanceHook(...)
    • sdk.setOnSwapIntentHook(...)

Understand hook contract

  • Any active hook payload includes allow() and deny().
  • If a widget sets hook-driven confirmation UI, always call one of them.
  • Not calling allow()/deny() leaves a flow pending.

useNexus() API surface

  • Core:
    • nexusSDK, loading, network
  • Lifecycle:
    • handleInit, initializeNexus, deinitializeNexus, attachEventHooks
  • Hook refs:
    • intent, allowance, swapIntent
  • Data:
    • bridgableBalance, swapBalance, exchangeRate
    • supportedChainsAndTokens, swapSupportedChainsAndTokens
  • Helpers:
    • fetchBridgableBalance, fetchSwapBalance, getFiatValue(amount, token)

E2E validation

  • Connect wallet and assert nexusSDK becomes non-null.
  • Assert supported chains/tokens are populated.
  • Assert bridge and swap balances are fetched.
  • Trigger a widget flow and confirm corresponding hook ref is populated.
  • Disconnect wallet and confirm state clears.

Troubleshoot

  • Invalid EIP-1193 provider:
    • use connector.getProvider() or a wallet client wrapper exposing request().
  • Init succeeds but widgets fail:
    • ensure handleInit runs before mounting interactive flows.
  • Missing fiat values:
    • check exchangeRate; fallback is token amount * 1 if rate missing.

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.

No third-party reports yet.

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/avail-widgets-nexus-provider