Introduction
The 0x Protocol is a system of smart contracts that live on respective blockchains. It facilitates trust-less, low friction exchange of assets. While the protocol is open source and accessible by anyone, 0x Labs built the 0x API as an additional off-chain layer to facilitate smooth interaction between applications and the 0x protocol smart contracts.
Used together, the 0x protocol and 0x API offer traders the opportunity to retain custody of their assets until their trades are settled. Conversely, one of the main disadvantages of trading on a centralized exchange (“CEX”) is that the CEX has full custody over your funds: you deposit your assets into a respective blockchain address controlled by the CEX, and must trust the CEX to secure your assets from hackers, rogue employees and other attackers. When trading with 0x, your assets never leave your own blockchain address until a trade is settled.
The 0x protocol currently serves two different kinds of orders: 0x Limit Orders and 0x RFQ Orders. This article focuses primarily on 0x Limit Orders, but both orders are essentially data packets that contain the order's details and at least one valid signature (e.g. a valid elliptic curve signature generated from the trader’s blockchain address). When two entities agree on the terms of a trade, the 0x order is submitted to the respective blockchain and settled via the 0x protocol smart contracts.
In order for the 0x smart contracts to move funds on the behalf of traders, the traders must first give the contracts explicit permission. This is done by setting an "allowance" for a certain number of assets the 0x protocol can transfer from the traders’ addresses, and then cryptographically agreeing to the terms of the trade by applying a valid signature to the order. These rules are all enforced by the 0x protocol’s open-source smart contracts, which are deployed to the respective blockchain. Read more about setting allowances here: How to Set Your Token Allowances.
Applications Supporting 0x Limit Orders​
0x Limit Orders are created off-chain and are completely free to create. Here are a few applications from the 0x ecosystem where you can trade with 0x Limit Orders:
0x API​
You can also trade with 0x Limit orders using the 0x API. 0x Limit Orders are supported on multiple blockchains, including:
- Ethereum
- Binance Smart Chain
- Polygon
Code Examples​
0x Starter Project includes with a number of scenarios using the 0x v4 protocol that can be run from the command-line: