> ## Documentation Index
> Fetch the complete documentation index at: https://docs.enso.build/llms.txt
> Use this file to discover all available pages before exploring further.

# Feeling Lucky

> A dApp that helps users diversify into random tokens from selected sectors using the Enso SDK.

export const date_0 = "2025-04-11"

Can't decide where to ape in? Feeling lucky is here to help you out.

<CardGroup>
  <Card href="https://github.com/EnsoBuild/shortcuts-ui-examples/tree/main/apps/feeling-lucky" title="Github" icon="github">
    Source code
  </Card>

  <Card href="https://templates.enso.build/feeling-lucky" title="Feeling Lucky Live Demo" icon="play">
    Try it out!
  </Card>
</CardGroup>

## Overview

Feeling Lucky is a Next.js application that enables users to "ape" into random tokens from their preferred sectors. The app leverages Enso's Router API to execute token swaps with optimal routing across multiple exchanges and protocols.

## Features

* **Random Token Selection**: Discover and invest in random tokens from specific sectors
* **Any-to-Any Swaps**: Use any token in your wallet to purchase the randomly selected token
* **Optimal Routing**: Get the best execution price through Enso's aggregation
* **Transaction Preview**: View expected output amount and price impact before execution
* **Wallet Integration**: Connect easily via Privy or WalletConnect

## Technology Stack

* **Frontend**: React, Next.js, Chakra UI
* **Web3**: wagmi, viem, Privy
* **DeFi Integration**: Enso Finance SDK
* **Build Tools**: TypeScript

## Implementation Example

```tsx theme={null}
import { useEnsoRouterData } from '@ensofinance/sdk-ts';

function FeelingLuckySwap({ tokenIn, randomToken }) {
  const { data, isLoading } = useEnsoRouterData({
    fromAddress: address,
    chainId: 1,
    tokenIn: tokenIn.address,
    tokenOut: randomToken.address,
    amountIn: swapValue,
    slippage: 200, // 2%
  });
  
  async function executeSwap() {
    // Using ethers/viem to send the transaction
    const tx = await walletClient.sendTransaction({
      to: data.tx.to,
      data: data.tx.data,
      value: data.tx.value,
    });
    
    await publicClient.waitForTransactionReceipt({ hash: tx });
  }
  
  return (
    <Button 
      onClick={executeSwap}
      isLoading={isLoading}
      loadingText="Finding best route"
    >
      Feeling Lucky!
    </Button>
  );
}
```

## Environment Setup

Required environment variables:

* `NEXT_PUBLIC_ENSO_API_KEY`: Your Enso API key
* `NEXT_PUBLIC_PRIVY_KEY`: Privy authentication key

## Key Components

* **TokenSelector**: Interface for selecting input tokens
* **SectorSelector**: UI for choosing token categories
* **TransactionPreview**: Displays swap details before execution

## Development

```bash theme={null}
# Install dependencies
pnpm install

# Start development server
pnpm dev
```

<div className="text-right text-xs gray-200 font-semibold w-full" style={{marginTop: '0'}}>
  <p style={{
        color: "#b2b2b2"  
    }}>Updated {date_0}</p>
</div>
