Token Sweeper is a DeFi application that enables users to efficiently sweep multiple small ERC-20 token balances into a single preferred token using EIP-7702 batch transactions. Experience atomic swaps with a single signature across Base and Optimism mainnets.
- 🔄 Multi-Token Consolidation: Convert multiple dust tokens into a single preferred token with optimal routing
- ⚡ EIP-7702 Batch Transactions: Execute all swaps atomically in a single transaction signature
- 📊 Real-time Portfolio Tracking: Live token balance fetching via Covalent GoldRush Token API
- 🛡️ Advanced Spam Filtering: Spam/scam token detection via Covalent GoldRush Token API and Aerodrome/Velodrome Swap APIs
- 🌐 Multi-Chain Support: Full support for Base (8453) and Optimism (10) with native DEX integration (Aerodrome and Velodrome)
- 📱 Social Achievement Cards: Generate and share beautiful post-swap achievement cards
token-sweeper/
├── app/ # Next.js App Router
│ ├── api/ # API routes
│ │ ├── covalent/ # Covalent API integration
│ │ ├── swap/ # Swap API integration
│ │ └── tokens/ # Token API integration
│ ├── layout.tsx # Root layout with providers
│ ├── page.tsx # Main application component
│ └── globals.css # Global styles
├── components/ # React components
│ ├── ui/ # shadcn/ui components
│ │ ├── button.tsx
│ │ ├── card.tsx
│ │ ├── badge.tsx
│ │ └── ...
│ ├── eip-7702-info.tsx # EIP-7702 information display
│ ├── footer.tsx # App footer
│ └── providers.tsx # Context providers
│ ├── social-card.tsx # Shareable achievement cards
│ ├── swap-configuration.tsx # Swap quotes and execution
│ ├── token-portfolio.tsx # Token selection interface
│ ├── wallet-connection.tsx # Wallet connection interface
├── hooks/ # Custom React hooks
│ ├── use-outcome-tokens.ts # DEX token fetching
│ ├── use-swap-builder.ts # Transaction building
│ ├── use-swap-quotes.ts # Swap quote fetching
│ ├── use-token-balances.ts # Covalent API integration
│ ├── use-verified-tokens.ts # Token verification (cached)
├── lib/ # Utility functions
│ ├── config.ts # Application configuration
│ ├── env-validation.ts # Environment validation
│ ├── logger.ts # Structured logging
│ ├── token-config.ts # Token configurations
│ └── utils.ts # General utilities
├── types/ # Type definitions
│ ├── index.ts # Main type exports
├── package.json # Dependencies and scripts
├── tailwind.config.ts # Tailwind CSS configuration
├── next.config.mjs # Next.js configuration
└── tsconfig.json # TypeScript configuration
- Next.js 14: React framework with App Router
- TypeScript: Type-safe development
- Tailwind CSS: Utility-first CSS framework
- shadcn/ui: Modern React component library
- Wagmi: React hooks for Ethereum
- Viem: TypeScript interface for Ethereum
- RainbowKit: Wallet connection
- EIP-7702: Atomic batch transaction support
- Covalent GoldRush Wallet API: Token balance fetching
- Aerodrome Swap API: Quotes and swaps on Aerodrome, leading DEX on Base
- Velodrome Swap API: Quotes and swaps on Velodrome, leading DEX on Optimism
- React Hooks: Component-level state
- TanStack Query: Server state management
- Local Caching: API response caching (5-minute TTL)
To run and use this application, you will need the following:
- Node.js 20+
- A Quicknode account with Base or Optimism endpoints
- The Covalent Token API add-on (free tier not available) and Aerodrome or Velodrome Swap API add-on (free tier available)
- Project ID from Reown, formerly WalletConnect
- MetaMask or compatible wallet with EIP-7702 support
- Create Endpoints: Log in to your Quicknode account and create a new endpoint for each chain you want to support. For this guide, we will use Base and Optimism.
Since these API add-ons are available on mainnet only, you will need to set up your Quicknode account with a mainnet endpoint.
- Install Add-ons:
- Once you are in your endpoint's dashboard, navigate to the Add-ons for your endpoint.
- Install the Covalent Token API add-on.
- Install the Aerodrome Swap API and Velodrome Swap API add-ons. You can use the free tier for the swap APIs to start.
-
Get Covalent API Key: Click Sign in to Dashboard next to the Covalent Token API add-on. This will redirect you to the Covalent dashboard where you can find your API key.
-
Get Swap API URLs: Click Getting Started next to the Aerodrome or Velodrome Swap API add-on. This will show you the base API URLs you need to use in your application. Use the URL before the
/v1/...part, as we will append the specific endpoints in our code. It should look something like this:https://YOUR-QUICKNODE-ENDPOINT-URL/addon/YOUR-ADDON-ID
-
Create a Reown (formerly, WalletConnect) Project: Head to the Reown Cloud and create a new project. You can name it whatever you want.
-
Get Project ID: After creating the project, you will be redirected to the project dashboard. Here, you can find your Project ID, which you'll need to use in your application.
- Clone the repository
git clone https://github.com/quiknode-labs/qn-guide-examples.git
cd qn-guide-examples/sample-dapps/token-sweeper-eip-7702- Install dependencies
npm install
# or using yarn
yarn install
# or using pnpm
pnpm install- Set up environment variables
cp .env.example .env.localRequired environment variables:
COVALENT_API_KEY=your-covalent-api-key
NEXT_PUBLIC_WALLETCONNECT_PROJECT_ID=your-walletconnect-project-id
NEXT_PUBLIC_BASE_RPC_URL=your-base-rpc-url
NEXT_PUBLIC_OPTIMISM_RPC_URL=your-optimism-rpc-url
AERODROME_BASE_API=aerodrome-api-endpoint
VELODROME_OPTIMISM_API=velodrome-api-endpoint- Start the development server
npm run dev
# or using yarn
yarn dev
# or using pnpm
pnpm dev- Visit the application
http://localhost:3000
- Connect your wallet: Click the "Connect Wallet" button and select your wallet provider (e.g., MetaMask).
- View your token portfolio: The application will fetch and display your ERC-20 token balances.
- Select tokens to sweep: Choose the tokens you want to consolidate and the preferred output token.
- Review swap quotes: The application will calculate and display the best swap quotes for your selected tokens.
- Execute the swap: Confirm the transaction to sweep your tokens into the preferred token. If you have a smart account, it will execute as a single batch transaction; otherwise, it will process sequentially.
- Share your achievement: After the swap, you can generate a social achievement card to share your success on social media.
| Network | Chain ID | DEX Integration | Status |
|---|---|---|---|
| Base Mainnet | 8453 | Aerodrome | ✅ Active |
| Optimism Mainnet | 10 | Velodrome | ✅ Active |


