Token Swap - Blockchain Patterns (2024)

Disclaimer: This is a summary of patterns we have observed during our research and should not be considered any form of technical or investment advice. Also, the given “known examples” do not imply they are the best implementations of the said pattern or any superior to any other implementation of the pattern not listed.

Summary

Token swap allows users to trade directly between two types of tokens as an atomic transaction.

Context

A blockchain-based payment application supports different types of tokens, e.g., different asset classes.

Problem

How can users buy and sell tokens for other types of tokens without the risk of other-party not transferring their tokens?

Forces

  • Liquidity – Users need to convert tokens to other types of tokens.
  • Atomicity – The exchange of tokens should be atomic based on a rate/amount agreed by both parties of the transaction.
  • Trust – It is hard for the parties involved in a transaction to trust each other completely.

Solution

By making the token swap atomic, we can ensure both parties will either receive the respective tokens or none of the tokens. A token swap is an agreement between two parties that exchange different token types (say token 𝐴 and token 𝐵). In a token swap, one party will pay a certain amount of token 𝐴 to the other party and receive the agreed amount of token 𝐵 in return. The token swap process is usually managed using a Hashed Timelock Contract (HTLC) deployed on the blockchain. Multiple HTLCs are used to swap tokens in payment channels and across blockchains with the help of an application-layer integrator.

The followingng figure illustrates the steps involved in atomically swapping two tokens using a HTLC. First, a HTLC smart contract is deployed by one of the parties on-chain. HTLC specifies a hash generated from an off-chain secret and a timeout specified as a block number. Second, each party transfers the agreed amount of tokens to the HTLC. For example, party 1 transfers token 𝐴 while party 2 transfers token 𝐵. Next, to swap the tokens, the off-chain secret is sent to the HTLC using a transaction. Finally, if the revealed off-chain secret generates the same hash embedded in the HTLC, the contract exchanges tokens by transferstoken𝐴to party 2 and token 𝐵 to party 1. If the off-chain secret is not revealed before the timeout, tokens are sent back to their owners.

Token Swap - Blockchain Patterns (1)

Sequence diagram of token swap

In payment channels and inter-blockchain token swap, two or more intermediate HTLC contacts are deployed, forming a chain of HTLCs. While each HTLC specifies the same hash generated from the off-chain secret, timeout decreases as we move along the HTLC chain. Then the off-chain secret is revealed from the end of the HTLC chain, leading to a chain reaction that enables each HTLC to swap the tokens it holds. In practice, one HTLC does not automatically transfer the off-chain secret to the next HTLC on the chain. Instead, each party interested in receiving tokens locked by a particular HTLC continues to look for a transaction that reveals the off-chain secret. Once it is observed, the off-chain secret is extracted from the transaction and submitted in a new transaction to the respective HTLC to unlock the tokens. The off-chain secret must be revealed to a HTLC before its timeout.

Benefits

  • Liquidity – A user can use his/her tokens to buy other types of tokens, increasing liquidity.
  • Data Integrity – The data integrity of the swapped tokens can be ensured because the token swap process and respective transactions are stored on-chain.
  • Atomicity – Smart contracts guarantee the atomicity of token swap.
  • Cost – As smart contracts can manage the token swap process, no third party service fee is incurred, e.g., payment to an escrow.
  • Interoperability – Interoperability is increased through cross-chain token swap.

Drawbacks

  • Privacy – Token swap transactions are publicly visible.
  • Cost – There might be additional cost due to the exchanged rate. Also, if a public blockchain is used, there is a cost to deploy and use HTLC smart contract.
  • Lack of flexibility – If a party does not withdraw tokens out in time by submitting the off-chain secret, the deposited tokens will be locked in the HTLC or sent back to the payer.

Related patterns

  • When exchanging on-chain assets like tokens, this pattern could be used over the escrow pattern, as no external confirmation of delivery of assets is needed.
  • The token registry pattern can be used to send/receive tokens to/from HTLC.

Known uses

  • Metamask supports token swap feature to compare and swap tokens directly within the wallet and browsers.
  • Kaileido offers a simple process to swap tokens using HTLCs securely.
  • The Bitcoin Lightning Network supports multi-hop payment channels by linking existing payment channels through a chain of HTLCs. This enables parties to transact beyond their payment channel.
  • AirSwap supports atomic token swap with a guaranteed price. It also supports swap via Metamask wallet and custom swaps with parties trading tokens.
Token Swap - Blockchain Patterns (2024)

FAQs

Why can't I swap my tokens? ›

There are various reasons why the “Unable to swap these tokens” error may appear. The most common one is related to liquidity constraints when swapping two (or even one) long tail assets.

How long does a token swap take? ›

A swap usually takes anywhere from 5 to 30 minutes but could take longer, depending on the asset pair and market conditions.

What are the benefits of token swap? ›

Diverse Opportunities: By enabling easy access to a wide range of tokens, swapping opens the door to participating in new DeFi projects, yield farming, liquidity provision, and more. It empowers users to quickly adapt their strategies and take advantage of emerging opportunities.

What is swapping tokens? ›

A token swap is an agreement between two parties that exchange different token types (say token 𝐴 and token 𝐵). In a token swap, one party will pay a certain amount of token 𝐴 to the other party and receive the agreed amount of token 𝐵 in return.

Why do swaps fail on MetaMask? ›

MetaMask does its best to optimize each transaction before the swap is submitted. However, just like any on-chain transaction, transaction success is not guaranteed. The main reason why your swap might have failed is likely to be slippage. When you perform a swap, you are agreeing to a price quote.

How much does it cost to swap tokens? ›

There is a 0.3% fee for swapping tokens. This fee is split by liquidity providers proportional to their contribution to liquidity reserves.

Why is my swap taking so long? ›

Many factors can impact the delay, such as the network congestion on both networks of the swap, then the delay of the swap provider in processing the incoming and outgoing requests, and issues during KYC (Know-Your-Customer) verification.

What is the fastest way to swap crypto? ›

How to swap cryptocurrency fast?
  1. Choose the crypto pair for exchange. We will take care of the rest and find the deals available. Choose the offer you like best.
  2. Enter the amount of crypto needed and send the deposit in.
  3. Wait for the confirmation.
  4. Receive the exchanged amount of cryptocurrency.

Can I make profit by swapping crypto? ›

Arbitrage trading involves exploiting the price differences in the same cryptocurrency across different exchanges. By leveraging cryptocurrency swaps, one can capitalize on these price differentials to buy low on one exchange and sell high on another, thereby pocketing profit in the process.

Where to swap tokens? ›

Swap tokens directly from the MetaMask browser extension, mobile wallet, and MetaMask Portfolio. The Swaps feature combines data from decentralized exchange aggregators, market makers, and DEXs, to ensure you get competitive quotes with the lowest network fees.

Is swapping crypto worth it? ›

Swaps are much more cost-effective, often faster and support cross-chain crypto exchanges. Swaps are also great solutions for purchasing lesser-known crypto projects that could explode in valuation. Despite their plentiful benefits, swaps have downsides, including security, counterparty and slippage risks.

What is the coin swap process? ›

With this, users can exchange a crypto asset for another directly. All you need to do is enter the amount you want to exchange and your desired trading pair and the token swap service would instantly process and convert your coin. With this form of transacting, you only have to pay transaction fees once.

Can you swap tokens between networks? ›

A cross chain swap is a specialized form of token swapping that involves exchanging tokens from one blockchain network to another. This process is vital for enhancing interoperability in the decentralized ecosystem, allowing different blockchains to interact and share value seamlessly.

How many swap tokens are out? ›

Finding all the Swaps Tokens can be tricky, especially when they are in sneaky places not many people visit, but the graphic below shows you exactly where to find each of the 30 Tokens, including any bonus Store Tokens, and when the Tokens expire.

What is the best crypto swap? ›

What is Crypto Swapping?
CompanySupported cryptoPayment methods
1. Change NowRead More700+Apple Pay, Card payment, SEPA, Union Pay
2. EasyBit Read More200+Wire transfer, Credit card payments
3. Changelly Read More500+Apple Pay, Google Pay, Card payment
4. CoinStats Read More20,000+Card payments
4 more rows
Jul 25, 2024

Why can't i swap tokens in MetaMask? ›

If you are on a network on which Swaps is available, but are unable to click the Swap button, try restarting your browser, or try a different network connection entirely. Sometimes toggling networks (switch from one network back to the network you were using) helps.

Why can't i swap tokens on Uniswap? ›

Your swap on Uniswap might be failing for a variety of reasons. Here's the most common issues and how to fix them: Your max slippage settings are too low: Adjust the setting to allow for higher slippage. The transaction is timing out: Pay a higher network fee or set a longer transaction deadline in the settings.

Why can't I swap on Coinbase? ›

A swap can fail because of a sudden shift in the exchange price between the cryptocurrencies you're trying to swap. We recommend waiting at least 60 seconds before retrying the transaction.

Why are my tokens not working? ›

Replace your batteries with new ones

If your CIU meter is not connecting, you should check the batteries. Ensure they are properly inserted and not drained. If they are drained, replace or recharge them to ensure a successful connection.

Top Articles
Co-op Group to lose control of Co-op Bank
How to Live on One Low Income So You Can Be A Stay-at-Home Mom - Very Anxious Mommy
This website is unavailable in your location. – WSB-TV Channel 2 - Atlanta
Matgyn
فیلم رهگیر دوبله فارسی بدون سانسور نماشا
The 10 Best Restaurants In Freiburg Germany
Optimal Perks Rs3
J Prince Steps Over Takeoff
Chase Claypool Pfr
Crime Scene Photos West Memphis Three
Jesus Revolution Showtimes Near Chisholm Trail 8
Premier Boating Center Conroe
Sitcoms Online Message Board
Unit 1 Lesson 5 Practice Problems Answer Key
Troy Athens Cheer Weebly
Bowie Tx Craigslist
10-Day Weather Forecast for Florence, AL - The Weather Channel | weather.com
Espn Horse Racing Results
Metro Pcs.near Me
Our History
20 Different Cat Sounds and What They Mean
Halo Worth Animal Jam
Hyvee Workday
Www.craigslist.com Savannah Ga
Www Pointclickcare Cna Login
Suspiciouswetspot
Labcorp.leavepro.com
When His Eyes Opened Chapter 3123
Cosas Aesthetic Para Decorar Tu Cuarto Para Imprimir
Penn State Service Management
Alternatieven - Acteamo - WebCatalog
031515 828
5 Star Rated Nail Salons Near Me
Otis Inmate Locator
Craigs List Tallahassee
Warn Notice Va
Worlds Hardest Game Tyrone
Mississippi State baseball vs Virginia score, highlights: Bulldogs crumble in the ninth, season ends in NCAA regional
Chatropolis Call Me
8 Ball Pool Unblocked Cool Math Games
2020 Can-Am DS 90 X Vs 2020 Honda TRX90X: By the Numbers
Firestone Batteries Prices
At Home Hourly Pay
Craigslist Food And Beverage Jobs Chicago
Matt Brickman Wikipedia
Chr Pop Pulse
The Cutest Photos of Enrique Iglesias and Anna Kournikova with Their Three Kids
Graduation Requirements
303-615-0055
Craigslist Sparta Nj
Lesson 5 Homework 4.5 Answer Key
The Plug Las Vegas Dispensary
Latest Posts
Article information

Author: Lilliana Bartoletti

Last Updated:

Views: 6192

Rating: 4.2 / 5 (73 voted)

Reviews: 88% of readers found this page helpful

Author information

Name: Lilliana Bartoletti

Birthday: 1999-11-18

Address: 58866 Tricia Spurs, North Melvinberg, HI 91346-3774

Phone: +50616620367928

Job: Real-Estate Liaison

Hobby: Graffiti, Astronomy, Handball, Magic, Origami, Fashion, Foreign language learning

Introduction: My name is Lilliana Bartoletti, I am a adventurous, pleasant, shiny, beautiful, handsome, zealous, tasty person who loves writing and wants to share my knowledge and understanding with you.