Move to Hodl Hodl: The technical perspective

This article is from the series “Move to Hodl Hodl” and explains what’s under the hood of the exchange, and how it looks from a technical perspective, and why Hodl Hodl can’t get hold of your bitcoins and run away with them.

Let’s get everything in order.

In this article, we’ll mostly explain how contracts at Hodl Hodl work from the inside out, because multisig contracts are still not a common thing among Bitcoin users.

With Hodl Hodl, you have a choice: trade on the Bitcoin blockchain (on-chain trades), or on the Lightning Network. We’ll explain how these two contract types differ, and we’ll delve deeper into both contract types.

On-chain contracts

For on chain contracts, we provide an automated non-custodial solution, which allows the exchange to avoid holding funds, and our customers to trade securely and anonymously.

When a contract is initiated, Hodl Hodl would generate a 2 out of 3 multisig Bitcoin address. Every address is generated in SegWit format (P2SH-P2WSH) and everyone can send and receive funds directly from escrow to Bech32 addresses.

There are three keys to escrow, with two of them required to release bitcoins from escrow: buyer, seller, and the exchange each hold one key.

  • The user’s escrow key pair is generated in the browser, and is encrypted by a payment password that every user is asked to create before starting their first contract. We only store private keys encrypted by payment passwords on our servers, so there’s no way to decrypt user’s private key without the payment password. The password is only known to the user and is never sent to or stored in the backend.

Contract starts with buyer and seller confirming their payment passwords before we show the seller an escrow address to which he needs to deposit bitcoins. By confirming the password, the frontend side is able to decrypt the private keys it received from the backend and generate an escrow address.

When seller sends bitcoins to the multisig address we immediately see it and once it receives the required number of confirmation(s) stated in the contract description, we automatically change the status of the contract, and inform the buyer that the bitcoins are locked in escrow and it is safe to make the payment.

Next, buyer pays the seller, and there are two scenarios with three different outcomes:

Contract is completed successfully: seller simply initiates the release from escrow to buyers Bitcoin address. To do that, the seller enters his payment password to sign the transaction with his private key on his side, while Hodl Hodl automatically signs the transaction with its key in the backend.

A dispute is started: Hodl Hodl resolves the dispute:

  • If the seller wins the dispute, Hodl Hodl allows him to refund the bitcoins using his payment password, and automatically signs the transaction with its key.
  • If the buyer wins the dispute, Hodl Hodl allows him to make the release from escrow to himself, using his payment password, and automatically signs the transaction with its key.

When it’s impossible to tell who is right, Hodl Hodl will not allow a release from escrow, and will not sign the release transaction, effectively leaving bitcoins locked until sufficient evidence is obtained that would help come to a correct decision.

The transaction signing process is the following:

  1. Client gets raw unsigned transaction, and when the payment password is confirmed, the transaction gets signed with the decrypted user’s key right in user’s browser.
  2. Half-signed transaction is sent back to the server.
  3. Hodl Hodl signs the transaction with its key on the server side and broadcasts it.

When (and only when) a contract is successfully completed, Hodl Hodl also receives exchange fee — we simply add an additional output to the release transaction, and deduct our exchange fee from the deposit amount.

Lightning exchange mode

When we started working on Lightning Network support, we didn’t know it’s possible to implement a non-custodial working scheme, and decided to act as an intermediary in Lightning contracts.

Basically, we set up our own lightning node using LND (030bde3ee226b7cf456703811976e4241a929d11e5fc0549e9a1c6d10a8e23a738), through which we have our Lighting wallet. We also wrote our own library, which allows us to automate & secure the trading process.

When a contract is initiated, the exchange generates an invoice for the amount of the contract, and the seller has to pay it from his wallet, thus locking the funds in the exchange’s wallet for the contract’s lifetime.

When we see funds in our wallet, the buyer pays the seller and then specifies the invoice for his wallet in order to receive funds from our wallet. As with on-chain contracts, there are two scenarios with three different outcomes:

Contract is completed successfully: seller simply initiates the release from our wallet, and we pay the buyers invoice.

Dispute is started: Hodl Hodl resolves the dispute:

  • If the seller wins the dispute, Hodl Hodl allows him to refund the bitcoins, paying the invoice the seller provides.
  • If the buyer wins the dispute, Hodl Hodl allows him to make the release from escrow to himself, paying the invoice the buyer provides.

When it’s impossible to tell who is right, Hodl Hodl will not allow a release from escrow, effectively leaving bitcoins locked in our Lightning wallet until sufficient evidence is obtained that would help come to a correct decision.

Paying an invoice is an automated process, which is being managed using our own Lightning Network library. Client side everything is simple: the user only has to click a few buttons on the contract page.

When (and only when) a contract is successfully completed, Hodl Hodl also receives exchange fee — we simply ask the buyer to send us an invoice for a specified amount that takes into account our exchange fee.

Next post

In the next post we’ll dig deeper into the underlying features, and see what implicit functions does the exchange have!

Reach us

Hodl!

--

--

--

P2P cryptocurrency trading platform that doesn’t hold funds

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

May Governance Voting Guide

AVOCADO COIN: INTRODUCTION OF BLOCKCHAIN TECHNOLOGY INTO AGRICULTURE TO HELP ERADICATE POVERTY AND…

Introducing Easy Options to Simplify Options Trading

Sustainable Crypto?

Crypto Moonshots on Binance Smart Chain

Why, MaskDAO. For Real Now.

5 Most Underrated Crypto.com Features (And Why You Should Use Them)

How To Do Your Own Research (DYOR)

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Hodl Hodl

Hodl Hodl

P2P cryptocurrency trading platform that doesn’t hold funds

More from Medium

Nathalie Arias Bitcoin Immediate– Review

Ripple: Ryan Fugger 05.24.2006

What is Bitcoin mining?

What is MoneySwitch