How to get Sushiswap V2 pair address
Step 1: Setup Moralisβ
Read the article Setting Up Moralis: Getting Started and make sure to finish all the steps. Only after that you can go ahead to complete this guide.
Step 2: Get Pair Address of A Sushiswap V2 Liquidity Poolβ
In order to get pair address of a liquidity, Moralis provides you a getPairAddress endpoint to do so.
Here you'll need three parameters: token0
, token1
and address
.
Once you've obtained all three parameters, you can copy the following code:
- index.js (JavaScript)
- index.ts (TypeScript)
- index.py (Python)
const Moralis = require("moralis").default;
const { EvmChain } = require("@moralisweb3/common-evm-utils");
const runApp = async () => {
await Moralis.start({
apiKey: "YOUR_API_KEY",
// ...and any other configuration
});
const chain = EvmChain.ETHEREUM;
// token 0 address, e.g. WETH token address
const token0Address = "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2";
// token 1 address, e.g. LINK token address
const token1Address = "0x514910771AF9Ca656af840dff83E8264EcF986CA";
const response = await Moralis.EvmApi.defi.getPairAddress({
token0Address,
token1Address,
chain,
exchange: "sushiswapv2",
});
console.log(response.toJSON());
};
runApp();
import Moralis from "moralis";
import { EvmChain } from "@moralisweb3/common-evm-utils";
const runApp = async () => {
await Moralis.start({
apiKey: "YOUR_API_KEY",
// ...and any other configuration
});
const chain = EvmChain.ETHEREUM;
// token 0 address, e.g. WETH token address
const token0Address = "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2";
// token 1 address, e.g. LINK token address
const token1Address = "0x514910771AF9Ca656af840dff83E8264EcF986CA";
const response = await Moralis.EvmApi.defi.getPairAddress({
token0Address,
token1Address,
chain,
exchange: "sushiswapv2",
});
console.log(response.toJSON());
};
runApp();
from moralis import evm_api
api_key = "YOUR_API_KEY"
params = {
"exchange": "sushiswapv2",
# token 0 address, e.g. WETH token address
"token0_address": "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2",
# token 1 address, e.g. LINK token address
"token1_address": "0x514910771AF9Ca656af840dff83E8264EcF986CA",
"chain": "eth"
}
result = evm_api.defi.get_pair_address(
api_key=api_key,
params=params,
)
print(result)
Step 3: Run the scriptβ
To run the script, enter the following command:
- Shell (JavaScript)
- Shell (TypeScript)
- Shell (Python)
node index.js
ts-node index.ts
python index.py
In your terminal, you should see the following JSON response:
{
"token0": {
"address": "0x514910771af9ca656af840dff83e8264ecf986ca",
"name": "Chain Link",
"symbol": "LINK",
"decimals": "18",
"logo": "https://cdn.moralis.io/eth/0x514910771af9ca656af840dff83e8264ecf986ca.webp",
"logo_hash": "fd74ea1227adb458733847c09aab05d89c35c14b640c5ee1e0a8bffa79193eb4",
"thumbnail": "https://cdn.moralis.io/eth/0x514910771af9ca656af840dff83e8264ecf986ca_thumb.webp",
"block_number": null,
"validated": null,
"created_at": "2022-01-20T10:39:55.818Z"
},
"token1": {
"address": "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2",
"name": "Wrapped Ether",
"symbol": "WETH",
"decimals": "18",
"logo": "https://cdn.moralis.io/eth/0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2.webp",
"logo_hash": "0a7fc292596820fe066ce8ce3fd6e2ad9d479c2993f905e410ef74f2062a83ec",
"thumbnail": "https://cdn.moralis.io/eth/0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2_thumb.webp",
"block_number": null,
"validated": null,
"created_at": "2022-01-20T10:39:55.818Z"
},
"pairAddress": "0xc40d16476380e4037e6b1a2594caf6a6cc8da967"
}
Congratulations π₯³ You just get the pair address of a Sushiswap V2 liquidity pool with just a few lines of code using the Moralis DeFi API!
Youtube Videoβ
API Referenceβ
If you want to know more details on the endpoint and optional parameters, check out:
Supportβ
If you face any trouble following the tutorial, feel free to reach out to our community engineers in our Discord or Forum to get 24/7 developer support.