Build a real DEX on Bitcoin in 20 minutes!
This is a complete starter kit for building decentralized exchanges on MIDL - Bitcoin Layer 1 with EVM compatibility. You'll deploy Uniswap V2 contracts, create trading pairs, and execute real swaps on Bitcoin!
New here? Start with the hands-on tutorial:
This guide walks you through everything step-by-step. No prior Bitcoin or DeFi experience needed!
What you'll build:
- ✅ Your own DEX on Bitcoin (like Uniswap)
- ✅ Custom tokens (TBTC & WBTC)
- ✅ Live liquidity pools
- ✅ Real swaps on Bitcoin L1
Time needed: 15-20 minutes
This starter kit includes:
- ✅ Uniswap V2 Contracts - Battle-tested AMM
- ✅ Deployment Scripts - One-command deployment
- ✅ Testing Scripts - Automated DEX testing
- ✅ Frontend UI - React interface (optional)
- ✅ Complete Docs - Step-by-step guides
- Node.js 18+
- pnpm
- Test Bitcoin wallet (Xverse recommended)
# Clone repository
git clone https://github.com/Svector-anu/midint.git
cd midint
# Install dependencies
cd contracts && pnpm install
cd ../frontend && pnpm installcd contracts
# Deploy all contracts
npx hardhat deploy --network default
# Mint test tokens
npx hardhat deploy --tags Faucet --network default
# Test complete DEX flow
npx hardhat deploy --tags TestDex --network default-
SCRIPT_TUTORIAL.md ⭐ RECOMMENDED
- Complete script-based guide
- Production-ready approach
- All operations via Hardhat scripts
-
- Original full-stack tutorial
- Frontend + Backend integration
- Comprehensive overview
- TESTING.md - Testing workflows and verification
- FRONTEND_FIX.md - Frontend implementation details
- SCREENSHOTS.md - Tutorial screenshots guide
contracts/
├── TestToken.sol # ERC20 with minting (TBTC)
├── WBTC.sol # Wrapped Bitcoin
├── UniswapV2Factory.sol
├── UniswapV2Router02.sol
└── UniswapV2Pair.sol
deploy/
├── 00_deploy_tokens.ts # Deploy TBTC & WBTC
├── 02_deploy_factory.ts # Deploy Uniswap Factory
├── 03_deploy_router.ts # Deploy Uniswap Router
├── 04_create_pair.ts # Create TBTC/WBTC pair
├── 05_add_liquidity.ts # Add initial liquidity
├── 08_faucet.ts # Mint test tokens
└── 09_test_dex.ts # Complete DEX test
frontend/
├── src/
│ ├── components/ # React components
│ ├── config/ # MIDL & contract config
│ └── styles/ # CSS styling
└── package.json
npx hardhat deploy --tags Faucet --network defaultOutput:
🚰 MIDL Token Faucet
Minting tokens to: 0xF8483dddbCB103519F8BfE1713aBDa4f3A9C20b0
Minting 1,000 TBTC...
✅ 1,000 TBTC minted!
npx hardhat deploy --tags TestDex --network defaultOutput:
🧪 Testing Complete DEX Flow
✅ Step 1: Approving Router for TBTC...
✅ Step 2: Approving Router for WBTC...
💧 Step 3: Adding Liquidity (100 TBTC + 1 WBTC)...
🔄 Step 4: Swapping 10 TBTC for WBTC...
✅ DEX Test Complete!
https://blockscout.regtest.midl.xyz/address/YOUR_ADDRESS
| Contract | Address |
|---|---|
| TBTC | 0xA4D2CbAF027125a967E48e94b1Baa03363981b1c |
| WBTC | 0xca0daeff9cB8DED3EEF075Df62aDBb1522479639 |
| Factory | 0xde6c29923d7BB9FDbcDfEC54E7e726894B982593 |
| Router | 0x29cf3A9B709f94Eb46fBbA67753B90E721ddC9Ed |
- Start Here: Read SCRIPT_TUTORIAL.md
- Deploy Contracts: Follow the Quick Start guide
- Run Tests: Execute the Faucet and TestDex scripts
- Verify: Check transactions on Blockscout
- Customize: Modify scripts for your use case
cd frontend
pnpm dev
# Open http://localhost:3000Note: Frontend is for visualization only. Use Hardhat scripts for transactions.
Create new scripts in contracts/scripts/:
import { ethers } from "hardhat";
async function main() {
const hre = require("hardhat");
await hre.midl.initialize();
// Your custom logic here
await hre.midl.execute();
}
main().catch(console.error);- ✅ Use TEST WALLETS ONLY for development
- ✅ Never commit private keys or mnemonics
- ✅ Audit contracts before mainnet deployment
- ✅ Test thoroughly on testnet first
- RPC:
https://rpc.regtest.midl.xyz - Explorer:
https://blockscout.regtest.midl.xyz
- RPC:
https://rpc.testnet.midl.xyz - Explorer:
https://blockscout.testnet.midl.xyz
- RPC:
https://rpc.mainnet.midl.xyz - Explorer:
https://blockscout.mainnet.midl.xyz
Create contracts/.env:
MNEMONIC="your twelve word test wallet mnemonic here"
RPC_URL="https://rpc.regtest.midl.xyz"Contributions welcome! Please:
- Fork the repository
- Create a feature branch
- Make your changes
- Submit a pull request
MIT License - see LICENSE file
- MIDL Documentation: https://js.midl.xyz
- Hardhat Documentation: https://hardhat.org
- Uniswap V2 Docs: https://docs.uniswap.org/contracts/v2
- GitHub Repository: https://github.com/Svector-anu/midint
- Reliability: Direct integration with MIDL's intention system
- Simplicity: No wallet connection complexity
- Production Pattern: Same approach used in production dApps
- Full Control: Complete visibility into execution
Hardhat Script
↓
hre.midl.execute({...}) // Queue intention
↓
hre.midl.execute() // Execute all intentions
↓
MIDL RPC (wraps in BTC tx)
↓
Bitcoin L1 Execution
- ✅ Customize Scripts - Modify for your use case
- ✅ Add Features - Multi-hop swaps, price oracles
- ✅ Deploy to Testnet - Test with real BTC
- ✅ Build Frontend - Create read-only UI
- ✅ Audit & Launch - Security review and mainnet
- Issues: https://github.com/Svector-anu/midint/issues
- Discussions: https://github.com/Svector-anu/midint/discussions
- MIDL Telegram: https://t.me/midl_xyz
**Built by Anu ** | Powered by MIDL