JSPM

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

๐Ÿงพ Designed for 0x integrators: This parser library enables precise extraction of swap amounts from 0x transactions.

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 build and test codecov

Designed for 0x integrators, this library is used to parse swap amounts from 0x transactions, a task that becomes complex when trades involve Automated Market Makers (AMMs). Given the potential for slippage in these trades, the final swap amounts cannot be anticipated before trade execution. This library addresses this challenge by accepting a transaction hash as input, then parses through the event logs to identify the exact swap amounts.

Installation

npm install @0x/0x-parser

Usage

import { parseSwap } from '@0x/0x-parser';

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

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

  console.log(JSON.stringify(data);
}

main();

Live demo

Try a demo app that uses 0x-parser here.

0x parser React demo app

Examples

This repository includes an example you can execute locally using the npm run web:example command. Additionally, there's another repository that showcases how to use this package within a simple React app, which you can find here.

Contributing

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