V Atomic Swap Contract: a cross-chain DEX solution

V Systems
V Systems
Published in
4 min readAug 16, 2021


Decentralized exchanges will replace centralized exchanges. To further decentralize cryptocurrency trading, a cross-chain solution is needed to make it possible to exchange coins between different blockchains without any intermediate tokens or third parties.

V Atomic Swap

V Atomic Swap allows for cross-chain communication between different cryptocurrencies such as Bitcoin and Ether in non-custodial wallet without the need to trust third-party providers, and without any pegged tokens.

By using the properties of a hash function which is deterministic (the same input gives the same output) and cannot be reversed (the input cannot be determined from the output), users can trade directly from their wallet and funds are not transferred anywhere besides hash time locked contracts for Atomic swap execution, meaning the execution is fully decentralized.

V Atomic Swap allows users to exchange one asset for another atomically, such that the entire process either succeeds or fails. This allows for no risk for either party losing out by only one of the two transfers completing. As long as Atomic swaps are implemented correctly, it is virtually impossible for either party to cheat. The two possible outcomes of an Atomic swap are either, both parties receive the funds agreed upon, or the swap fails and the funds don’t switch ownership.


If Alice wishes to swap 100 Token A for 100 of Bob’s Token B in the ratio 1:1, Alice will first create a secret Secret A and hash it, generating Hash(Secret A). Since hashes are infeasible to reverse, no one should be able to get Secret A from Hash(Secret A).

Alice then creates an Atomic Swap contract Contract A which releases 100 Token A to Bob as long as Bob can broadcast Secret A before timestamp 1000. The contract also shows Hash(Secret A) publicly.

Bob copies Hash(Secret A) into his own Atomic Swap contract Contract B that releases 100 Token B to Alice as long as she can broadcast Secret A before timestamp 500. Alice then broadcasts Secret A to obtain these 100 Token B, revealing Secret A to the entire blockchain.

Bob now knows Secret A and has at least 500 seconds to broadcast it to obtain the 100 Token A. Of course, the entire blockchain knows Secret A, however, the contract specifies Bob as the recipient, as such, he is the only one who can obtain the stored Token A.


The V Atomic Swap contract can store a single type of Token, to swap between different Tokens, two separate contracts are necessary. Users are required to deposit Tokens into the contract before they are able to lock it.

The lock function itself is fairly simple, the input should be the hash of some secret together with the determined recipient and an expiration timestamp. To unlock the lock, the recipient simply needs to call the SolvePuzzle function with the transaction id of the lock together with the secret.

The contract will check that the hash of the secret matches the puzzle in the lock. If it matches, the contract will transfer ownership of the locked coins or tokens to the recipient. Note however, that while the funds change ownership, they stay within the contract, so the wallet’s balance won’t change until the recipient withdraws the funds from the contract.

To sum up, V Atomic Swap is a method of swapping tokens in a secure manner that requires no trusted party to hold custody of the coins. It is a simple way to remove the importance of transaction ordering or time, to use a pre-commit scheme to mitigate the risk.

We believe the enabling of the creation of cross-chain deals between different cryptocurrencies in a non-custodial way will help bring DeFi, especially DEX innovation to a new level.



V Systems
V Systems

A blockchain platform that supports the efficient and agile development of decentralized applications. Visit our website at www.v.systems