wallet.useSwap
Hook for opening the wallet swap flow with optional pre-filled swap fields.
Usage
ts
import { Hooks } from 'wagmi/tempo'
const swap = Hooks.wallet.useSwap()
// Call `mutate` in response to user action (e.g. button click, form submission)
swap.mutate({
amount: '1.5',
pairToken: '0x20c0000000000000000000000000000000000001',
slippage: 0.05,
token: '0x20c0000000000000000000000000000000000002',
type: 'sell',
})
console.log('Transaction hash:', swap.data?.receipt.transactionHash)
// @log: Transaction hash: 0x1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdefts
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
See TanStack Query mutation docs for more info hook return types.
data
See Wagmi Action wallet.swap Return Type
mutate/mutateAsync
See Wagmi Action wallet.swap 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.