A comprehensive Next.js application demonstrating how to integrate the Codex SDK in a modern React environment. This example showcases real-time crypto data visualization, network exploration, and token analysis.
- 🌐 Network Explorer: Browse and explore different blockchain networks
- 🪙 Token Discovery: Search and analyze tokens across networks
- 📊 Real-time Charts: Live price data and trading metrics
- 🔄 WebSocket Integration: Real-time updates using Codex subscriptions
- 📱 Responsive Design: Mobile-first, modern UI components
- ⚡ Server-Side Rendering: Fast initial page loads with SSR
- 🎨 Modern UI: Built with Tailwind CSS and Radix UI components
- Node.js >= 17.5.0
- pnpm (recommended)
- A Codex API key from docs.codex.io
-
Set your API key:
export NEXT_PUBLIC_CODEX_API_KEY="your_api_key_here"
-
Install dependencies (from the root directory):
pnpm install
-
Start the development server:
cd examples/next pnpm run dev -
Open your browser: Navigate to http://localhost:3000
Create a .env.local file in this directory:
# Required: Your Codex API key
NEXT_PUBLIC_CODEX_API_KEY=your_api_key_here
# Optional: Custom API endpoints
NEXT_PUBLIC_CODEX_API_URL=https://graph.codex.io/graphql
NEXT_PUBLIC_CODEX_WS_URL=wss://graph.codex.io/graphqlsrc/
├── app/ # Next.js App Router
│ ├── page.tsx # Home page with network list
│ ├── networks/ # Network exploration
│ │ └── [networkId]/ # Dynamic network pages
│ └── layout.tsx # Root layout
├── components/ # React components
│ ├── NetworkList.tsx # Network browsing component
│ ├── TokenChart.tsx # Token price visualization
│ ├── GlitchText.tsx # Animated text effects
│ └── ui/ # Reusable UI components
└── lib/
└── utils.ts # Utility functions
Displays available blockchain networks with real-time data:
// Fetches networks using the Codex SDK
const networks = await sdk.queries.getNetworks({});Renders interactive price charts for tokens:
// Real-time price updates via WebSocket
sdk.subscriptions.onPriceUpdated(params, {
next: (data) => updateChart(data),
});/- Network overview/networks/[networkId]- Network details/networks/[networkId]/tokens/[tokenId]- Token analysis
// app/page.tsx
export default async function HomePage() {
const sdk = new Codex(process.env.NEXT_PUBLIC_CODEX_API_KEY!);
const networks = await sdk.queries.getNetworks({});
return <NetworkList networks={networks} />;
}// components/TokenChart.tsx
useEffect(() => {
const cleanup = sdk.subscriptions.onPriceUpdated(
{ address, networkId },
{
next: (data) => setPriceData(data),
error: (err) => console.error(err),
},
);
return cleanup;
}, [address, networkId]);try {
const token = await sdk.queries.token({ input: { address, networkId } });
setTokenData(token);
} catch (error) {
setError("Failed to fetch token data");
}| Command | Description |
|---|---|
pnpm run dev |
Start development server |
pnpm run build |
Build for production |
pnpm run start |
Start production server |
pnpm run lint |
Run ESLint |
"API key not found"
- Ensure
NEXT_PUBLIC_CODEX_API_KEYis set in your environment - Check that the environment variable starts with
NEXT_PUBLIC_
"WebSocket connection failed"
- Verify your network allows WebSocket connections
- Check that the WebSocket URL is correct
- Ensure your API key has subscription permissions
"Build fails"
# Clear Next.js cache
rm -rf .next
pnpm run build- 🎨 Tailwind CSS
- ♿ Radix UI
- 📊 Recharts