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
Smart account wallet address to top up.
Transaction hash of the top-up deposit. Used for verification.
Return Value
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
| Error | Cause | Solution |
|---|
ValidationError: wallet address is required | Missing wallet parameter | Provide a valid wallet address |
ValidationError: Transaction hash is required | Missing tx_hash parameter | Provide the deposit transaction hash |
GizaAPIError: Agent not active | Agent is not in active state | Activate the agent before topping up |
Next Steps