Skip to main content

Function Signature

Description

Prepares and executes a withdrawal from an Earn vault in one call: it builds the payload with prepareWithdrawal and executes it with executeEarnTransaction. Withdrawals redeem shares the wallet already holds, so they never need an approval. The underlying asset is sent to receiverAddress when given, otherwise to the withdrawing wallet.

Parameters

Required Parameters

  • vaultId (string): The vault identifier from listVaults.
  • amount (string): How much of the vault’s underlying asset to withdraw, in the asset’s human-readable units ('12.5' USDC, not '12500000'). Needs a leading zero ('0.01', not '.01').
  • walletMetadata (WalletMetadata): Non-sensitive wallet metadata persisted from createWalletAccount() / importPrivateKey(). Its chainName must be 'EVM'.

Optional Parameters

  • receiverAddress (string): The address that receives the withdrawn asset. Defaults to the withdrawing wallet.
  • password (string): Required if the wallet was created with backUpToDynamic: true. Used for backup decryption when externalServerKeyShares is not provided.
  • externalServerKeyShares (ServerKeyShare[]): Caller-supplied plaintext shares.
  • sponsored (boolean): When true, relays the vault call as a gasless transaction. See EVM Gas Sponsorship.
  • chain (Chain): The viem chain for the vault. Its id must match the vault’s chainId. When omitted, the chain is built from rpcUrl, so one of chain or rpcUrl is required.
  • rpcUrl (string): RPC endpoint for the vault’s chain.
  • onStepChange ((step: EarnExecutionStep) => void): Reports transaction as execution proceeds.
  • traceContext (TraceContext): Trace context forwarded to the Dynamic API.

Returns

  • Promise<EarnTransactionResult>: An object with transactionHash, the hash of the vault transaction.

Example

Error Handling

Fails with an HTTP 403 error when Earn is not enabled for your environment or an HTTP 400 error when the amount exceeds the position or is otherwise invalid. Throws when walletMetadata.chainName is not 'EVM', when chain.id mismatches the payload’s chainId, when neither chain nor rpcUrl is given, or when the vault transaction reverts.

See Also

Last modified on October 29, 2026