Ether.js and Uniswap V3

Solidity Programming Language
2 min readAug 24, 2021

--

Thanos

This is Thanos Polychronakis. He is very smart and compact developer. He is working on uniswap v3 and developed ether.js query module for uniswap.

https://github.com/thanpolas/uniswap-chain-queries

Firstly we install this module in terminal

npm install @thanpolas/uniswap-chain-queries — save

Secondly we add this folder to the workspace.

Start.

getToken(tokenAddress, provider)

We create new file in this folder and we paste the following code.

const { ethers } = require(‘ethers’);

const { getToken } = require(‘@thanpolas/uniswap-chain-queries’);

async function run() {

// Define the DAI address

const erc20Address = ‘0x6B175474E89094C44Da98b954EedeAC495271d0F’;

const provider = ethers.getDefaultProvider();

const tokenData = await getToken(erc20Address, provider);

console.log(tokenData);

}

run();

Result:

getToken

getLPTokensDataByLpAddress(lpContract, provider)

const { ethers } = require(‘ethers’);

const {

getLPTokensDataByLpAddress,

} = require(‘@thanpolas/uniswap-chain-queries’);

async function run() {

const provider = ethers.getDefaultProvider();

// LP of DAI/WETH

const lpAddress = ‘0xa478c2975ab1ea89e8196811f51a7b7ade33eb11’;

const tokensData = await getLPTokensDataByLpAddress(lpAddress, provider);

console.log(tokensData);

}

run();

Result:

DAI/ETH Pool %0.3 Contract

getPriceUniswapV3(lpAddress, provider, optTokenDecimals)

const { ethers } = require(‘ethers’);

const { getPriceUniswapV3 } = require(‘@thanpolas/uniswap-chain-queries’);

async function run() {

// Uni V3 LP of DAI/WETH at 0.3% Fee

const lpAddress = ‘0xc2e9f25be6257c210d7adf0d4cd6e3e881ba25f8’;

const provider = ethers.getDefaultProvider();

const tokenPairPrice = await getPriceUniswapV3(lpAddress, provider, [18, 18]);

console.log(tokenPairPrice);

}

run();

Result:

--

--

Solidity Programming Language
Solidity Programming Language

Written by Solidity Programming Language

Solidity basics for beginners: Learn the fundamentals of smart contract development and build your first DApp! #Solidity #Foundry #Ethereum #Opcodes #DApps

No responses yet