Decentralized exchanges (DEXs) have become targets for hacks due to vulnerabilities in smart contract coding and logic. To prevent these attacks, DEXs should implement thorough testing, conduct internal and external audits, utilize multi-signature protection, and engage in bug bounty programs. Despite their risks, DEXs are vital for the crypto ecosystem, and ensuring robust security measures is essential for their success.