nexus-elements-deposit
Nexus Elements - Deposit
Install
- Install widget:
npx shadcn@latest add @nexus-elements/deposit
- Ensure
NexusProvideris installed and initialized before rendering.
Required setup before rendering
- Ensure
useNexus().nexusSDKis initialized. - Ensure
exchangeRatecontains destination token rate (widget requires it for amount simulation). - Provide a correct
destinationconfig andexecuteDepositbuilder. - If using the built-in
MAXinteraction, ensure the widget can compute current source selections so it can callsdk.calculateMaxForSwap(...).
Initialize SDK (required once per app)
- On wallet connect, resolve an EIP-1193 provider and call
useNexus().handleInit(provider). - Wait for
useNexus().nexusSDKbefore allowing amount confirmation. - Re-run init after reconnect if wallet session resets.
Render widget
"use client";
import NexusDeposit from "@/components/deposit/nexus-deposit";
import {
SUPPORTED_CHAINS,
TOKEN_CONTRACT_ADDRESSES,
TOKEN_METADATA,
CHAIN_METADATA,
} from "@avail-project/nexus-core";
import { encodeFunctionData, type Abi } from "viem";
export function DepositPanel() {
return (
<NexusDeposit
heading="Deposit USDC"
destination={{
chainId: SUPPORTED_CHAINS.BASE,
tokenAddress: TOKEN_CONTRACT_ADDRESSES["USDC"][SUPPORTED_CHAINS.BASE],
tokenSymbol: "USDC",
tokenDecimals: TOKEN_METADATA["USDC"].decimals,
tokenLogo: TOKEN_METADATA["USDC"].icon,
label: "Deposit to protocol",
gasTokenSymbol: CHAIN_METADATA[SUPPORTED_CHAINS.BASE].nativeCurrency.symbol,
explorerUrl: CHAIN_METADATA[SUPPORTED_CHAINS.BASE].blockExplorerUrls[0],
estimatedTime: "~30s",
}}
executeDeposit={(tokenSymbol, tokenAddress, amount, _chainId, user) => {
const contract = "0x0000000000000000000000000000000000000000" as const;
const abi: Abi = [
{
type: "function",
name: "deposit",
stateMutability: "nonpayable",
inputs: [
{ name: "asset", type: "address" },
{ name: "amount", type: "uint256" },
{ name: "beneficiary", type: "address" },
],
outputs: [],
},
];
const data = encodeFunctionData({
abi,
functionName: "deposit",
args: [tokenAddress, amount, user],
});
return {
to: contract,
data,
tokenApproval: {
token: tokenAddress,
amount,
spender: contract,
},
};
}}
onSuccess={() => {
// success
}}
onError={(message) => {
console.error(message);
}}
/>
);
}
Live prop contract
- Required:
destination: DestinationConfigexecuteDeposit(tokenSymbol, tokenAddress, amount, chainId, user)
- Optional:
heading,embed,classNameopen,onOpenChange,defaultOpen(dialog mode)onSuccess,onError,onClose
SDK flow details (under the hood)
- Main execute call:
sdk.swapAndExecute({ toChainId, toTokenAddress, toAmount, fromSources?, execute }, { onEvent })
- Max amount call:
sdk.calculateMaxForSwap({ toChainId, toTokenAddress, fromSources? })
- Step and status behavior:
- amount step starts simulation-loading
- waits for
swapIntenthook to enter previewing state - confirm order calls
activeIntent.allow()and moves to executing
- Event mapping:
- listens to
NEXUS_EVENTS.SWAP_STEP_COMPLETE - handles
DETERMINING_SWAPandSWAP_SKIPPED
- listens to
- Fee handling:
- destination execute receipt computes actual gas USD in success path
Important amount semantics
- Amount input is interpreted as USD in this widget flow.
- Widget converts USD amount to destination token amount via provider exchange rates.
MAXis destination-token aware:- widget computes
MaxSwapInputfrom the current destination and selected source pool - widget calls
sdk.calculateMaxForSwap(...) - returned destination-token max is converted back to USD for the input field
- widget computes
- If destination token exchange rate is missing/invalid, widget shows error and blocks confirmation.
Source selection semantics
- Amount changes reset source selection back to auto mode.
- In auto mode, the widget derives source balances from the current filter and current widget logic before simulation.
- Preset filters in the source picker (
Any token,Stablecoins,Native) act as explicit source selections for that pool. - Manual source edits are treated as exact selected sources until the amount changes again.
Pay usingand thefromSourcessent tosdk.swapAndExecute(...)should reflect the same current source set.
Preview cancellation behavior
- Backing out from the confirmation screen before
activeIntent.allow()denies the preview intent. - This intentional preview cancellation should not surface as the widget's own local error banner, though external
onErrorhandlers may still observe the rejection if the app wants it.
E2E verification
- Enter amount and continue to confirmation.
- Confirm simulation appears and updates every polling cycle.
- Confirm order and verify status screen transitions.
- Verify both source and destination explorer links when available.
- Verify
onSuccessand balance refresh after completion. - Verify error screen appears on failed simulation/execution.
Common failure cases
Nexus SDK is not initialized:- ensure
handleInit(provider)ran after wallet connect.
- ensure
Unable to fetch pricing for <token>:- ensure rates loaded in provider and token symbol is valid.
- Execute revert:
- validate
executeDeposittarget, calldata, and token approval spender.
- validate
More from availproject/nexus-elements
nexus-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.
21nexus-elements-unified-balance
Integrate the UnifiedBalance element for cross-chain token balance views in React/TypeScript apps. Use when installing or debugging bridgeable/swappable balance aggregation, per-chain breakdown rendering, and formatting powered by Nexus SDK balance APIs.
21