Skip to main content

Method Signature

agent.topUp(params: TopUpParams): Promise<TopUpResponse>

Description

Adds additional funds to an active agent. Call this method after the user has deposited additional funds to the smart account.

Parameters

wallet
Address
required
Smart account wallet address to top up.
tx_hash
string
required
Transaction hash of the top-up deposit. Used for verification.

Return Value

message
string
Success message confirming the top-up.

Example

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

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

// After user deposits additional funds to the smart account
await giza.agent.topUp({
  wallet: smartAccountAddress,
  tx_hash: depositTxHash,
});

console.log('Top-up successful! Agent will optimize the new funds.');

Error Handling

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

try {
  await giza.agent.topUp({
    wallet: smartAccountAddress,
    tx_hash: depositTxHash,
  });
} catch (error) {
  if (error instanceof ValidationError) {
    console.error('Invalid parameters:', error.message);
  } else if (error instanceof GizaAPIError) {
    console.error('Top-up failed:', error.message);
  }
}

Common Errors

ErrorCauseSolution
ValidationError: wallet address is requiredMissing wallet parameterProvide a valid wallet address
ValidationError: Transaction hash is requiredMissing tx_hash parameterProvide the deposit transaction hash
GizaAPIError: Agent not activeAgent is not in active stateActivate the agent before topping up

Next Steps