dex.getBuyQuote
Gets the quote for buying a specific amount of tokens.
Usage
example.ts
import { parseUnits } from 'viem'
import { client } from './viem.config'
const amountIn = await client.dex.getBuyQuote({
amountOut: parseUnits('100', 6),
tokenIn: '0x20c0000000000000000000000000000000000001',
tokenOut: '0x20c0000000000000000000000000000000000002',
})
console.log('Amount needed:', amountIn)
Amount needed: 100300000nReturn Type
type ReturnType = bigintReturns the amount of tokenIn needed to buy the specified amountOut of tokenOut.
Parameters
amountOut
- Type:
bigint
Amount of tokenOut to buy.
tokenIn
- Type:
Address
Address of the token to spend.
tokenOut
- Type:
Address
Address of the token to buy.
account (optional)
- Type:
Account | Address
Account that will be used to send the transaction.
blockNumber (optional)
- Type:
bigint
Block number to read the state from.
blockOverrides (optional)
- Type:
BlockOverrides
Block overrides to apply to the state.
blockTag (optional)
- Type:
BlockTag
Block tag to read the state from.
stateOverride (optional)
- Type:
StateOverride
State override to apply.