Atomic swaps: Truly trustless transactions
1月 16, 2020
- Atomic swaps enable verifiable digital assets to be exchanged in a completely trustless environment
- Smart contracts verify the terms of a proposed transaction
- Learn more by trying our new demo
In an earlier series of blog posts we examined how Fetch.ai Autonomous Economic Agents (AEAs), or agents for short, negotiate and trade with one another. We used the example of data being shared between a weather station and an individual to show how knowledge is traded and the importance of trust ratings for agents.
In an ideal world, agents conducting economic transactions would be able to complete transactions without needing to trust the other parties involved. At Fetch.ai we are developing a decentralized network that creates this ideal environment. The platform’s digital infrastructure is optimized for agents, rather than humans, and operates using an entirely different set of rules from those we are accustomed to in the physical world. This enables verifiable digital assets to be exchanged in a completely trustless environment. Such transactions are called atomic swaps.
To explain how these swaps work, let’s begin with a real world example. Let’s say I want to exchange five apples with Suzy, who has three oranges. By meeting together and putting our fruit on the table, we can inspect the goods and see exactly what the other person is willing to exchange. If we are happy with what is proposed, Suzy and I will exchange fruit. If we are not happy, we both leave the negotiation, each taking away the fruit we brought with us. We will both walk away with either a successful trade — a completed transaction — or no trade at all. The transaction is therefore ‘atomic’. Assuming neither party forcefully takes the other’s fruit, the risk that either Suzy or I end up with all of the fruit is essentially zero.
In the digital world, it simply isn’t possible for individuals to be physically present at the point of transaction. It would also not be desirable, as it would limit agents’ autonomy. Instead, smart contracts can help us verify the terms of transactions and ensure that a transaction either succeeds completely or not at all. This enables atomic swaps to take place.
Recalling our real world example, the smart contract verifies the negotiated terms on behalf of Suzy and myself. For instance, the smart contract can check that the negotiated trade terms have not been altered since they were agreed. This ensures that neither Suzy nor I have amended the terms, without the knowledge of the other person, so as to include an extra apple or orange. The smart contract would also check that the signatures on the contract match those of Suzy and myself. If all the details appear exactly as they should, and are verified by the immutable records of the blockchain (meaning Suzy and I have the relevant fruit), then the transaction will complete successfully and I will receive three oranges and Suzy will receive five apples. If for any reason the details do not match, the transaction will fail and nothing will be exchanged.
Of course, apples and oranges aren’t verifiable digital assets — they are real, living things. The smart contract could verify all of the terms mentioned above, but if I receive three moldy oranges from Suzy in exchange for the five ripe apples I have given her, I’m going to feel shortchanged. The same problem occurs regarding the weather data we discussed at the start of this article. The smart contract will be able to verify the agreed terms, but it wouldn’t be able to verify the quality (i.e. the accuracy or relevancy) of the data sent across by the weather station upon completion of the trade. For this reason, atomic swaps can only take place for verifiable digital assets such as the exchange of tokens.
There are two types of token: fungible and non-fungible. Both tokens can be digitally verified and therefore exchanged on the Fetch.ai network using atomic swaps. For example, if I want to trade 10 FET (fungible) tokens for 1 CryptoKitty (non-fungible) token, as long as the trade terms are verified and the signatures match, the transaction will complete successfully.
The implementation of atomic swap transactions is incredibly exciting and the technology is starting to have a huge impact on sectors such as decentralized finance. You can find out more about our work enabling atomic swaps by checking out our new demo.
- Find out more about Fetch.ai’s Autonomous Economic Agents by visiting our developer website. Alternatively, read our 文档, which includes some innovative 演示.
- 加入我们的 Developer Slack Channel 探索我们不断增长的 GitHub资料库.
- Watch videos outlining our technology and follow our tutorials on Youtube.
- If you’re not a developer, you can stay up to date with our progress by joining us on 电报群 or by following us on 推特.