Hello everyone! HTLCs are sooo in right now, so lease meet our friends Grandma Ethel Ethereum and Bitsy Bitcoin who will take us through the world of cross currency swaps with HTLCs. (Adapted from my ETHIS.io presentation).

Grandma Ethel Ethereum (left) and Bitsy Bitcoin (right)

HTLC stands for Hashed Timelock Contract and is most known for its usage in atomic swap implementations as well as in the Lightning Network. They can enable payment routing through multiple hops and various types of conditional payments that can embed other triggers as well!

HTLCs are typically defined by their usage of the following:

Hashlocks to restrict the spending of a contract until the preimage of the hash is revealed. A preimage is a random number that’s used to create the hash: a is a preimage of b if H(a) = b. The SHA256 hash of “we love cryptoeconomics.study” hashes to 85a9bc68a22963785f82d4410fe38807b4c11452af593e81c3ad114e7510f824

Timelocks to restrict the transfer of cryptocurrency until a specified time or blockheight, and as a failsafe in an emergency. For example, if Bitsy and Ethel are transacting but Ethel gets hit by a bus, then Bitsy knows that the funds will be returned to her at the end of the timeout.

But first, Ethel and Bitsy must agree to some terms off-chain:

Along with the exchange rate, timeout, and hash, they must also select a lead to generate the preimage.

Exchange rate: 10 ETH for 1 BTC

Timeout: 1 day

Hash: 85a9bc68a22963785f82d4410fe38807b4c11452af593e81c3ad114e7510f824

Our computer savvy Ethereum grandmother Ethel takes the lead in generating the preimage for the hash.

Ethel then gives this hash to Bitsy for her to use in her contract.

Deploying contracts:

Bitsy deploys a contract to the Bitcoin network with the hash, the timelock, and 1 BTC.

Ethel deploys a contract to the Ethereum network with the hash, the timelock, and 10 ETH.

Ethel must present her preimage “we love cryptoeconomics.study” in order to claim her BTC from Bitsy’s contract. In doing so, Ethel reveals the preimage to Bitsy who can then use it to claim her ETH from Ethel’s contract. Sounds pretty dope.

BUT WAIT!

Holy shit!!!

ETHEL’S BETRAYAL