This post was first published on Medium.
Using Hash Time-Locked Contracts
As we have shown before, Ordinals can be seamlessly combined with bitcoin smart contracts. To further demonstrate the power and flexibility of combining them, we lock up an ordinal into a Hash Time-Locked Contract (HTLC) and atomically swap it with bitcoins, allowing trustless trading.
- Swap between assets on the same chain, instead of across two different chains. The protocol works the same since it relies on two hash locks having same PINs/preimages, regardless of the blockchains they are running on.
- Swap Ordinals tokens rather than native assets such as BTC or BSV.
During setup, an ordinal is transferred to a HLTC, whose code we reproduce below.
The rest of protocol execution is the same as swapping BSV and BTC.
Here is a run for Ordinal #25883457:
- setup tx: https://whatsonchain.com/tx/63370f71e1f52474f74
- swap tx: https://whatsonchain.com/tx/d4eb46f64941ba6d08
It is straightforward to extend it to atomically swap other pair of assets, as long as they are on chains that support both HLTC and Ordinals, e.g.,
- Ordinals <-> Ordinals: same chain or different chains
- Ordinals on Bitcore Core <-> BTC
- Ordinals on Bitcoin SV <-> BTC
- Ordinals on Bitcoin Core <-> BSV.
Watch CoinGeek Roundtable Episode 7: 1Sat Ordinals on Bitcoin
New to blockchain? Check out CoinGeek’s Blockchain for Beginners section, the ultimate resource guide to learn more about blockchain technology.