Atomic Swap (HTLC) [ GBV — ETH ]

Atomic swap is a method of digital assets functioning that provides an opportunity for fast exchange between two cryptocurrencies operating on different blockchains.

This process (also known as atomic cross-chain trading) is based on smart contracts and allows users to trade coins directly from the cryptocurrency wallet.

Operating principle

Atomic swap protocols are designed in to prevent fraud on the part of any of the participants. To understand how it works, let’s imagine that User1 wants to exchange (GBV) for Ethereum (ETH) with User2.

First of all, User1 makes a deposit in ETH to the contract’ address, which acts as a safe. When this safe is created, User1 generates a key to access it. Then it shares the cryptographic hash of this key with User2. Please note, that User2 cannot access GBV yet because it only has the hash of the key, not the key itself. Then User2 uses the hash provided by User1 to create another secure contract address where its ETH is stored. To get ETH, User1 must use the same key, thus providing its currency to User2 (thanks to a special function called a hashlock). This means that as soon as User1 requests ETH, User2 in turn will also request GBV, after which the currency exchange will be completed.

The term «atomic» refers to the fact that these transactions are either carried out in full or do not occur at all. If one of the parties does not fulfill its obligations, the contract is canceled and the funds are automatically returned to their owners.

Atomic swaps can occur in two different ways:

in a chain;

outside the chain.

Please note that User2 cannot access GBV yet because it only has the hash of the key and not the key itself.

What is HTLS (Hash Time lock Contracts)

Hashed Timelock Contract (HTLC) is a type of smart contract used in cryptocurrency channels to eliminate counterparty risk. This allows for timebound transactions

In practical terms, this means that the recipients of the transaction must confirm the payment by creating a cryptographic confirmation within a certain period of time. Otherwise, the transaction will not take place.

The Hashed Time Lock (HTC) contract uses several elements from existing cryptocurrency transactions. For example, HTLC transactions use multiple signatures, which consist of a private public key, to validate and validate transactions. But there are two elements that distinguish HTLC from standard cryptocurrency transactions.

The scheme of interaction between the GBV blockchain and the Ethereum blockchain
Operation Algorithm
  1. User1 selects a random value, which we will call «preimage“ and passes it through an irreversible hash function, getting a hashed value, which we will call H.
  2. A contract is created between the user User1 and User2 in the GBV blockchain.
  3. Transfer of the contract address generated in step 2 to the user User2.
  4. User2 Creates a contract on the Ethereum network with the provided preimage from step 3. And transfers funds to a smart contract (reservation).
  5. The received contract identifier from the Ethereum network is transmitted to the user User1.
  6. User1 on the Ethereum network checks the details of the contract.
  7. Sending funds to the Ethereum network From the contract to the User1 wallet.