Skip to content

Viem extension to quote prices. Get ETH price in a few lines of code.

License

Notifications You must be signed in to change notification settings

dalechyn/viem-quoter

Repository files navigation

Viem Quoter

Viem extension for quoting prices from different DEXes across all chains


Features

  • Get UniswapV3 ETH price or any other pool quote.
  • Seamless extension to Viem
  • TypeScript ready

Overview

import { publicViemQuoterActions } from 'viem-quoter'
import { createPublicClient, http } from 'viem'
import { mainnet } from 'viem/chains'

const publicClient = createPublicClient({
  chain: mainnet,
  transport: http(),
}).extend(publicViemQuoterActions)

console.log('ETH/USD Price is:', await publicClient.getUniswapV3EthPrice())

console.log(
  'WBTC/ETH Price is:',
  await publicClient.getUniswapV3Price({
    tokenToQuote: '0x2260FAC5E5542a773Aa44fBCfeDf7C193bc2C599', // WBTC
    otherToken: '0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2',
  }),
)

Better tree shaking version:

import { getUniswapV3Price, getUniswapV3EthPrice } from 'viem-quoter/actions'
import { createPublicClient, http } from 'viem'
import { mainnet } from 'viem/chains'

const publicClient = createPublicClient({
  chain: mainnet,
  transport: http(),
})

console.log('ETH/USD Price is:', await getUniswapV3EthPrice(publicClient))

console.log(
  'WBTC/ETH Price is:',
  await getUniswapV3Price(publicClient, {
    tokenToQuote: '0x2260FAC5E5542a773Aa44fBCfeDf7C193bc2C599', // WBTC
    otherToken: '0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2',
  }),
)

Authors

License

MIT License

About

Viem extension to quote prices. Get ETH price in a few lines of code.

Resources

License

Stars

Watchers

Forks

Packages

No packages published