JSPM

  • Created
  • Published
  • Downloads 328
  • Score
    100M100P100Q98935F
  • License MIT

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

Package Exports

  • @0x/0x-parser
  • @0x/0x-parser/dist/index.cjs.js
  • @0x/0x-parser/dist/index.esm.js

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@0x/0x-parser) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

0x-parser

npm version codecov build and test Medium

Blockchain Support

arbitrum avalanche base bnb chain celo ethereum fantom optimism polygon
Arbitrum Avalanche Base BNB Chain Celo Ethereum Fantom Optimism Polygon

Overview

This library is designed for 0x integrators, and it simplifies the complex task of parsing 0x transactions into a format that is both user-friendly and easy to understand.

One of the challenges when swapping tokens is that the trade can experience slippage through Automated Market Makers (AMMs), making 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. Try the demo here.

Screenshot of demo app using 0x-parser

Installation

Step 1: Install Peer Dependencies

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";

async function main() {
  const response = await fetch(
    "https://raw.githubusercontent.com/0xProject/protocol/development/packages/contract-artifacts/artifacts/IZeroEx.json"
  );

  const IZeroEx = await response.json();

  const data = await parseSwap({
    rpcUrl: "https://eth.llamarpc.com",
    exchangeProxyAbi: IZeroEx.compilerOutput.abi,
    transactionHash: "0xd8637124d650268ae7680781809800e103a3a2bee9fec56083028fea6d98140b",
  });

  console.log(data);
}

main();

Examples

This repository includes examples you can execute locally. Navigate to the /examples directory for additional README information on how to run the demos locally. You can also explore a live demo of 0x-parser here.

Contributing

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