Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

🧾 A library that parses 0x transactions from EVM blockchains into a format that is user-friendly and easy to understand.

License

NotificationsYou must be signed in to change notification settings

0xProject/0x-parser

Repository files navigation

npm versionminified sizecodecovbuild and testMedium

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
Plasma
Plasma
coming soon
🔜
coming soon
🔜
coming soon
🔜

Overview

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.

Demo

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.

Screenshot of demo app using 0x-parser

Requirements

0x-parser relies on thedebug_traceTransaction Ethereum JSON-RPC method to parse 0x transactions. Ensure that your RPC nodesupportsthismethod.

Installation

Step 1: Install Peer Dependency

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

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 runningnpm run web:example.

Contributing

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

Stars

Watchers

Forks

Packages

No packages published

Contributors4

  •  
  •  
  •  
  •  

[8]ページ先頭

©2009-2025 Movatter.jp