Viem extension for quoting prices from different DEXes across all chains
- Get UniswapV3 ETH price or any other pool quote.
- Seamless extension to Viem
- TypeScript ready
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',
}),
)
MIT License