A comprehensive extension for Scaffold-ETH 2 that integrates the Avail Nexus SDK for cross-chain token operations.
- Node:
^=20.19.2
- Run the command below to initialize a new Scaffold-ETH project with the Avail Nexus Extension
npx create-eth@latest -e robin-rrt/avail-nexus-scaffold-widget:main
- Start running the project on
localhost
yarn start
- Navigate to
/nexusroute for using Nexus related functions on Scaffold ETH
- Copy the extension files to your Scaffold-ETH 2 project
- Install the required dependencies:
yarn add avail-nexus-sdk@0.0.10 viem- Add the NexusProvider to your app's provider hierarchy
- Import and use the Nexus components in your pages
Add the NexusProvider to your app's provider hierarchy:
import { NexusProvider } from "./app/nexus/NexusContext";
function ScaffoldEthAppWithProviders({ children }: { children: React.ReactNode }) {
return (
<Provider>
<NexusProvider>
{/* Other providers */}
{children}
</NexusProvider>
</Provider>
);
}The extension provides a complete Nexus page with all functionality:
import NexusPage from "./app/nexus/page";
// Use in your app
<NexusPage />You can also use individual components:
import { InitNexus } from "./app/nexus/InitNexus";
import { useNexusSdk } from "./app/nexus/NexusContext";
function MyComponent() {
const { sdk } = useNexusSdk();
// Use the SDK for custom operations
const handleCustomTransfer = async () => {
if (!sdk) return;
const result = await sdk.transfer({
token: "ETH",
amount: "0.1",
chainId: 1, // Ethereum
recipient: "0x...",
});
};
return (
<div>
<InitNexus />
{/* Your custom UI */}
</div>
);
}Handles wallet creation and Nexus SDK initialization.
Displays the connected address and unified balance across all chains.
Provides cross-chain transfer functionality with simulation support.
Enables bridging tokens between different chains.
Shows a detailed breakdown of your portfolio across all supported chains.
const { sdk, setSdk } = useNexusSdk();sdk: The initialized Nexus SDK instancesetSdk: Function to update the SDK instance
interface TransferParams {
token: SUPPORTED_TOKENS;
amount: string;
chainId: SUPPORTED_CHAINS_IDS;
recipient: `0x${string}`;
}interface BridgeParams {
token: SUPPORTED_TOKENS;
amount: string;
chainId: SUPPORTED_CHAINS_IDS;
}- Cross-Chain Transfers: Transfer tokens across multiple supported chains
- Bridge Operations: Bridge tokens between different chains
- Unified Balance Display: View your portfolio across all supported chains
- Simulation Support: Simulate transfers and bridge operations before execution
- Privy Integration: Seamless wallet integration with Privy
- Real-time Status Updates: Track transaction status and results
- Ethereum
- Optimism
- Polygon
- Arbitrum
- Avalanche
- Base
- Scroll
- ETH
- USDC
- USDT
The extension uses the following configuration:
- Network: Mainnet (configurable in InitNexus)
- Wallet Provider: Privy embedded wallet
- Default Chain: Base (configurable)
The extension includes comprehensive error handling:
- SDK initialization errors
- Transfer/bridge failures
- Network connectivity issues
- User input validation
To extend the functionality:
- Add new components to the
app/nexus/directory - Update the main page to include new features
- Add new chain/token support in the constants
- Test thoroughly with the simulation features
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests if applicable
- Submit a pull request
MIT License - see LICENSE file for details.
For issues and questions:
- Check the Scaffold-ETH 2 documentation
- Review the Avail Nexus SDK documentation
- Open an issue in the repository