Simple APIs to get Latest Uniswap Pair Listing

Uniswap Pool APIs

In the last article, we showed you how to get Uniswap trades using simple rest APIs. Today, we will show how you get the latest Uniswap listings using a single GraphQL query.

Before we move forward, let’s understand what Uniswap pair listing is?

Anyone can create a pool of two tokens on Uniswap. While creating, they need to provide initial liquidity (whatever they want) to both tokens for price discovery. This pool is an ERC20 token smart contract, which was created by the Uniswap Factory contract.

Don’t worry; we will show you an example of everything as we will progress.

For now, let’s get the newly created pools listing from the Uniswap.

Note: We are Uniswap V2 in this article.

Get Newly Created Uniswap Pools

To get the latest Uniswap pools, we need to run the following GraphQL query. Here —  https://graphql.bitquery.io/. This is also our endpoint for GraphQL APIs.


Result

{
"data": {
"ethereum": {
"arguments": [
{
"block": {
"height": 10836664
},
"argument": {
"name": "token0"
},
"reference": {
"address": "0x930ed81ad809603baf727117385d01f04354612e"
}
},
{
"block": {
"height": 10836664
},
"argument": {
"name": "pair"
},
"reference": {
"address": "0x7bc3a77b1b8daa4bf4b38c710119b932c5b27925"
}
},
{
"block": {
"height": 10836664
},
"argument": {
"name": "token1"
},
"reference": {
"address": "0xdf5e0e81dff6faf3a7e52ba697820c5e32d806a8"
}
}
]
}
}
}

Understing the query and the result

In this query, we are pulling data from Uniswap events. Whenever a pool is created Uniswap emits an event name ‘PairCreated’ with 3 main parameters.

  • token0 — A ERC20 token
  • token1 — Another ERC20 token
  • pair — Newly created Pair (aka pool) token address

We will be using ‘PairCreated’ events in our query to get the latest Uniswap pairs/pools.

If you notice, we are using Uniswap Factory contact address (0x5c69bee701ef814a2b6a3edd4b1652cb9cc5aa6f) in our query and a limit 3 to get the latest 3 arguments.

As you can see in the result, these arguments are token0 address, token1 address, and the newly created pair address.

Learning about the Tokens

To know the token details, just run the following query with the token address.

For example, if we want to know the details of token0 from the above result.

Result

{
"data": {
"ethereum": {
"address": [
{
"annotation": "",
"address": "0x930ed81ad809603baf727117385d01f04354612e",
"smartContract": {
"contractType": "Token",
"currency": {
"symbol": "SOLARITE",
"name": "SOLARITE",
"decimals": 18,
"tokenType": "ERC20"
}
},
"balance": 0
}
]
}
}
}

Learning about the Pair(Pool)

Now let’s look at some detail of the newly created pool.

Getting Initial Liquidity of the Pools

As we mentioned above, while creating a pool, you need to provide liquidity for both tokens; therefore, if we want to know the initial amount for both tokens in the pool, run the following query.

Here we are getting 1st two transactions received by the pool (pair).

Note: 0x7bc3a77b1b8daa4bf4b38c710119b932c5b27925 is pool (pair) address from the result above.

Result

{
"data": {
"ethereum": {
"transfers": [
{
"block": {
"timestamp": {
"time": "2020-09-10 22:10:16"
},
"height": 10836664
},
"address": {
"address": "0x37d50885b44500a2eacab7c93dd349590600f05f",
"annotation": null
},
"currency": {
"address": "0x930ed81ad809603baf727117385d01f04354612e",
"symbol": "SOLARITE"
},
"amount": 0.08,
"transaction": {
"hash": "0xf69e4560ae36fd2948cfe5b6a5d22654b46307fe0ef04022bc68c8a3ee55f957"
},
"external": true
},
{
"block": {
"timestamp": {
"time": "2020-09-10 22:10:16"
},
"height": 10836664
},
"address": {
"address": "0x37d50885b44500a2eacab7c93dd349590600f05f",
"annotation": null
},
"currency": {
"address": "0xdf5e0e81dff6faf3a7e52ba697820c5e32d806a8",
"symbol": "yDAI+yUSDC+yUSDT+yTUSD"
},
"amount": 200,
"transaction": {
"hash": "0xf69e4560ae36fd2948cfe5b6a5d22654b46307fe0ef04022bc68c8a3ee55f957"
},
"external": true
}
]
}
}
}

Getting Total Balance of different tokens in the Pool

Let’s say now you want to check the balance of both tokens in the Uniswap pool. You can use the below query for that.

By default, every pool/pair currency name is “UNI-V2”. Remember, we mentioned that pool itself is an ERC20 token.

Results

{
"data": {
"ethereum": {
"address": [
{
"balances": [
{
"currency": {
"symbol": "UNI-V2"
},
"value": 0
},
{
"currency": {
"symbol": "SOLARITE"
},
"value": 619.42286725
},
{
"currency": {
"symbol": "yDAI+yUSDC+yUSDT+yTUSD"
},
"value": 199915.11344483
}
]
}
]
}
}
}

Wrapping Up

Our GraphQL APIs are highly flexible and performative. You can write GraphQL queries to get any data from any Ethereum protocol. In future articles, we will show how to get data for different DeFi protocol. If you have any questions, ping us on our Telegram channel.

Also Read:

About Bitquery

Bitquery is a set of software tools that parse, index, access, search, and use information across blockchain networks in a unified way. Our products are:

  • Digital Assets API provides index information related to all major cryptocurrencies, coins, and tokens.
  • DEX API provides real-time deposits and transactions, trades, and other related data on different DEX protocols like Uniswap, Kyber Network, Airswap, Matching Network, etc.

If you have any questions about our products, ask them on our Telegram channel or email us at hello@bitquery.io. Also, subscribe to our newsletter below, we will keep you updated with the latest in the cryptocurrency world.