Skip to main content
Version: 1.0

Introduction

Easily embed crypto trading in your app with Swap API

tip

Prefer to watch a video or see a code demo instead? Jump to 0x Videos or 0x Code Examples.

What is Swap API?

Swap API is a professional-grade DEX aggregation and smart order routing REST API that allows you to find the best price and easily submit the trade with just a few lines of code.

Swap API allows you to add crypto trading in your application with just a single API integration. It finds the best real-time price across 100+ liquidity sources, both public (AMMs) and private (professional market makers), across 9 different chains

Swap API UI

tip

Want to build a gasless trading app? Check out Gasless API instead.

Why use Swap API?

Swap API watches out for your users, is easy for your developers, and your team can earn fee revenue!

  • ⛓️ Easily access multi-chain liquidity on the most popular networks
  • 🤑 Earn revenue fees through your app's swap integration
  • 🛡️ Built-in user-protection features, including Price Impact Protection which protects users from getting rekt by illiquid markets
  • ↩ Best execution with the lowest reverts
  • 💰 Exclusive built-in RFQ liquidity which is competitive with AMMs and comes with the added benefit of zero slippage and guaranteed MEV protection
  • 🚀 It is easy-to-use! For example, you can easily find the best price to buy DAI with WETH with the following request:

Try it out

tip

👉 Run this curl request to see a live quote response for selling ETH -> DAI, excluding Kyber as a source:

// Replace API key in the header with your own key from https://dashboard.0x.org/
// Using vitalik.eth as takerAddress
curl https://api.0x.org/swap/v1/quote?buyToken=0x6B175474E89094C44Da98b954EedeAC495271d0F&sellToken=0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE&sellAmount=100000&excludedSources=Kyber&takerAddress=0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045 --header '0x-api-key: REPLACE_WITH_API_KEY'


You will receive a response that looks like this:
{
"chainId": 1,
"price": "1969.101",
"guaranteedPrice": "1949.40999",
"estimatedPriceImpact": "0",
"to": "0xdef1c0ded9bec7f1a1670819833240f027b25eff",
"data": "0xd9627...
...
}

This is a valid unsigned Ethereum transaction that can be signed and submitted directly to a node to complete the swap. Read more about the parameters here.


How does it work?

Swap API is a professional-grade DEX aggregation and smart order routing API. Using the API, developers can easily and reliably tap into aggregated multi-chain DEX liquidity. Swap API finds the best executed price across 70+ liquidity sources, both public (AMMs) and private (professional market makers), across a growing number of blockchains

Below is a high-level diagram showing how Swap API works under the hood:

Swap API Diagram

  1. Retail Trader Requests a quote
  2. Swap API simultaneously (a) retrieves quote from AMM and (b) requests quotes from Market Makers
  3. Market Makers responds with signed quote at their discretion
  4. Swap API aggregates the quotes it has received and compares the prices, taking into account price impact. It returns the best price to the Retail Trader.
  5. If the Retail Trader likes the quote, the Retail Trader signs the order. Swap API sends the signed order to the blockchain to be settled by the 0x Protocol.

For more details about how 0x orders are executed, check out How does 0x work?

Under the hood, Swap API performs a series of tasks:

  • Queries prices from multiple DEXs and market makers and aggregates the liquidity from the queried sources to provide the best price possible. Think of how Google flights aggregates flight prices for a certain time and date to help you find the best price, /swap similarly helps you find the best price across DeFi liquidity sources.
  • Swap API’s smart order routing algorithm splits up your transaction across different sources to maximize the overall return on your swap. Read more about smart order routing here.
  • Swap API's Price Impact Protection calculates price impact estimates, and allows developers to easily notify users if insufficient liquidity may negatively affect the price.
  • The response returned by Swap API is a valid unsigned Ethereum transaction that can be signed and submitted directly to an Ethereum node. Easily execute using the transaction using the web3 library of your choice.

Supported Networks

Read more about using the Swap API.

Get Started

info

To create an account, and get your live API keys to access 0x APIs, visit the 0x Dashboard.

Now that you're familiar with what Swap API offers, read How to Use Swap API to get started or choose one of the resources below.

Code Examples

Guides

API References

Advanced Topics

API FAQs