Skip to main content

Method Signature

agent.pollWithdrawalStatus(
  wallet: Address,
  options?: PollWithdrawalStatusOptions
): Promise<WithdrawalStatusResponse>

Description

Polls the withdrawal status at regular intervals until the agent reaches deactivated status. Useful for waiting until a full withdrawal completes.

Parameters

wallet
Address
required
Smart account wallet address.
options
PollWithdrawalStatusOptions
Optional polling configuration:
  • interval - Polling interval in milliseconds (default: 5000ms)
  • timeout - Maximum wait time in milliseconds (default: 300000ms / 5 minutes)
  • onUpdate - Callback function called on each status update

Return Value

Returns Promise<WithdrawalStatusResponse> when the agent status becomes deactivated.
status
AgentStatus
Final status (will be deactivated on success).
wallet
Address
Smart account wallet address.
activation_date
string
When the agent was activated.
last_deactivation_date
string
When the agent was deactivated.

Example

import { GizaAgent, Chain } from '@giza/agent-sdk';

const giza = new GizaAgent({ chainId: Chain.BASE });

// Initiate full withdrawal
await giza.agent.withdraw({
  wallet: smartAccountAddress,
  transfer: true,
});

// Wait for completion with progress updates
const finalStatus = await giza.agent.pollWithdrawalStatus(
  smartAccountAddress,
  {
    interval: 5000,    // Check every 5 seconds
    timeout: 300000,   // Wait up to 5 minutes
    onUpdate: (status) => {
      console.log('Current status:', status);
    },
  }
);

console.log('Withdrawal complete!');
console.log('Final status:', finalStatus.status);
console.log('Deactivated at:', finalStatus.last_deactivation_date);

Error Handling

import { ValidationError, TimeoutError, GizaAPIError } from '@giza/agent-sdk';

try {
  const finalStatus = await giza.agent.pollWithdrawalStatus(
    smartAccountAddress,
    { timeout: 60000 } // 1 minute timeout
  );
  console.log('Withdrawal complete:', finalStatus);
} catch (error) {
  if (error instanceof TimeoutError) {
    console.error('Withdrawal timed out. Check status manually.');
    // Optionally check status and retry
    const status = await giza.agent.getWithdrawalStatus(smartAccountAddress);
    console.log('Current status:', status.status);
  } else if (error instanceof ValidationError) {
    console.error('Invalid parameters:', error.message);
  } else if (error instanceof GizaAPIError) {
    console.error('API error:', error.message);
  }
}

Common Errors

ErrorCauseSolution
TimeoutErrorWithdrawal didn’t complete within timeoutIncrease timeout or check status manually
ValidationError: Polling interval must be greater than 0Invalid interval valueUse a positive interval
ValidationError: Polling timeout must be greater than 0Invalid timeout valueUse a positive timeout

Notes

If the timeout is reached before the agent is deactivated, a TimeoutError is thrown. The withdrawal is still in progress and can be monitored with getWithdrawalStatus().
Use the onUpdate callback to provide visual feedback to users during the withdrawal process.

Next Steps