Skip to content

dex.getBuyQuote

Gets the quote for buying a specific amount of tokens.

Usage

ts
import { Actions } from 'wagmi/tempo'
import { parseUnits } from 'viem'
import { config } from './config'

const amountIn = await Actions.dex.getBuyQuote(config, {
  amountOut: parseUnits('100', 6),
  tokenIn: '0x20c0000000000000000000000000000000000001',
  tokenOut: '0x20c0000000000000000000000000000000000002',
})

console.log('Amount needed:', amountIn)
// @log: Amount needed: 100300000n
ts
import { createConfig, http } from 'wagmi'
import { tempo } from 'wagmi/chains'
import { tempoWallet } from 'wagmi/tempo'

export const config = createConfig({
  connectors: [tempoWallet()],
  chains: [tempo],
  multiInjectedProviderDiscovery: false,
  transports: {
    [tempo.id]: http(),
  },
})

Return Type

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

Viem

Released under the MIT License.