Skip to content

dex.useSell

Sells a specific amount of tokens on the Stablecoin DEX orderbook.

Usage

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

const  = ..()

// Call `mutate` in response to user action (e.g. button click, form submission)
.({
  : ('100', 6),
  : ('95', 6),
  : '0x20c0000000000000000000000000000000000001',
  : '0x20c0000000000000000000000000000000000002',
})

.('Transaction hash:', .?..)
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(),
  },
})

Asynchronous Usage

The example above uses a *Sync variant of the action, that will wait for the transaction to be included before returning.

If you are optimizing for performance, you should use the non-sync dex.sell action and wait for inclusion manually:

ts
import { Hooks } from 'wagmi/tempo'
import { parseUnits } from 'viem'
import { useWaitForTransactionReceipt } from 'wagmi'

const sell = Hooks.dex.useSell()
const { data: receipt } = useWaitForTransactionReceipt({ hash: sell.data })

// Call `mutate` in response to user action (e.g. button click, form submission)
sell.mutate({
  amountIn: parseUnits('100', 6),
  minAmountOut: parseUnits('95', 6),
  tokenIn: '0x20c0000000000000000000000000000000000001',
  tokenOut: '0x20c0000000000000000000000000000000000002',
})

Return Type

See TanStack Query mutation docs for more info hook return types.

data

See Wagmi Action dex.sell Return Type

mutate/mutateAsync

See Wagmi Action dex.sell Parameters

Parameters

config

Config | undefined

Config to use instead of retrieving from the nearest WagmiProvider.

mutation

See the TanStack Query mutation docs for more info hook parameters.

Action

Released under the MIT License.