earn.withdrawExact
Withdraws an exact asset amount while limiting the vault shares burned.
Usage
import { client } from './viem.config'
const result = await client.earn.withdrawExactSync({
assetAmount: 40_000_000n,
slippageBps: 50,
vault: '0x0000000000000000000000000000000000000001',
})
{
// assetAmount: 40_000_000n,
// caller: '0x...',
// receipt: { ... },
// recipient: '0x...',
// shareAmount: 40_100_000n,
// }import { Account, createClient } from 'viem/tempo'
export const client = createClient({
account: Account.fromSecp256k1('0x...'),
})When only slippageBps is provided, the action gets a live
earn.getWithdrawQuote and derives the maximum vault share
input. The transaction approves and burns the required shares atomically.
Set an Exact Maximum
Use shareAmountMax when you already know the most vault shares you will burn.
import { client } from './viem.config'
const result = await client.earn.withdrawExactSync({
assetAmount: 40_000_000n,
shareAmountMax: 40_250_000n,
vault: '0x0000000000000000000000000000000000000001',
})
{ assetAmount: 40_000_000n, shareAmount: 40_100_000n, ... }import { Account, createClient } from 'viem/tempo'
export const client = createClient({
account: Account.fromSecp256k1('0x...'),
})Asynchronous Usage
earn.withdrawExactSync waits for inclusion and returns the decoded withdrawal event. Use
earn.withdrawExact to return the transaction hash immediately.
import { client } from './viem.config'
const hash = await client.earn.withdrawExact({
assetAmount: 40_000_000n,
shareAmountMax: 40_250_000n,
vault: '0x0000000000000000000000000000000000000001',
})
0x1234...abcdReturn Value
type ReturnValue = {
/** Exact assets received. */
assetAmount: bigint
/** Withdrawing caller. */
caller: Address
/** Transaction receipt. */
receipt: TransactionReceipt
/** Asset recipient. */
recipient: Address
/** Vault shares burned. */
shareAmount: bigint
}The asynchronous action returns the transaction hash instead.
Parameters
assetAmount
- Type:
bigint | { decimals?: number | undefined; formatted: string }
Exact assets to receive. A bigint uses base units; a formatted value uses the vault asset's
decimals unless decimals is provided.
recipient (optional)
- Type:
Address - Default:
account.address
Asset recipient.
shareAmount (optional)
- Type:
bigint
Quoted vault share input. Provide it with slippageBps to avoid a live quote.
shareAmountMax (optional)
- Type:
bigint
Maximum vault shares to burn. It cannot be combined with shareAmount or slippageBps.
slippageBps (optional)
- Type:
number
Slippage headroom above the provided or live quote, in basis points. For example, 50 means 0.5%.
vault
- Type:
Address
Vault address.
account (optional)
- Type:
Account | Address
Account that will be used to send the transaction.
feeToken (optional)
- Type:
Address | bigint
Fee token for the transaction.
Can be an unpaused USD-denominated TIP-20 token address or ID. Use client.fee.validateToken({ token }) to validate a token before submitting a transaction or setting it as a fee preference.
feePayer (optional)
- Type:
Account | true
Fee payer for the transaction.
Can be a Viem Account, or true if a Fee Payer Service will be used.
gas (optional)
- Type:
bigint
Gas limit for the transaction.
maxFeePerGas (optional)
- Type:
bigint
Max fee per gas for the transaction.
maxPriorityFeePerGas (optional)
- Type:
bigint
Max priority fee per gas for the transaction.
nonce (optional)
- Type:
number
Nonce for the transaction.
nonceKey (optional)
- Type:
'expiring' | bigint
Nonce key for the transaction. Use 'expiring' to use expiring nonces (TIP-1009), which enables concurrent transaction submission without nonce ordering.
validBefore (optional)
- Type:
number
Unix timestamp before which the transaction must be included.
validAfter (optional)
- Type:
number
Unix timestamp after which the transaction can be included.
throwOnReceiptRevert (optional)
- Type:
boolean - Default:
true
Whether to throw an error if the transaction receipt indicates a revert. Only applicable to *Sync actions.