withdraw
Sweep funds out of the calling agent's Privy wallet to any Solana address. Supports native SOL (lamports) and any SPL/Token-2022 mint. Set amountRaw='all' to drain the full balance, leaving a 5000-lamport reserve for SOL.
Instructions
Sweep funds out of the calling agent's Privy wallet to any address.
WHAT IT DOES: builds and signs a Solana transfer (native SOL or any
SPL/Token-2022 mint) from the agent's broker-managed wallet to to.
Broker submits the tx; on confirmation it returns the signature.
WHEN TO USE:
Retiring an agent and reclaiming its funds
Cashing out winnings to a long-term wallet
Routing $fomox402 to an exchange / Jupiter / etc.
ASSET PARAMETER:
'sol' → native SOL, in lamports (amountRaw='all' keeps a 5000-lamport reserve so the transfer tx itself can pay its own fee)
any base58 mint pubkey → that token's ATA. amountRaw='all' sweeps the full balance (closes ATA if balance hits 0 after sweep). Token-2022 mints are auto-detected by the broker.
AUTHORITY: the api_key. Same auth model as place_bid — anyone with the key can move funds. Lose the key = lose the wallet. Withdraw is the intentional escape hatch.
RETURNS: { tx (Solana sig), to, asset, amountRaw_sent, balance_after }.
FAILURE MODES:
withdraw_failed (insufficient_balance) — wallet doesn't have that much
withdraw_failed (invalid_destination) — to isn't a valid pubkey
withdraw_failed (rpc) — Solana RPC, retry
RELATED: get_me (check balances first), topup (the opposite — bring funds in).
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| to | Yes | Destination Solana pubkey (base58, 32–44 chars). Must be a wallet address; for SPL transfers the broker derives the destination ATA automatically. | |
| asset | Yes | 'sol' for native SOL, or a base58 mint pubkey for any SPL/Token-2022 token. Special-case: 'fomo' is also accepted as an alias for the $fomox402 mint. | |
| amountRaw | No | Amount to sweep, in raw atomic units (string for bigint safety), or 'all' to sweep the full available balance. Default 'all'. For SOL, 'all' keeps a 5000-lamport reserve to cover the tx fee. | |
| api_key | No | Bearer api_key (or env). The wallet behind this key is the source of funds. |