Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

@0x/0x-parser

0xproject1kMIT2.10.2TypeScript support: included

🧾 Designed for 0x integrators: This library parses 0x transactions on EVM blockchains into a format that is both user-friendly and easy to understand.

0x, dex, logs, swap, parse, tokens, events, gasless, settler, ethereum, aggregator, 0x protocol, transactions

readme

0x-parser

npm version minified size codecov build and test Medium

Blockchain Support

arbitrum
Arbitrum
avalanche
Avalanche
base
Base
bnb chain
BNB Chain
blast
Blast
ethereum
Ethereum
linea
Linea
mantle
Mantle
optimism
Optimism
polygon
Polygon
scroll
Scroll
coming soon
Mode
Worldchain
Worldchain
Unichain
Unichain
coming soon
Berachain
coming soon
🔜
coming soon
🔜
coming soon
🔜

Overview

This library is designed for 0x integrators, simplifying the complex task of parsing 0x transactions into a format that is both user-friendly and easy to understand. When swapping tokens, one of the challenges is that the trade can experience slippage through Automated Market Makers (AMMs). This makes the final swap amounts difficult to predict prior to executing the trade. However, this library overcomes that challenge by parsing the transaction receipt and event logs to accurately identify the final swap amounts.

Demo

Try out the parser in a live code environment directly in your browser 🌐. You can also experience it in action through the demo UI app, which is built with 0x-parser.

Screenshot of demo app using 0x-parser

Requirements

0x-parser relies on the debug_traceTransaction Ethereum JSON-RPC method to parse 0x transactions. Ensure that your RPC node supports this method.

Installation

Step 1: Install Peer Dependency

First, make sure you have the required peer dependency viem installed. If you haven't installed it yet, you can do so with the following command:

npm install viem

Step 2: Install the Parsing Library

After installing the peer dependency, proceed to install the @0x/0x-parser package:

npm install @0x/0x-parser

Usage

import { parseSwap } from "@0x/0x-parser";
import { createPublicClient } from "viem";
import { http } from "viem";
import { mainnet } from "viem/chains";

async function main() {
  const RPC_URL = `https://eth-mainnet.g.alchemy.com/v2/${process.env.ALCHEMY_API_KEY}`;

  // You can pass any transaction hash that you got after submitted a 0x transaction:
  // https://etherscan.io/address/0x2fc205711fc933ef6e5bcc0bf6e6a9bfc220b2d8073aea4f41305882f485669d
  const transactionHash = `0x2fc205711fc933ef6e5bcc0bf6e6a9bfc220b2d8073aea4f41305882f485669d`;

  const publicClient = createPublicClient({
    chain: mainnet,
    transport: http(RPC_URL),
  });

  const swap = await parseSwap({ publicClient, transactionHash });

  console.log(swap); // Logs the swap details.
}

main();

Development

This repository contains example code that you can run locally, which is useful for the development process. The code can be found in /examples/web/index.html and you can run the code by running npm run web:example.

Contributing

Contributions are always welcomed! Please read the contributing guidelines before submitting a pull request.

changelog

Changelog

2.10.2 (2025-06-07)

Bug Fixes

  • use log that has taker from transfer for meta txn (9020b47)

2.10.1 (2025-03-21)

Bug Fixes

  • added batch call + delete useless on-chain call (#75) (bce9f9f)

2.10.0 (2025-02-25)

Features

  • log warning for reverted transactions (4d0ab07)

2.9.0 (2025-02-21)

Features

  • support parsing transactions on berachain (34900e7)

2.8.0 (2025-02-12)

Features

2.7.1 (2025-01-21)

Bug Fixes

  • sum total amount leaving the taker's account (3fa9001), closes #72

2.7.0 (2025-01-01)

Features

2.6.0 (2024-10-28)

Features

2.5.0 (2024-10-06)

Features

  • introduce mantle support (182c90f)
  • support new chain, blast (410971b)

2.4.0 (2024-09-28)

Features

  • support new chain, blast (410971b)

2.3.0 (2024-09-26)

Features

  • support linea + update polygon native symbol (f2ff8c4)

2.2.0 (2024-09-24)

Features

  • support new chain, scroll (5f5bed4)

2.1.3 (2024-09-23)

Bug Fixes

  • use correct taker for meta transaction (70caa91)

2.1.2 (2024-08-19)

Bug Fixes

  • ensure output values exist (0c3dc98)

2.1.1 (2024-08-19)

Bug Fixes

  • return null for smart contract wallet reverts (bcd9730)

2.1.0 (2024-08-19)

Features

  • support parsing erc-4337 transactions (373d143)

2.0.2 (2024-08-11)

Bug Fixes

  • remove hardcoded settler meta txn contract (70893de)

2.0.1 (2024-07-31)

Bug Fixes

  • parse latest executeMetaTxn from base (f6a825c)

2.0.0 (2024-07-18)

⚠ BREAKING CHANGES

  • migrate project to 0x v2 & settler

Features

  • migrate project to 0x v2 & settler (ec87786)

1.2.5 (2024-07-17)

Bug Fixes

  • filter from logs from taker for initial input (fb218e5)

1.2.4 (2024-07-16)

Bug Fixes

  • use logs if taker received found in logs (ef27691)

1.2.3 (2024-07-10)

Bug Fixes

  • erc-20 transfers for SettlerMetaTxn (329a1fd)

1.2.2 (2024-07-10)

Bug Fixes

  • native transfers with SettlerMetaTxn (1d659a6)

1.2.1 (2024-07-10)

Bug Fixes

  • account for native token transfer & meta transactions (2f65804)

1.2.0 (2024-06-19)

Features

  • introduce parseSwapV2 for Settler (a15fcc4)

1.1.1 (2024-06-03)

Miscellaneous Chores

1.1.0 (2024-05-03)

deps

Bug Fixes

  • latest TS requires specific rootDir (55b0dbc)

1.0.4 (2024-03-19)

Bug Fixes

  • use output log that has WETH for sellTokenForEthToUniswapV3 (7660957)

1.0.3 (2024-03-01)

Bug Fixes

  • bnb txs that do not transfer tokens to taker (a1940e3)

1.0.2 (2023-09-10)

Bug Fixes

  • handle permitAndCall function overload (34d01c9)

1.0.1 (2023-09-04)

Performance Improvements

1.0.0 (2023-09-02)

⚠ BREAKING CHANGES

  • viem as peer dependency

Features

  • viem as peer dependency (f8c2239)

Bug Fixes

  • account for identical permitAndCall function names (1ead225)
  • handle zero transfer events for sellToPancakeSwap (4ea566a)
  • support sellEthForTokenToUniswapV3 multihop (06f7faf)

0.6.0 (2023-08-31)

Features

  • introduce viem + remove ethers (1432283)

Bug Fixes

  • remove exchange proxy abi from bundle... (2b6e6f8)
  • support multihop for sellToUniswap (5128e75)
  • use native asset for parsers that need it (ae82504)

0.5.0 (2023-08-13)

Features

  • add new addresses for permitandcall (4cc8f86)

0.4.0 (2023-08-13)

Features

0.3.6 (2023-06-19)

Bug Fixes

  • reduce rpc call for transformERC20 by one (7803fb5)
  • reduce rpc calls for multiplexBatchSellTokenForToken by 80% (03c0a04)
  • use exchange proxy address by chain id (b3bbb88)

0.3.5 (2023-06-13)

Build System

  • expand node support & update deps (48f3d24)

0.3.4 (2023-06-12)

Build System

  • update esbuild minification for nextjs (26764e1)

0.3.3 (2023-06-11)

Build System

  • update type declarations (68f609a)

0.3.2 (2023-06-11)

Build System

  • update type declarations (102befd)

0.3.1 (2023-06-11)

Build System

  • fix location of type declarations (b38e8d5)

0.3.0 (2023-06-11)

Features

0.2.0 (2023-05-30)

Features

  • introduce executeMetaTransactionV2 (b51afd0)
  • update executeMetaTransactionV2 & transformERC20 (4ec05c2)

Bug Fixes

  • unwrap metatransaction from permitAndCall (7aaa97b)

0.1.0 (2023-05-22)

Features

0.0.5 (2023-05-19)

Features