Nexus Core Quickstart
This page will help you quickly get started with nexus-core, using a Next JS template.
PREFER VITE?
We prepared two template repos for devs to get started with nexus-core as easily as possible:
- For more docs on
nexus-core, you can refer to the Nexus SDK reference. - Also refer to the API reference for a complete feature list.
Getting started with the headless Nexus SDK is simple.
Clone the template repo
Clone the repo by running this command in your terminal:
git clone
git clone https://github.com/availproject/nexus-nextjs-templateInstall the dependencies
In this template, we use ConnectKit with Wagmi & Viem for a seamless wallet connection experience, with cross-chain support being powered by @avail-project/nexus-core.
Install the dependencies by opening a terminal in the root of the project and running this command:
pnpm
pnpm installUncomment initializeNexus() in NexusProvider.tsx
Go to src/components/nexus/NexusProvider.tsx and uncomment the initializeNexus() function.
This function:
- Fetches the EIP-1193 Provider from the connected wallet.
- Initializes the Nexus SDK if it is not already initialized.
- Fetches the unified balances of the connected wallet.
This page is also where we register the hooks for the Nexus SDK and store the data in the context. You can read more about hooks here:
const initializeNexus = async (provider: EthereumProvider) => {
setLoading(true);
try {
if (sdk.isInitialized()) throw new Error("Nexus is already initialized");
await sdk.initialize(provider);
setNexusSDK(sdk);
initChainsAndTokens();
const [unifiedBalanceResult, rates] = await Promise.allSettled([
sdk?.getUnifiedBalances(true),
sdk?.utils?.getCoinbaseRates(),
]);
if (unifiedBalanceResult.status === "fulfilled") {
unifiedBalance.current = unifiedBalanceResult.value;
}
if (rates?.status === "fulfilled") {
// Coinbase returns "units per USD" (e.g., 1 USD = 0.00028 ETH).
// Convert to "USD per unit" (e.g., 1 ETH = ~$3514) for straightforward UI calculations.
const usdPerUnit: Record<string, number> = {};
for (const [symbol, value] of Object.entries(rates ?? {})) {
const unitsPerUsd = Number.parseFloat(String(value));
if (Number.isFinite(unitsPerUsd) && unitsPerUsd > 0) {
usdPerUnit[symbol.toUpperCase()] = 1 / unitsPerUsd;
}
}
for (const token of ["ETH", "USDC", "USDT"]) {
usdPerUnit[token] ??= 1;
}
exchangeRate.current = usdPerUnit;
}
} catch (error) {
console.error("Error initializing Nexus:", error);
} finally {
setLoading(false);
}
};Update the Web3Provider.tsx file
Go to src/providers/Web3Provider.tsx and:
-
Uncomment the
walletConnectProjectIdvariable. you can get an API key from WalletConnect Cloud . Set up the variable in the.envfile at the root of the project. -
Uncomment the
transportsobject. This object is used to set up the chains that you want to support. -
Uncomment the
Web3Providercomponent. We wrap ourNexusProviderwithWagmiProviderso that it can borrow the EIP-1193 Provider from the connected wallet. TheConnectKitProvideris used to provide a pre-configured WalletConnect modal for the user to connect their wallet. The wallet provider itself comes from Wagmi.
const Web3Provider = ({ children }: { children: React.ReactNode }) => {
return (
<WagmiProvider config={config}>
<QueryClientProvider client={queryClient}>
<NexusProvider>
<ConnectKitProvider theme="soft" mode="light">
{children}
</ConnectKitProvider>
</NexusProvider>
</QueryClientProvider>
</WagmiProvider>
);
};Wrap everything in Web3Provider
Go to src/app/layout.tsx and uncomment the Web3Provider component.
This will wrap our entire app and provide the necessary context for the Nexus SDK to work.
import Web3Provider from "@/providers/Web3Provider";
export default function RootLayout({
children,
}: Readonly<{
children: React.ReactNode;
}>) {
return (
<html lang="en">
<body><Web3Provider>{children}</Web3Provider></body>
</html>
);
}Run the app
Run the app by running this command in your terminal:
pnpm
pnpm run devYour app should now be running at http://localhost:3000.
Play around with the code to tweak the existing components or add new ones.
Or maybe you’d like to add a pre-configured React component to your app?
What’s next?
Congratulations on finishing the quickstart! Feel free to explore the following resources to learn more about the Nexus SDK: