This project contains a script to query the top 10 trades by volume on the Uniswap V2 subgraph using The Graph API. This information can be used for market analysis, trading strategies, and understanding liquidity flows.
This project provides a script to query and analyze the top 10 trades by volume on the Uniswap V2 platform deployed on the Arbitrum network. It leverages The Graph API to fetch data from the Uniswap V2 subgraph. The primary components of the project include:
Node.js
: A JavaScript runtime used to run the script.Axios
: A promise-based HTTP client for making requests to The Graph API.Dotenv
: A module to manage environment variables securely.Analyzing the top trades by volume enables users to gain insights into the most significant transactions on the Uniswap V2 platform. This information is crucial for:
Real-World Example:
The subgraph used in this project is the Uniswap V2 subgraph deployed on the Arbitrum network. A subgraph is a specific dataset that The Graph indexes and makes available for querying via GraphQL. This allows for efficient and flexible data retrieval from decentralized applications.
You can explore the subgraph here: Uniswap V2 Subgraph on Arbitrum
To query this subgraph from the terminal, use the following URL: https://gateway-arbitrum.network.thegraph.com/api/[YOUR_API_KEY]/subgraphs/id/EYCKATKGBKLWvSfwvBjzfCBmGwYNdVkduYXVivCsLRFu
Ensure you have the following prerequisites before running the script:
If you don't have Node.js installed, follow this guide to set it up for your operating system.
Screenshots:
Note: Each API key has usage limits. Refer to The Graph's documentation for more details on quotas and limitations.
Open your terminal and run the following commands:
git clone https://github.com/temichelle13/uniswap-top-trades-query
cd uniswap-top-trades-query
Note: This will clone the repository to your local machine and navigate into the project's root directory.
npm install axios dotenv
This command installs the necessary dependencies: axios
for HTTP requests and dotenv
for environment variable management
Note: Ensure you run these commands from the root directory of the cloned repository, which we navigated to it the previous step.
Rename the .env.example
file
.env.example
file in the root directory of your project..env
.Edit the Environment File:
.env
file using a text editor such as Notepad, VS Code, or any other editor of your choice.[GRAPH_API_KEY]
with your actual API key. Ensure there are no spaces around the equal sign and that the key is accurately copied.Save the Changes:
.env
file after editing.Sample .env File:
GRAPH_API_KEY=your_api_key_here
Environment variables allow you to manage configuration settings and sensitive information, like API keys, securely and separately from your source code. This helps to keep your private information and assets safe.
Execute the following command to run the script and fetch the top 10 trades by volume from the Uniswap V2 subgraph:
node query.js
The script will output details of the top trades, including trade IDs, transaction IDs, amounts in USD, and trading pairs.
Interpreting the Results:
Performance Considerations:
query TopTrades {
swaps(first: 10, orderBy: amountUSD, orderDirection: desc) {
id
amountUSD
transaction {
id
}
pair {
token0 {
symbol
}
token1 {
symbol
}
}
}
}
`;
Upon successful execution, the script will produce an output similar to the following:
Trade ID: 0x76f2546586ac5b1ba522babaa5fbbd9e65ca2047f39497b6b277a08da35cb152-27
Transaction ID: 0x76f2546586ac5b1ba522babaa5fbbd9e65ca2047f39497b6b277a08da35cb152
Amount (USD): 4.3981656918396856e+33
Pair: Unknown Token / 0xDEV
---------------------------------------
Trade ID: 0x76f2546586ac5b1ba522babaa5fbbd9e65ca2047f39497b6b277a08da35cb152-28
Transaction ID: 0x76f2546586ac5b1ba522babaa5fbbd9e65ca2047f39497b6b277a08da35cb152
Amount (USD): 4.3981656918396856e+33
Pair: USDC / Unknown Token
---------------------------------------
Trade ID: 0x76f2546586ac5b1ba522babaa5fbbd9e65ca2047f39497b6b277a08da35cb152-31
Transaction ID: 0x76f2546586ac5b1ba522babaa5fbbd9e65ca2047f39497b6b277a08da35cb152
Amount (USD): 4.3981656918396856e+33
Pair: ZKLK / Unknown Token
---------------------------------------
Trade ID: 0x76f2546586ac5b1ba522babaa5fbbd9e65ca2047f39497b6b277a08da35cb152-26
Transaction ID: 0x76f2546586ac5b1ba522babaa5fbbd9e65ca2047f39497b6b277a08da35cb152
Amount (USD): 4.3981656918396856e+33
Pair: PALAI / Unknown Token
---------------------------------------
Trade ID: 0x76f2546586ac5b1ba522babaa5fbbd9e65ca2047f39497b6b277a08da35cb152-29
Transaction ID: 0x76f2546586ac5b1ba522babaa5fbbd9e65ca2047f39497b6b277a08da35cb152
Amount (USD): 4.3981656918396856e+33
Pair: TPAD / Unknown Token
---------------------------------------
Trade ID: 0x76f2546586ac5b1ba522babaa5fbbd9e65ca2047f39497b6b277a08da35cb152-32
Transaction ID: 0x76f2546586ac5b1ba522babaa5fbbd9e65ca2047f39497b6b277a08da35cb152
Amount (USD): 4.3981656918396856e+33
Pair: PEPE / Unknown Token
---------------------------------------
Trade ID: 0x76f2546586ac5b1ba522babaa5fbbd9e65ca2047f39497b6b277a08da35cb152-30
Transaction ID: 0x76f2546586ac5b1ba522babaa5fbbd9e65ca2047f39497b6b277a08da35cb152
Amount (USD): 4.3981656918396856e+33
Pair: CRYPT / Unknown Token
---------------------------------------
Trade ID: 0x310307c773fcdbfacc21dba2ed454c48511529cf9e18dfe192f4d98c53bb42de-1
Transaction ID: 0x310307c773fcdbfacc21dba2ed454c48511529cf9e18dfe192f4d98c53bb42de
Amount (USD): 4.3981656918396856e+33
Pair: PEPE / Unknown Token
---------------------------------------
Trade ID: 0xea696c395092e2697212b5de2fbb00a10870286bd9a6e4fe903ca53250c55ab6-0
Transaction ID: 0xea696c395092e2697212b5de2fbb00a10870286bd9a6e4fe903ca53250c55ab6
Amount (USD): 1.278864171116066e+18
Pair: TRIAS / USDC
---------------------------------------
Trade ID: 0x97a6234a8eb09a6f193d1488e94c2262a8e7ee34b0e84afdbdbbe7e2bc1b7739-0
Transaction ID: 0x97a6234a8eb09a6f193d1488e94c2262a8e7ee34b0e84afdbdbbe7e2bc1b7739
Amount (USD): 1.2137438260380554e+16
Pair: $MONG / MING
---------------------------------------
.env
file.npm install
again..env
file.Additional Resources:
To customize the query, edit the query.js
file. For example, to fetch trades for a different token pair, modify the GraphQL query string accordingly.
Example:
const query = `
{
trades(first: 10, orderBy: volumeUSD, orderDirection: desc, where: {pair: "0x1234567890abcdef"}) {
id
transaction {
id
}
volumeUSD
pair {
token0 {
symbol
}
token1 {
symbol
}
}
}
}
You can extend this project by integrating it with other services such as:
Contributions are always welcome to this project! Please follow these steps to contribute:
Code of Conduct: Please adhere to our Code of Conduct to ensure a positive and inclusive community.
Detailed Contribution Guidelines: Refer to our Contributing Guide for more details on how to contribute.
Summary:
Additional Resources:
This project demonstrates how to interact with The Graph's GraphQL endpoint to fetch data from a subgraph. The provided query fetches the top 10 trades by volume from the Uniswap V2 subgraph on the Arbitrum network.
axios:
A promise-based HTTP client for Node.jsdotenv:
Module to load environment variables from a .env fileVisit the GitHub repository to explore the project.