- Notifications
You must be signed in to change notification settings - Fork15
🧾 A library that parses 0x transactions from EVM blockchains into a format that is user-friendly and easy to understand.
License
0xProject/0x-parser
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
This library is designed for0x integrators, simplifying the complex task of parsing0x 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.
Try out the parser in alive code environment directly in your browser 🌐. You can also experience it in action through thedemo UI app, which is built with 0x-parser.
0x-parser relies on thedebug_traceTransaction Ethereum JSON-RPC method to parse 0x transactions. Ensure that your RPC nodesupportsthismethod.
First, make sure you have the required peer dependencyviem installed. If you haven't installed it yet, you can do so with the following command:
npm install viemAfter installing the peer dependency, proceed to install the@0x/0x-parser package:
npm install @0x/0x-parserimport{parseSwap}from"@0x/0x-parser";import{createPublicClient}from"viem";import{http}from"viem";import{mainnet}from"viem/chains";asyncfunctionmain(){constRPC_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/0x2fc205711fc933ef6e5bcc0bf6e6a9bfc220b2d8073aea4f41305882f485669dconsttransactionHash=`0x2fc205711fc933ef6e5bcc0bf6e6a9bfc220b2d8073aea4f41305882f485669d`;constpublicClient=createPublicClient({chain:mainnet,transport:http(RPC_URL),});constswap=awaitparseSwap({ publicClient, transactionHash});console.log(swap);// Logs the swap details.}main();
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 runningnpm run web:example.
Contributions are always welcomed! Please read thecontributing guidelines before submitting a pull request.
About
🧾 A library that parses 0x transactions from EVM blockchains into a format that is user-friendly and easy to understand.
Topics
Resources
License
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Packages0
Uh oh!
There was an error while loading.Please reload this page.
Contributors4
Uh oh!
There was an error while loading.Please reload this page.
















