Building Ergo: Atomic Swaps

Translation temporarily unavailable. Showing original English.
Guy Brandon

24 aprile 2020

Because a blockchain is a siloed, self-contained system by design, interacting with other blockchain protocols is challenging. Atomic Swaps enable cross-chain exchange of digital assets, avoiding the need for centralised exchanges.

Blockchains are excellent at decentralised value transfer within their own domains. That is, you can send BTC to any Bitcoin address securely and easily, and you can send LTC to any Litecoin address securely and easily too.

But because blockchains are based on consensus between miners, they are not designed to interface with other blockchains. Trading assets on different blockchains has therefore traditionally involved third parties like exchanges and OTC desks – with all the risks and inefficiencies they bring.

Cross-chain swaps

Atomic swaps solve this problem by enabling cryptocurrencies to be traded across blockchains. This allows trustless exchange of assets, quickly and efficiently. Here’s how they work in theory:

  • Alice and Bob agree to exchange some cryptocurrency. Alice will send Bob 1 BTC, and Bob will send Alice 50,000 ERG. Neither party trusts the other, so neither wants to send their crypto first.

  • Alice generates a secret – a long random number – and hashes it. She then creates a transaction on the Bitcoin blockchain with a script attached, locking 1 BTC and specifying a condition: when the secret (pre-image) to the hash she has created is revealed, the BTC will be sent to Bob’s address. The hash can safely be included in the transaction script, because the pre-image cannot be calculated from it.

  • Bob then similarly creates a transaction on the Ergo blockchain, including a script with the same hash Alice has used. When the pre-image is revealed, 50,000 locked ERG will be sent from Bob’s address to Alice’s address. Because Bob doesn’t have the pre-image, he can’t execute Alice’s transaction before he has created his own.

  • Once Alice sees that Bob has created his transaction on the Ergo blockchain, she can publish the secret and execute his transaction. Because the pre-image is now public, Bob can also use it to execute the script that will send him his BTC.

  • Neither party can delete their transactions and scripts once they have been posted to the blockchain. They may include a condition that the transaction will expire within a certain time, to avoid their coins being locked indefinitely if Alice does not reveal the secret.

  • Ergo’s atomic swaps

They are called ‘atomic’ swaps because the orders are either executed in their entirety, or not at all – a kind of fill-or-kill order. But while that’s useful up to a point, it doesn’t allow for active trading, like you would be able to do on an exchange.

Ergo’s implementation of atomic swaps develops the concept further. It’s relatively easy to swap coins or custom tokens trustlessly across any Bitcoin-like blockchains. But beyond that, Ergo allows partial swaps. Just like on a regular exchange, orders can be partially filled, if that’s what the trader wants.

This means it’s possible to build a fully-fledged decentralised exchange (DEX) that enables cross-chain trading: a totally trustless version of existing crypto exchanges. There’s no need for any gateways, token wrapping or other potential bottlenecks or points of failure.

You can find out more about Ergo’s implementation of atomic swaps and intra-chain and cross-chain token swaps in the ErgoScript white paper.

Share post

Ergo Infrastructure DAO: Decentralizzare la Spina Dorsale dell'Ecosistema Ergo

Ergo Infrastructure DAO: Decentralizzare la Spina Dorsale dell'Ecosistema Ergo

La missione di Ergo è sempre stata radicata nella decentralizzazione, non solo a livello di consenso, ma in tutto lo stack.

Ergo Platform

13 agosto 2025

Mew Finance: Un Toolkit DeFi Giocoso per l'Ecosistema Ergo

Mew Finance: Un Toolkit DeFi Giocoso per l'Ecosistema Ergo

Mew Finance è una suite di applicazioni decentralizzate sulla Blockchain Ergo.

Ergo Platform

12 agosto 2025

Lithos: Decentralizzare il Mining con Pool On-Chain

Lithos: Decentralizzare il Mining con Pool On-Chain

Lithos è un nuovo protocollo progettato per ristrutturare il funzionamento delle pool di mining spostandole on-chain, dando ai min.

Ergo Platform

24 luglio 2025

Sigma 6.0: Un Ergo più Intelligente e Flessibile

Sigma 6.0: Un Ergo più Intelligente e Flessibile

Sigma 6.0 è un importante aggiornamento proposto per la blockchain Ergo.

Ergo Platform

23 luglio 2025

Plasmare il Futuro di Rosen: Una Chiamata della Comunità su Cinque Proposte Chiave del Tesoro

Plasmare il Futuro di Rosen: Una Chiamata della Comunità su Cinque Proposte Chiave del Tesoro

Il co-fondatore di Rosen, Armeanio, ha presentato cinque nuove proposte al Tesoro di Rosen.

Ergo Platform

9 luglio 2025

L'Extended UTXO di Ergo e l'Ascesa dell'Intelligenza Economica Artificiale

L'Extended UTXO di Ergo e l'Ascesa dell'Intelligenza Economica Artificiale

Una Visione Pratica per Agenti Economici Autonomi Gli agenti economici autonomi sulla blockchain di Ergo svolgono un lavoro utile.

Ergo Platform

12 maggio 2025

ErgoHACK X: Intelligenza Artificiale sulla Blockchain di Ergo

ErgoHACK X: Intelligenza Artificiale sulla Blockchain di Ergo

Celebrare un Decennio di Innovazione Decentralizzata Unisciti al decimo anniversario di ErgoHACK e sii in prima linea nella rivolu.

Ergo Platform

10 aprile 2025

I partecipanti all'Hackaton V: mining and minting

I partecipanti all'Hackaton V: mining and minting

La registrazione per "ErgoHack V: Mining and Minting" è ufficialmente chiusa ed è tempo di esplorare ciò che i partecipanti hanno .

Ergo Platform

11 ottobre 2022

EIP37 Hardfork

EIP37 Hardfork

Dopo il merge di Ethereum, l'industria del mining di criptovalute ha assistito a un impressionante riorientamento del potere di ha.

Ergo Platform

3 ottobre 2022

ErgoHack V: incontra i nostri giudici

ErgoHack V: incontra i nostri giudici

Con le iscrizioni ora aperte, ErgoHack V si sta avvicinando rapidamente.

Ergo Platform

25 settembre 2022

Ergo: Dopo il merge di Ethereum

Ergo: Dopo il merge di Ethereum

Una discussione per la comunità mineraria Sono state un paio di settimane vorticose per l'industria del mining di criptovalute.

Ergo Platform

25 settembre 2022

La tabella di marcia di Ergo: cosa succederà. Parte 1

La tabella di marcia di Ergo: cosa succederà. Parte 1

Dal lancio sulla rete principale di Ergo il 1 luglio 2019, la blockchain ha raggiunto molti traguardi importanti.

Ergo Platform

24 settembre 2022

I premi di ErgoHack V

I premi di ErgoHack V

Con la fusione di Ethereum, stiamo assistendo a un cambiamento sismico nel panorama degli hashrate per le blockchain Proof of Work.

Ergo platform

18 settembre 2022

EIP-0028 di Ergo: ErgoAuth

EIP-0028 di Ergo: ErgoAuth

Quando si parla di blockchain, è importante ricordare che i wallet sono completamente anonimi.

Ergoplatform

4 settembre 2022

The Ergo Manifesto

The Ergo Manifesto

Il Manifesto Ergo desidera educare e offrire una panoramica di ciò che la tecnologia blockchain può raggiungere.

Ergo Foundation

3 settembre 2022

Ergo e il meccanismo di consenso di Autolykos: parte I

Ergo e il meccanismo di consenso di Autolykos: parte I

Quello che segue è un'analisi tecnica approfondita del meccanismo di consenso di Ergo, Autolykos.

Ergo Platform

28 agosto 2022

Ergo e il meccanismo di consenso di Autolykos: parte II

Ergo e il meccanismo di consenso di Autolykos: parte II

La scorsa settimana abbiamo introdotto un'analisi approfondita del meccanismo di consenso Autolykos di Ergo.

Ergo Platform

28 agosto 2022

Come acquistare Ergo da Kucoin

Come acquistare Ergo da Kucoin

Tutti gli aspetti di questo articolo non sono consigli finanziari. Ricontrolla tutte le informazioni fornite da altre fonti.

Ergoplatform

7 agosto 2022

Ethereum Mining Community e GPU Miners: il caso di Ergo dopo la fusione

Ethereum Mining Community e GPU Miners: il caso di Ergo dopo la fusione

Un cambiamento epocale in arrivo nel campo delle blockchain minabili Il panorama del mining di criptovalute Proof of Work sta per.

Ergoplatform

7 agosto 2022

Ergo: una risposta ai fallimenti della teoria monetaria moderna

Ergo: una risposta ai fallimenti della teoria monetaria moderna

Nel 2008, un gruppo o una persona sconosciuta ha rilasciato una riserva di valore peer-to-peer e l’ha chiamata Bitcoin.

Ergo platform

9 febbraio 2022

E' nata Ergoitaly.it

E' nata Ergoitaly.it

La prima community ufficiale Ergo in Italia Ergo è nato l'8 aprile 2019. Alle 20:41.

ErGonario

27 gennaio 2022