Skip to content

dex.getBuyQuote

Gets the quote for buying a specific amount of tokens.

Usage

example.ts
import { Actions } from 'tempo.ts/wagmi'
import { parseUnits } from 'viem'
import { config } from './wagmi.config'
 
const amountIn = await Actions.dex.getBuyQuote(config, {
  amountOut: parseUnits('100', 6),
  tokenIn: '0x20c0000000000000000000000000000000000001',
  tokenOut: '0x20c0000000000000000000000000000000000002',
})
 
console.log('Amount needed:', amountIn)
Amount needed: 100300000n

Return Type

type ReturnType = bigint

Returns 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.