0x 101: Intro to 0x Orders

Take a look under the hood to see how a transaction is executed through 0x Protocol.

May 4, 2023

Learn & Build

0x Protocol is the trusted open source protocol for the settlement of decentralized exchange of tokenized value. It is the foundational settlement layer of the 0x infrastructure tech stack and a core Web3 building block. 0x Protocol reliably executes orders created by off-chain services such as 0x’s Swap API in a non-custodial manner.

In this article, we take a look under the hood to see how a transaction is executed through 0x Protocol.

Makers, Takers, and 0x Orders

For any given trade, there are two actors participating in the transaction: the “Maker”, short for market maker, and the “Taker”, the actor who wants to take the order the Maker is making. A trade between these two parties happens via an order.

For a transaction to be executed through 0x Protocol, a 0x order is required. A 0x order is a message passed through 0x Protocol to facilitate the trade of an ERC20 token for an ERC20, ERC721, or ERC1155 token. 

What exactly is an order? An order is a packet of data that contains the order’s details, such as what assets are being traded, the Maker’s and Taker’s addresses, and at least one valid signature. When two entities agree on the terms of a trade, the 0x order is submitted to the respective blockchain and settled via 0x Protocol smart contracts

The 0x Protocol supports different order types, including Limit Orders, whose structure is shown below:

0x order types

There are currently three types of orders in 0x Protocol: 

  • Limit Orders: These are standard 0x orders, which encode a possible trade between a Maker and Taker at a fixed price, and are primarily used for off-chain orderbook liquidity. Limit Orders facilitate ERC20 to ERC20 trades. (Note: A limit order in this context is not the same as a limit order in traditional finance)
  • RFQ Orders: These are a stripped down version of standard Limit Orders that support the settlement of off-chain liquidity sourced from professional market makers via the 0x Request-for-Quote (RFQ) System. These orders are fielded just-in-time, directly from market makers. RFQ orders facilitate ERC20 to ERC20 trades.
  • NFT Orders: NFT orders in 0x Protocol are optimized for swapping ERC20 tokens for either ERC721 or ERC1155 tokens.

How does a 0x trade work? 

Let’s take a look at the illustration below to see how a 0x order works. This flow applies to ERC20 to ERC20 trades and ERC20 to NFT trades.

  1. A Maker creates a 0x order, which is a json object that adheres to a standard order message format. This order indicates what kind of asset the Maker is looking to trade, such as ERC20, 721, or 1155.
  2. The order is hashed and the Maker signs the order to cryptographically commit to the order they authored.
  3. 0x Swap API aggregates liquidity across all available sources to surface the best price to the Taker.
  4. The Taker fills the 0x order by submitting the order and the amount they will fill it for to the blockchain.
  5. 0x Protocol smart contracts contain settlement logic to verify the Maker’s digital signature and that all the conditions of the trade are satisfied. If so, the given assets are atomically swapped between Maker and Taker. If not, the trade is reverted.

Unlike other decentralized exchanges that function entirely on-chain, 0x does not store orders on the blockchain; instead, orders are stored off-chain and only trade settlement occurs on-chain. This unique feature of off-chain relay, on-chain settlement makes 0x highly flexible and gas-efficient because only settlement information needs to be stored on-chain.

Get started building with 0x

In this article, we discussed the structure of 0x Orders, how they encode trade details between a Maker and Taker, and how orders are shared and swapped via the “off-chain relay, on-chain settlement” paradigm. 

0x offers a suite of fully integrated APIs to help you easily tap into this trading liquidity. Check out our guide below to learn how to get started building with Swap API:

Contents

Subscribe to newsletter

By submitting you're confirming that you agree with our Terms and Conditions.
Yay! You’re signed up.
Oops! Something went wrong, but it's not your fault.

Up next

Compliance made easy with 0x Address Screening

Sep 26, 2024

0x's next-gen pricing engine is now live

Sep 25, 2024

Introducing state-of-the-art Buy/Sell Tax support

Sep 4, 2024

Take control of your balance sheet with 0x v2

Aug 15, 2024

0x v2 bug bounty program

Jul 30, 2024

What does the "best price" in DeFi really mean?

Jul 23, 2024

Eliminate allowance risk with Permit2

Jul 17, 2024

Introducing 0x's next-gen pricing engine

Jul 15, 2024

0x Dev Digest: May 2024

May 31, 2024

Frame spotlight: Paycaster

May 21, 2024

Frame spotlight: Airstack

May 9, 2024

Power up your Farcaster Frames with 0x swaps

May 2, 2024

0x Dev Digest: April 2024

Apr 30, 2024

Introducing 0x Trade Analytics

Mar 12, 2024

Coinbase Case Study

Jan 30, 2024

Introducing gasless swaps and approvals with Gasless API

Jan 22, 2024

Bitcoin ETFs have arrived

Jan 12, 2024

Building in the open: 0x pricing update

Dec 11, 2023

Matcha leverages Gasless API to bring users the most frictionless trading experience in DeFi

Nov 30, 2023

0x Dev Digest: October 2023

Nov 2, 2023

Monetize crypto trading in your app with Swap API

Oct 26, 2023

0x Dev Digest: September 2023

Oct 3, 2023

A comprehensive analysis of RFQ performance

Sep 26, 2023

Unlock optimal trades in Swap API with 0x RFQ liquidity

Sep 20, 2023

0x Dev Digest: August 2023

Aug 31, 2023

Portal launches swaps in its white label MPC wallet powered by 0x

Aug 16, 2023

0x Swap API is now live on Base

Aug 9, 2023

Introducing paid plans for Swap API

Jul 24, 2023

Decreasing Frictions in DeFi hackathon recap

Jul 12, 2023

0x's pricing principles

Jul 3, 2023

0x Dev Digest: June 2023

Jun 30, 2023

App spotlight: tastycrypto

Jun 27, 2023

App spotlight: 31Third

Jun 22, 2023

0x 101: Intro to gasless API

Jun 13, 2023

Inspiration for building with Swap API

Jun 8, 2023

0x Dev Digest: May 2023

May 31, 2023

Fundamentals: What are gas fees?

May 25, 2023

Decreasing Frictions in DeFi Hackathon

May 12, 2023

Swap API liquidity management

May 18, 2023

0x 101: Getting started with Swap API

May 16, 2023

0x 101: Intro to Swap API

May 9, 2023

0x 101: Intro to 0x Protocol

Apr 27, 2023

A new home for 0x Protocol

Apr 24, 2023

Say hi to the new 0x

Apr 20, 2023

0x Year in Review 2022

Jan 5, 2023

0x Swap API expands to Arbitrum

Sep 22, 2022

Managed liquidity

Apr 23, 2020

0x Smart Order Routing

May 19, 2020

App spotlight: Taho

Mar 8, 2022

Fundamentals: What is a Layer 2 chain?

Apr 19, 2023

Fundamentals: What is the difference between quoted, executed, and adjusted prices?

Apr 19, 2023

Fundamentals: What is price impact?

Apr 19, 2023

Fundamentals: What is slippage?

Apr 19, 2023

Fundamentals: What is an automated market maker (AMM)?

Apr 19, 2023

Fundamentals: What is market making?

Apr 19, 2023

Fundamentals: What is a DEX aggregator?

Apr 19, 2023

Fundamentals: What is liquidity?

Apr 19, 2023

Fundamentals: What is a decentralized exchange (DEX)?

Apr 19, 2023

0x at ETHDenver 2023

Mar 21, 2023

The 0x Mission and Values

Jun 7, 2018

Announcing support for new testnets

Aug 10, 2022

0x Swap API expands to Binance Smart Chain

Mar 17, 2021

Scaling DeFi — Layer One

Sep 1, 2021

Introducing Slippage Protection

Jul 14, 2022

San Francisco Blockchain Week 2022 Recap

Nov 21, 2022

0x Swap API adds new liquidity sources

Jul 11, 2022

Review of slippage performance

Sep 14, 2022

Phuture case study

Oct 20, 2022

Measuring the impact of hidden DEX costs

Apr 14, 2022

Market making in DeFi

Aug 12, 2021

Introducing 0x Labs

Jun 22, 2020

Introducing 0x Explorer

Oct 26, 2022

Growing DeFi with professional market makers

Aug 26, 2020

0x 101: How to Access 0x Data

Apr 25, 2023

GameStop chooses 0x Swap API

Jul 8, 2022

Build on Base with 0x

Feb 23, 2023

A comprehensive analysis on DEX liquidity aggregators’ performance

Oct 1, 2020

Announcing 0x Swap API v1

Oct 1, 2020

Access all DEX liquidity through 0x Swap API

Jan 28, 2020

Announcing the 0xpo Summit 2022

Aug 24, 2022

0x Protocol, a preview of what’s to come

Mar 16, 2023

Update to our Privacy Policy

Mar 14, 2023

Price Impact Protection has arrived

Dec 14, 2022

0x Limit Orders Go Multi-Chain

Dec 23, 2021

0x Labs raises $70M Series B led by Greylock to continue expanding Web3’s core exchange infrastructure

Apr 26, 2022

0x launches Tx Relay API in beta, with Robinhood Wallet as first partner

Mar 1, 2023

0x Labs raises $15M Series A to bring decentralized exchange markets to a global audience

Feb 5, 2021

App spotlight: Zerion

Jun 22, 2022

App spotlight: Matcha

Nov 24, 2021

App spotlight: DexGuru

Jun 17, 2021

App spotlight: DEXTools

Sep 23, 2021

App spotlight: DODO

Aug 10, 2021

App spotlight: DappRadar

Dec 16, 2021

App spotlight: DeFi Saver

Jul 20, 2021

0x + Brave partner to make crypto and DeFi more accessible to everyone

Jul 7, 2021

0x Swap API now supports 0x Protocol v4

Mar 1, 2021

0x Swap API is now available on Fantom

Oct 26, 2021

0x Swap API is now live on Optimism

Jan 11, 2022

0x Swap API is now available on Polygon

May 31, 2021

0x Swap API is now available on Celo

Nov 18, 2022