A bridge to EOS

Alexander Namgaladze
SwapOnline
Published in
6 min readOct 18, 2018

Next generation Blockchain

Ever since the launch of the EOS token, the project was overwhelmed with an abnormal level of hype, one too high even for a blockchain community. The desperate adherents of the new EOS-religion have fervently defended their idol on the vast battlefields of Reddit and Bitcointalk, while the critics proclaimed the project to be a scam long before the developers even submitted a code for review.

The supporters of the project idea announced that EOS is a new generation of blockchains capable of solving most of the current problems faced by users of the Ethereum network, such as speed and the cost of transactions. Moreover, they also pointed to the limited potential of the main programming language of Ethereum — Solidity, claiming that more experienced C ++ developers will build more complex and reliable smart contracts.

On the other hand, the opponents of EOS proclaimed that its means of attracting funds is blatant fraud and reproached Daniel Lamer for abandoning work on Bitshares, Graphene and Steem. They were also unhappy with the alleged centralization and the system of delegated proof-of-stake, and the refinancing. The most ardent opponents even expressed the opinion that EOS will never launch its mainnet.

Current Situation

Despite the criticism, EOS was successfully launched, the block of producers was selected by means of community voting, the first DApps appeared immediately after the launch, and the demand for C ++ developers in the blockchain environment increased sharply. It is worth paying tribute to some DApps that have already demonstrated greater efficiency in comparison with their Ethereum counterparts. A striking example is EosBet, an uncomplicated example of Dice, which already works on the mainnet and is capable of processing a huge number of transactions at high speeds and without the Mining Fee so traditional for Ethereum.

The community of the project is growing, and so is the need to store and exchange EOS tokens. Several wallets allow users to store the tokens and use them to vote for the block producers of the EOS network. Consequently, users are faced with three needs — storage, voting and exchange. The Swap.Online team has set a goal to provide the EOS community with a convenient and reliable solution to these problems.

Atomic Swaps on EOS

Atomic Swaps using the EOS blockchain are a critically missing solution on the market in its current form. The official EOS Reddit community expected it from Daniel Larimer, but it never happened. So the Swap Online team decoded to get there first. And we did it.

Atomic Swap with EOS: Technical Details

The system works in the following manner:

  1. (open) An EOS owner creates a swap with a BTC participant after the BTC participant has funded the BTC script.
  2. (deposit) Within the same transaction, the EOS owner transfers the required deposit to a smart contract.
  3. (withdraw) The BTC owner then withdraws funds from the smart contract, thus revealing the Secret.
  4. (refund)If the BTC owner does not call a withdraw, then the EOS owner can take the money back.

The smart contract has a special permission to transfer the funds from itself to the BTC owner upon withdrawal action.

EOS uses a WebAssembly virtual machine to run smart contracts. The “eosio.token” is smart contract that enables different tokens including SYS tokens. Users will need to create an account to interact with EOS smart contracts. The Swap Online team prepared scripts and instruction for this, which can be found here. Users can also use the “Register” button on the swap.online website and pay in BTC for account creation. The user also has the function to interact with EOS smart contracts though the EOS endpoint via eosjs library that is imported at swap.online. It is also possible to interact with the special contract for atomic swaps in order to exchange BTC to EOS using the swap.online orderbook.

When the user agrees to make a peer-to-peer atomic swap with the owner of EOS tokens, then they have to prefund the HTLC Bitcoin script. Then the owner of EOS will be notified and will send funds to the swap smart contract. In order to withdraw the EOS funds from the smart contracts, the user will have to reveal their secret from the HTLC script in the same transaction. Then the owner of EOS will notified and will withdraw the BTC using the given secret.

Every swap in the smart contract has a period of time when users can withdraw the funds and reveal their secret. That period is twice as less as the period of HTLC to ensure that the EOS owner will have enough time to withdraw their Bitcoins from the HTLC.

If you will not reveal your secret during this period of time, then the EOS owner will be able to get a refund and the opposing user’s reputation on swap.online will be decreased. If the EOS owner will not create a swap when they prefunded the HTLC script, then their reputation will be decreased.

The smart contract has actions that mutate the state of a contract. Single transactions can have multiple actions. The swap contract has the create, deposit, refund, withdraw and refund actions. When the EOS owner creates swap they send two actions in a single transaction: create and deposit. The swap contract immediately sees that it received EOS token and creates an open swap that is available for withdraw by revealing the secret key. When the user withdraws funds from the swap, they send a withdraw action with their secret key in the argument. When the EOS owner wants to get a refund after the safe period of time, they send a refund action. The code of the smart contract account has the permission to transfer funds to the user.

Again

  1. When owner of BTC agrees to make a peer-to-peer atomic swap with the owner of BTC then owner of BTC have to prefund the HTLC Bitcoin Script
  2. Then the owner of EOS will be notified and will send funds to the swap smart contract.
  3. In order to withdraw EOS from the smart contract, the owner of BTC will reveal his secret from HTLC script in the withdrawal transaction.
  4. Then the owner of EOS will be notified and will withdraw BTC using revealed secret.

We are still working on development of EOS and adding new features. If you have any suggestions or feedback — feel free to share it in our official telegram group. Also, you may check our EOS contract here.

--

--