What is an Atomic Swap?
An atomic swap is a peer-to-peer exchange of cryptocurrencies residing on different blockchains. The 'atomic' nature means the swap either completes successfully for both parties or fails entirely, ensuring neither party can cheat the other by receiving funds without sending theirs. This is typically achieved using Hashed Timelock Contracts (HTLCs).
How it Works (using HTLCs)
- Initiation: Alice wants to trade her Coin A for Bob's Coin B. Alice generates a secret (preimage) and creates its hash.
- Alice's Contract: Alice creates a smart contract on Coin A's blockchain that locks her Coin A. Bob can claim these coins if he provides the secret within a specific timeframe (e.g., 48 hours). If not, Alice can reclaim her coins.
- Bob's Contract: Bob creates a similar smart contract on Coin B's blockchain, locking his Coin B. Alice can claim these coins if she provides the same secret within a shorter timeframe (e.g., 24 hours), using the hash Alice provided. If not, Bob can reclaim his coins.
- Alice Claims: Alice reveals the secret to claim Bob's Coin B from his contract.
- Bob Claims: By claiming, Alice reveals the secret on Coin B's blockchain. Bob sees this secret and uses it to claim Alice's Coin A from her contract before her longer timelock expires.
If anything goes wrong or time runs out, both parties can reclaim their original funds.
Benefits
- Decentralization: Removes the need for centralized exchanges.
- Security: Reduces counterparty risk as funds are locked in contracts.
- Lower Fees: Potentially lower fees compared to exchanges.
Requirements
- Both blockchains must support HTLCs or similar smart contract functionality.
- Both blockchains must use the same hashing algorithm.
Related Terms
- Smart Contract
- Hashed Timelock Contract (HTLC) (Implicit - needs creation)
- Interoperability
- Peer to Peer
Ready to Start Trading?
Join The Kingfisher community and get access to professional-grade trading tools and insights.