Swap assets with exact-in or exact-out across supported chains. Intent-based with prefill, callbacks, and progress UI.
Connect wallet to use Nexus Swaps
"use client";
import SwapExactIn from "./exact-in/exact-in";
import SwapExactOut from "./exact-out/exact-out";
import { Tabs, TabsContent, TabsList, TabsTrigger } from "../ui/tabs";
interface SwapsProps {
onComplete?: (amount?: string) => void;
onStart?: () => void;
onError?: (message: string) => void;
exactInprefill?: {
fromChainID?: number;
fromToken?: string;
fromAmount?: string;
toChainID?: number;
toToken?: string;
};
exactOutprefill?: {
toAmount?: string;
toChainID?: number;
toToken?: string;
};
}
const Swaps = ({
onComplete,
onStart,
onError,
exactInprefill,
exactOutprefill,
}: SwapsProps) => {
return (
<Tabs className="w-full" defaultValue={"exact-in"}>
<TabsList>
<TabsTrigger value="exact-int">
<p className="text-sm font-medium">Exact In</p>
</TabsTrigger>
<TabsTrigger value="exact-out">
<p className="text-sm font-medium">Exact Out</p>
</TabsTrigger>
</TabsList>
<TabsContent value="exact-in">
<SwapExactIn
onComplete={onComplete}
onStart={onStart}
onError={onError}
prefill={exactInprefill}
/>
</TabsContent>
<TabsContent value="exact-out">
<SwapExactOut
onComplete={onComplete}
onStart={onStart}
onError={onError}
prefill={exactOutprefill}
/>
</TabsContent>
</Tabs>
);
};
export Swaps;
pnpm dlx shadcn@latest add @nexus-elements/swaps
<SwapExactIn
onComplete={completeCurrent}
onError={handleError}
onStart={handleStart}
exactInprefill={{
fromToken: "USDC",
fromChainID: SUPPORTED_CHAINS.BASE,
fromAmount: "100",
toToken: "USDT",
toChainID: SUPPORTED_CHAINS.ARBITRUM,
}}
/><SwapExactOut
onComplete={completeCurrent}
onError={handleError}
onStart={handleStart}
exactOutprefill={{
toToken: "USDT",
toChainID: SUPPORTED_CHAINS.ARBITRUM,
toAmount: "100",
}}
/>Swaps component provides cross-chain swaps in either exact-in or exact-out mode with optional prefill and lifecycle callbacks.
interface SwapsProps {
onComplete?: (amount?: string) => void; // called when the swap completes
onStart?: () => void; // called when the swap starts
onError?: (message: string) => void; // called on error
exactInprefill?: {
// optional prefill for exact-in mode
fromChainID?: number;
fromToken?: string;
fromAmount?: string;
toChainID?: number;
toToken?: string;
};
exactOutprefill?: {
// optional prefill for exact-out mode
toAmount?: string;
toChainID?: number;
toToken?: string;
};
}