Skip to main content

Introduction

tip

Prefer to watch a video instead? Jump to 0x Concept Videos.

What is Swap API?​

Swap API is a professional-grade DEX aggregation and smart order routing REST API that runs on HTTP. Using the API, developers can easily and reliably tap into aggregated multi-chain DEX liquidity.

Swap API UI/UX

Power crypto trading in your application with a single API integration that unlocks thousands of tokens. 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.

Why use Swap API?​

Swap API watches out for your users and is easy for developers.

  • By default, it has built-in user-protection features, including:
  • Best execution with the lowest reverts
  • Exclusive built-in RFQ liquidity which is competetive with AMMs and comes with the added benefit of zero slippage and guarnteed MEV protection
  • It is easy-to-use! For example, you can easily find the best price to buy DAI with WETH with this request
tip

Try it out

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


// Replace API key in the header with your own key from https://dashboard.0x.org/
curl --location --request GET 'https://api.0x.org/swap/v1/quote?buyToken=DAI&sellToken=ETH&sellAmount=100000&excludedSources=Kyber' --header '0x-api-key: 35aa607c-1e98-4404-ad87-4bed10a538ae'

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 submitted directly to a node to complete the swap. Read more about the parameters here.


Note: This request uses a test API key that should not be used in production. Create an account and get your live API keys to access the Swap API from 0x Dashboard.

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

Swap API Diagram

Under the hood, the 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 Slippage Protection enables developers to surface more reliable quotes and consistently deliver the best executed price to users.
  • 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.
  • 0x API's responses are returned in a format that can be easily executed using the Web3 library of your choice.

Get Started​

info

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

This section contains the following docs and guides

Guides​

API References​

Advanced Topics​

API FAQs