A modern Next.js application demonstrating ETH staking capabilities using the Coinbase Developer Platform (CDP) SDK. This project showcases how to build an intuitive staking interface with real-time balance tracking, staking operations, and seamless wallet integration.
- ETH Staking Operations: Stake and unstake ETH with intuitive UI controls
- Real-time Balance Tracking: Monitor staking balances and rewards in real-time
- CDP SDK Integration: Leverages Coinbase Developer Platform for secure staking operations
- Modern UI/UX: Clean, responsive interface built with React and Tailwind CSS
- Wallet Integration: Seamless wallet connection using ConnectKit
- Base Network Support: Built for Base network integration
- TypeScript Implementation: Fully typed codebase for better development experience
- Next.js 15: React framework with App Router and Turbopack
- Coinbase CDP SDK: Core staking functionality and wallet management
- ConnectKit: Wallet connection and management
- Wagmi & Viem: Ethereum interaction libraries
- React Query: Data fetching and state management
- Tailwind CSS: Utility-first CSS framework
- TypeScript: Type-safe development environment
- Node.js (v18 or later)
- npm, yarn, pnpm, or bun package manager
- A wallet that supports Ethereum staking
- Coinbase Developer Platform API key (for advanced features)
# Clone the repository
git clone https://github.com/HeimLabs/coinbase-cdp-demos.git
cd 13-CDP-Staking-Demo
# Install dependencies
npm install
# or
yarn install
# or
pnpm install
# or
bun install# Copy the example environment file (if available)
cp .env.example .envAdd any required configuration:
# CDP API Key (optional, for enhanced features)
CDP_API_KEY_NAME=your_api_key_name_here
CDP_API_KEY_PRIVATE_KEY=your_private_key_here
# Network Configuration
NEXT_PUBLIC_NETWORK=basenpm run dev
# or
yarn dev
# or
pnpm dev
# or
bun devOpen http://localhost:3000 with your browser to see the result.
- Click "Connect Wallet" to open the wallet selection modal
- Choose your preferred wallet (MetaMask, Coinbase Wallet, WalletConnect, etc.)
- Approve the connection and ensure you're on the correct network
- Enter the amount of ETH you want to stake
- Review the staking details including estimated rewards
- Click "Stake ETH" and confirm the transaction in your wallet
- Monitor your staking position in real-time
- View your active stakes in the dashboard
- Track rewards accumulation with live updates
- Unstake when ready by clicking the unstake button
- Claim rewards as they become available
13-CDP-Staking-Demo/
├── app/
│ ├── page.tsx # Main staking interface
│ ├── layout.tsx # Root layout with providers
│ ├── globals.css # Global styles and Tailwind
│ └── providers.tsx # Wagmi and React Query providers
├── next.config.ts # Next.js configuration
├── tailwind.config.ts # Tailwind CSS configuration
└── tsconfig.json # TypeScript configuration
- Staking Interface: Interactive UI for staking operations
- Balance Display: Real-time ETH and staked balance tracking
- Transaction Management: Handle staking and unstaking transactions
- Wallet Integration: ConnectKit-powered wallet connection
// Example staking operation
const stakeETH = async (amount: string) => {
try {
// Prepare staking transaction
const transaction = await prepareStakeTransaction(amount);
// Execute via CDP SDK
const result = await cdp.stake({
amount: parseEther(amount),
validator: selectedValidator,
});
console.log('Staking successful:', result.transactionHash);
} catch (error) {
console.error('Staking failed:', error);
}
};- Individual Staking: Personal ETH staking with user-friendly interface
- Portfolio Management: Track multiple staking positions
- Educational Demo: Learn about Ethereum staking mechanisms
- DApp Integration: Reference implementation for staking features
- Yield Farming: Explore staking rewards and strategies
Update staking configuration in your components:
const stakingConfig = {
minimumStake: parseEther('0.01'), // Minimum stake amount
maxStake: parseEther('32'), // Maximum stake per operation
validator: '0x....', // Preferred validator address
network: 'base', // Target network
};The interface can be customized through:
- Tailwind Classes: Modify styling directly in components
- CSS Variables: Update theme colors in
globals.css - Component Structure: Adjust layout in
page.tsx
Switch networks by updating the Wagmi configuration:
const config = createConfig({
chains: [mainnet, base], // Add or modify supported chains
connectors: [
// Wallet connectors
],
});npm run dev: Start development server with Turbopacknpm run build: Build for productionnpm run start: Start production servernpm run lint: Run ESLint for code quality
- New Staking Strategies: Extend with additional staking mechanisms
- Reward Tracking: Implement detailed reward analytics
- Multi-Asset Support: Add support for other stakeable assets
- Advanced UI: Build more sophisticated user interfaces
For production deployment:
- Environment Variables: Set production API keys and configuration
- Network Configuration: Update to mainnet if deploying to production
- Security Review: Audit smart contract interactions
- Performance Optimization: Implement caching and optimization strategies
- Monitoring: Add error tracking and analytics
- This demo is designed for educational purposes; review security practices before mainnet deployment
- Never commit private keys or sensitive environment variables
- Implement proper validation for staking amounts and parameters
- Consider slashing risks and validator selection carefully
- Test thoroughly on testnets before using real ETH
Contributions are welcome! To contribute:
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
Disclaimer: This project is for demonstration purposes. Staking involves risks including potential loss of funds due to slashing. Always do your own research and consider the risks before staking real ETH.
Built with ❤️ using Coinbase Developer Platform