Skip to content

dex.getBuyQuote

Gets the quote for buying a specific amount of tokens.

Usage

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

const  = await ..(, {
  : ('100', 6),
  : '0x20c0000000000000000000000000000000000001',
  : '0x20c0000000000000000000000000000000000002',
})

.('Amount needed:', )
Amount needed: 100300000n
ts
import { createConfig, http } from 'wagmi'
import { tempoTestnet } from 'wagmi/chains'
import { KeyManager, webAuthn } from 'wagmi/tempo'

export const config = createConfig({
  connectors: [
    webAuthn({
      keyManager: KeyManager.localStorage(),
    }),
  ],
  chains: [tempoTestnet],
  multiInjectedProviderDiscovery: false,
  transports: {
    [tempoTestnet.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.