Overview
The Agent class provides methods for withdrawing funds, monitoring withdrawal status, and querying fees and limits. Withdrawals come in two forms:- Partial withdrawal: Specify an amount to withdraw while the agent stays active.
- Full withdrawal: Omit the amount to deactivate the agent and transfer all funds back to the origin wallet.
withdraw()
Initiate a withdrawal from the agent’s smart account.Signature
Parameters
string
Token amount to withdraw, in the token’s smallest unit (e.g.,
'500000000' for 500 USDC with 6 decimals). When omitted, the agent is fully deactivated and all funds are transferred to the origin wallet.Returns
Promise<WithdrawResponse> — the response type depends on the withdrawal mode:
- Full withdrawal (no amount): Returns
FullWithdrawResponsewith a confirmation message. The agent begins deactivation. - Partial withdrawal (amount provided): Returns
PartialWithdrawResponsewith details of the withdrawn tokens.
Response Types
Examples
status()
Get the current status of the agent, including activation and deactivation dates.Signature
Returns
Promise<WithdrawalStatusResponse>
WithdrawalStatusResponse Type
Examples
waitForDeactivation()
Poll the agent status until it reachesDEACTIVATED. This is used after calling withdraw() without an amount (full withdrawal) to wait for the deactivation process to complete.
Signature
Parameters
WaitForDeactivationOptions
Polling configuration.
number
Polling interval in milliseconds. Defaults to
5000 (5 seconds). Must be greater than 0.number
Maximum time to wait in milliseconds. Defaults to
300000 (5 minutes). Must be greater than 0. Throws TimeoutError if exceeded.(status: AgentStatus) => void
Callback invoked on each poll with the current agent status. Use this to update a progress UI.
Returns
Promise<WithdrawalStatusResponse> — resolves when the agent reaches DEACTIVATED status.
Errors
TimeoutError: Thrown if the timeout is exceeded before the agent is deactivated. The agent may still be deactivating; callstatus()to check.ValidationError: Thrown ifintervalortimeoutis not a positive number.
Examples
fees()
Get the fee information for the agent’s smart account.Signature
Returns
Promise<FeeResponse>
FeeResponse Type
Examples
limit()
Get the withdrawal limit for a given origin wallet (EOA).Signature
Parameters
Address
required
The origin wallet address (
0x-prefixed hex string) to check the limit for.Returns
Promise<LimitResponse>
LimitResponse Type
Examples
Complete Withdrawal Flow
This example shows a complete withdrawal flow: checking fees, performing a full withdrawal, and waiting for completion.After a full withdrawal, the agent is deactivated. To use the agent again, you must re-activate it with
agent.activate().