Overview

0x is an open-source, non-custodial protocol designed for the peer-to-peer exchange of digital assets on various blockchain networks. Launched in 2017, the protocol provides the fundamental infrastructure for developers to integrate decentralized exchange (DEX) functionality directly into their applications. This enables use cases such as token swaps, liquidity aggregation, and the creation of custom DeFi products without requiring users to relinquish control of their assets to a centralized entity.

The core of 0x's offering includes the 0x API, which aggregates liquidity from numerous DEXs and automated market makers (AMMs) across supported blockchains. This aggregation aims to provide users with optimal pricing and reduced slippage for trades. Developers can access this aggregated liquidity and trading functionality through a unified interface, simplifying the process of building Web3 applications that require token exchange. The protocol is also underpinned by 0x Smart Contracts, which manage the on-chain settlement of trades, ensuring security and transparency.

0x is suitable for developers and businesses looking to build or enhance applications within the decentralized finance (DeFi) ecosystem. This includes wallets, portfolio trackers, dApps, and other platforms that benefit from direct access to a broad spectrum of digital asset liquidity. For instance, a wallet application might use 0x to allow users to swap tokens directly within the wallet interface, while a DeFi lending platform could integrate 0x to facilitate collateral swaps. The protocol's modular design and comprehensive documentation, along with available TypeScript/JavaScript SDKs, aim to provide a streamlined developer experience for integrating decentralized exchange capabilities.

Key features

  • Liquidity Aggregation: Combines order books and liquidity pools from multiple decentralized exchanges, aiming to offer competitive pricing for token swaps.
  • Multi-chain Support: Operates across various blockchain networks, including Ethereum, Polygon, Avalanche, and others, to broaden asset access.
  • Customizable Swaps: Provides developers with granular control over swap parameters, such as gas limits, slippage tolerance, and transaction deadlines.
  • Developer-Friendly API: Offers a RESTful API designed to simplify integration of trading functionality into Web3 applications.
  • Smart Contract Foundation: Utilizes audited smart contracts for secure and transparent on-chain settlement of trades, emphasizing non-custodial asset management.
  • Gas Optimization: Implements mechanisms to optimize network transaction fees for users executing trades.

Pricing

As of May 2026, the 0x API is generally free for developers to access and integrate into their applications. The core revenue model for the protocol involves transaction fees, often referred to as taker fees, which are applied to trades executed through the 0x network. These fees are typically paid by the user initiating the trade (the 'taker') and can be paid in the swapped asset or the blockchain's native currency (e.g., ETH for Ethereum transactions).

0x API Pricing Overview (as of May 2026)
Service Component Cost Model Notes
0x API Access Free No direct API usage fees for developers.
Transaction Fees (Taker Fees) Variable, per trade Paid by the user executing the trade; often a small percentage of the swapped tokens or in native chain currency.
Network Gas Fees Variable, per transaction Standard blockchain transaction costs, paid by the user.

For detailed information on transaction costs and specific fee structures, refer to the 0x documentation.

Common integrations

  • Decentralized Wallets: Integration allows users to perform token swaps directly within their non-custodial wallets (e.g., MetaMask, Ledger Live).
  • DeFi Aggregators: Platforms that combine multiple DeFi protocols to offer users a single interface for various financial services can utilize 0x for liquidity.
  • DApp Development: Developers building decentralized applications that require token exchange functionality can embed 0x.
  • Web3 Gaming: Games incorporating tokenized items or in-game currencies can use 0x for marketplaces or trading features.
  • Portfolio Trackers: Applications that monitor and manage cryptocurrency portfolios can integrate 0x to enable rebalancing or asset swaps.

Alternatives

  • Uniswap: A leading decentralized exchange protocol primarily using Automated Market Maker (AMM) model for liquidity.
  • Pancakeswap: A popular decentralized exchange and DeFi platform built on the BNB Smart Chain.
  • 1inch Network: A DEX aggregator that sources liquidity from various exchanges to find optimal swap paths.

Getting started

To begin using the 0x API for token swaps, developers can leverage the provided TypeScript/JavaScript SDK. The following example demonstrates how to fetch a quote for a token swap and execute it.

First, install the 0x SDK:

npm install @0x/api-client @0x/asset-swapper ethers

Then, use the SDK to get a quote and, if desired, execute a swap. This example assumes you have an Ethereum provider (like MetaMask or ethers.js) configured.

import { BigNumber, Contract, providers, Wallet } from 'ethers';
import { RfqClient, RfqOrder, SignatureType } from '@0x/asset-swapper'; // simplified import for example

// NOTE: This is a simplified example. In a real application, you would manage keys securely
// and interact with a user's wallet provider (e.g., window.ethereum).
const PRIVATE_KEY = 'YOUR_PRIVATE_KEY'; // Replace with a secure key management strategy
const provider = new providers.JsonRpcProvider('https://mainnet.infura.io/v3/YOUR_INFURA_PROJECT_ID');
const wallet = new Wallet(PRIVATE_KEY, provider);

const ZERO_EX_API_URL = 'https://api.0x.org/swap/v1'; // Or your desired chain's API

async function getAndExecuteSwap() {
    const sellToken = 'WETH'; // Wrapped Ethereum
    const buyToken = 'DAI'; // DAI Stablecoin
    const sellAmount = '1000000000000000000'; // 1 WETH (in wei)

    try {
        // Step 1: Fetch a quote from the 0x API
        const response = await fetch(
            `${ZERO_EX_API_URL}/quote?sellToken=${sellToken}&buyToken=${buyToken}&sellAmount=${sellAmount}`
        );
        const quote = await response.json();

        if (quote.code || quote.reason) {
            console.error('Error fetching quote:', quote.reason || quote.code);
            return;
        }

        console.log('Fetched Quote:', quote);

        // Step 2: Approve the Exchange Proxy to spend your sellToken (if not already approved)
        // This step is highly dependent on the token and chain. For ERC20 tokens,
        // you'd typically interact with the token's approve method.
        // Example (simplified - requires ABI and token contract address):
        // const wethAddress = '0xC02aaA39B223FE8D0A0e5C4F27eAD9083C756Cc2'; // Mainnet WETH
        // const wethContract = new Contract(wethAddress, ['function approve(address spender, uint256 amount) returns (bool)'], wallet);
        // const approvalTx = await wethContract.approve(quote.allowanceTarget, BigNumber.from(sellAmount));
        // await approvalTx.wait();
        // console.log('Approval transaction sent:', approvalTx.hash);
        // console.log('Waiting for approval confirmation...');
        // await approvalTx.wait();
        // console.log('Approval confirmed.');

        // Step 3: Execute the swap using the wallet signer
        const tx = await wallet.sendTransaction({
            from: wallet.address,
            to: quote.to,
            data: quote.data,
            value: quote.value,
            gasPrice: quote.gasPrice,
            gasLimit: quote.gas
        });

        console.log('Swap transaction sent:', tx.hash);
        console.log('Waiting for transaction confirmation...');
        await tx.wait();
        console.log('Swap confirmed!');

    } catch (error) {
        console.error('Error during swap:', error);
    }
}

getAndExecuteSwap();