This guide covers deploying KDEX Core contracts to Base Sepolia testnet and eventually to Base mainnet.
-
Copy the environment template:
cp env.example .env
-
Fill in your environment variables in
.env:# Private key (without 0x prefix) PRIVATE_KEY=your_private_key_here # BaseScan API key for verification BASESCAN_API_KEY=your_api_key_here # Optional: Custom RPC URLs BASE_SEPOLIA_RPC_URL=https://sepolia.base.org BASE_MAINNET_RPC_URL=https://mainnet.base.org
- ETH for gas: Get Base Sepolia ETH from Base Sepolia Faucet
- BaseScan API Key: Register at BaseScan and create an API key
- ETH for gas: Bridge ETH to Base using Base Bridge
- BaseScan API Key: Same as testnet
- ✅ Use a dedicated deployment wallet (not your main wallet)
- ✅ Only fund the deployment wallet with the minimum ETH needed for gas
- ✅ Never commit your
.envfile to version control - ✅ Store your private key securely (consider using a hardware wallet for mainnet)
# Deploy to Base Sepolia with verification and save deployment info
npx hardhat deploy-kdex --network baseSepolia --verify --save
# Deploy to Base Mainnet (when ready)
npx hardhat deploy-kdex --network baseMainnet --verify --savenpx hardhat run scripts/deploy.ts --network baseSepolianpx hardhat verify-kdex --network baseSepolia \
--factory <FACTORY_ADDRESS> \
--ilpmanager <ILP_MANAGER_ADDRESS> \
--deployer <YOUR_DEPLOYER_ADDRESS>npx hardhat check-deployment --network baseSepolia \
--factory <FACTORY_ADDRESS> \
--ilpmanager <ILP_MANAGER_ADDRESS>-
UniswapV2Factory
- Core factory contract for creating trading pairs
- Configured with ILP (Infinite Liquidity Pool) functionality
- Deployer becomes the initial
feeToSetter
-
ILPManager
- Manages accumulated ILP fees
- Connected to the factory for automated fee collection
- Deployer becomes the initial
ilpManagerOwner
- Contract Compilation: Contracts are compiled with optimization enabled (999999 runs)
- Factory Deployment: UniswapV2Factory deployed with deployer as feeToSetter
- ILPManager Deployment: ILPManager deployed with factory address
- Configuration: Factory is configured with ILPManager address
- Verification: Both contracts are verified on BaseScan
- Validation: All connections and configurations are validated
- UniswapV2Factory: ~2.9M gas (2,895,276 gas for pair creation)
- ILPManager: ~800k gas
- Configuration: ~50k gas
- Total: ~5.3M gas (measured: 5,269,530 gas)
- Cost: ~$10-20 at 1 gwei on Base
The deployment script will output contract addresses. Save these for future reference:
UniswapV2Factory: 0x...
ILPManager: 0x...
If automatic verification fails, you can verify manually:
- Go to BaseScan
- Search for your contract address
- Click "Contract" → "Verify and Publish"
- Use Solidity 0.5.16 with optimization enabled (999999 runs)
As the ILP Manager owner, you can configure ILP fee rates for specific tokens:
// Example: Set 10 basis points (0.1%) ILP fee for a token
await ilpManager.setIlpFeeRate(tokenAddress, 10);Use the factory to create trading pairs:
// Create a new trading pair
await factory.createPair(tokenA, tokenB);Before deploying to Base mainnet:
- Thoroughly test on Base Sepolia
- Audit smart contracts (if not already done)
- Prepare sufficient ETH for gas fees (5-10 ETH recommended)
- Use a hardware wallet or secure key management
- Double-check all environment variables
- Have a rollback plan ready
- Prepare announcement/documentation for users
- Insufficient Gas: Increase gas limit in hardhat.config.ts
- Network Connection: Check RPC URL and network connectivity
- Private Key Issues: Ensure no 0x prefix and correct format
- Verification Failures: Wait a few minutes and retry, or verify manually
# Check account balance
npx hardhat run --network baseSepolia -e 'console.log(await ethers.provider.getBalance("YOUR_ADDRESS"))'
# List available tasks
npx hardhat help
# Check network configuration
npx hardhat run --network baseSepolia -e 'console.log(await ethers.provider.getNetwork())'If you encounter issues:
- Check the Base documentation
- Review the deployment logs for specific error messages
- Ensure all prerequisites are met
- Consider testing on a local Hardhat network first
After successful deployment:
- Set up a frontend/SDK to interact with your DEX
- Configure monitoring and analytics
- Plan your token listing and liquidity provision strategy
- Set up governance mechanisms for fee management