0x 101: Intro to Swap API
With Swap API, you can easily power crypto trading in your application with a single integration that unlocks thousands of tokens. In this guide, we''ll take a deeper look at what Swap API is and how you can leverage it to access deep liquidity without the infrastructure overhead.
Swap API is your gateway to unrivaled liquidity. With Swap API, you can easily power crypto trading in your application with a single integration that unlocks thousands of tokens.
In this guide, we''ll take a deeper look at what Swap API is and how you can leverage it to access deep liquidity without the infrastructure overhead.
What is Swap API?
Building in Web3 has become increasingly difficult as the number of ecosystems, DEX protocols, and tokens has grown. And in DeFi, liquidity is fragmented across dozens of sources, making it difficult for users to find the best prices.
Swap API solves this by fetching available quotes from across the liquidity supply to help users quickly find the best price for a given trade. It aggregates liquidity from 100+ exchanges, including the most popular AMMs and private market makers, across the most popular chains - allowing you to easily tap into the deepest liquidity with one simple integration.
Swap API is a REST API that runs on HTTP. We built Swap API to make it easy for developers to leverage the underlying trade settlement of 0x Protocol, a set of smart contracts that make up the base layer of the 0x tech stack, and integrate swap functionality into their apps.
How does Swap API work?
Think of how Google Flights aggregates flight prices for a certain route and time to help you find the best price.
Under the hood, Swap API works similarly by querying prices from dozens of decentralized exchanges (DEXes), such as Uniswap, Aave, and Sushiwap, and professional market makers across the most popular blockchains, including Ethereum, Polygon, and Arbitrum, and aggregating the liquidity from the queried sources to help users quickly find the best price for a given trade.
Swap API’s proprietary smart order routing algorithm then splits up a user’s transaction across different sources to maximize the overall return on the trade by analyzing gas costs, available liquidity, execution quality, and price impact in real-time.
For example, the best price to sell 1,500 DAI for ETH may be 50% through Bancor, 25% through Uniswap, and 25% through Sushiswap. Swap API’s smart order routing logic automatically calculates this and packages it into a single quote that’s ready to be executed using the Web3 library of your choice. Whether you prefer web3.js or ether.js, or something else, you are in control.
Why use Swap API?
Swap API provides access to deep liquidity without the infrastructure overhead.
Similar to managing nodes or other layers of infrastructure, managing liquidity sources is a vital piece of the infrastructure stack. Missteps in sourcing liquidity can result in poor experiences for users, including uncompetitive pricing, lack of token coverage, and increased slippage. With Swap API, we manage the overhead and allow you to focus on building what matters: your product.
Unlimited crypto assets: One integration with 0x unlocks thousands of tokens on the most popular blockchains and aggregated liquidity from 100+ AMMs and market makers.
Slippage and MEV protection: When trading on DEXes, slippage can cause the price to shift before the trade actually executes. Swap API is designed to minimize the impact of sandwich attacks and MEV. When Slippage Protection is enabled, users save an average of 50-80% on slippage.
Price Impact Protection: Similar to slippage, price impact can occur in between a trader placing a trade and its actual execution. Price Impact Protection is an optional feature that, when enabled, protects users from suffering significant losses by trading illiquid tokens.
Low revert rates: Despite the complexity of routing orders through multiple DEXes and market makers, Swap API’s robust infrastructure enables it to have a 4x lower revert rate than competitors.
Exclusive RFQ liquidity: We work with Professional Market Makers to provide exclusive RFQ liquidity. This liquidity is competitive with AMMs, and comes with additional benefits, including zero slippage and guaranteed MEV protection.
And best of all, it’s easy to use! With Swap API, you can enable crypto trading in your app with just a few lines of code. For example, you can easily find the best price to buy DAI with WETH with this simple request.
What can you build with Swap API?
Swap API is extremely versatile. It has become the go-to endpoint for DEX liquidity for leading teams across the Web3 ecosystem. Since launch, over $125 billion in tokenized value has been traded across 50 million transactions with Swap API. Here are some example use cases.
Centralized exchanges act as intermediaries between buyers and sellers, facilitating the trading of cryptocurrencies. Swap API can be integrated by centralized exchanges to expand the trading options available to users. Coinbase leverages Swap API to power DEX trading.
Fintechs can utilize Swap API to enable seamless cryptocurrency transactions for their users, expanding the offerings available within their platforms.
Self-custody wallets allow users to store, transfer, and swap tokens. Wallets can integrate Swap API in order to offer the ability to swap tokens at the best prices directly within the UI. Swaps in Metamask, Phantom, and Brave Wallet are all powered by 0x.
Decentralized exchanges allow users to exchange one cryptocurrency token for another without intermediaries. Leading DEXes, such as Matcha, Cowswap, and dYdX, use Swap API to access deep liquidity and get users the best price.
Portfolio management apps provide a convenient way to build and manage a portfolio of tokenized assets. These apps often offer additional features such as direct token swaps, automatic liquidation protection, liquidity mining, and yield farming. Top portfolio managers, including Zapper, Zerion, and DeFi Saver, rely on 0x.
DeFi investment apps offer their users various active and passive investment strategies, such as creating and trading baskets of assets, earning optimized lending yields, and social trading. Learn how Phuture utilizes Swap API to power all of its on-chain index funds and improve returns for users.
Ready to get started?
Check out our guide below to get started building with Swap API.