Skip to main content

Method Signature

agent.claimRewards(wallet: Address): Promise<ClaimedRewardsResponse>

Description

Claims accrued rewards from DeFi protocols for an agent. Many protocols distribute reward tokens (like AAVE, COMP, etc.) that accumulate over time and can be claimed.

Parameters

wallet
Address
required
Smart account wallet address.

Return Value

rewards
ClaimedReward[]
Array of claimed rewards, each containing:
  • token - Token address of the reward
  • amount - Raw amount claimed
  • amount_float - Human-readable amount
  • current_price_in_underlying - Price in the underlying token

Example

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

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

// Claim rewards
const rewards = await giza.agent.claimRewards(smartAccountAddress);

console.log(`Claimed ${rewards.rewards.length} reward tokens`);

rewards.rewards.forEach((reward) => {
  console.log(`Token: ${reward.token}`);
  console.log(`  Amount: ${reward.amount_float}`);
  console.log(`  Value: ${reward.current_price_in_underlying}`);
});

// Calculate total value
const totalValue = rewards.rewards.reduce(
  (sum, r) => sum + r.amount_float * r.current_price_in_underlying,
  0
);
console.log(`Total claimed value: ${totalValue}`);

Output

{
  rewards: [
    {
      token: '0x7Fc66500c84A76Ad7e9c93437bFc5Ac33E2DDaE9', // AAVE
      amount: 500000000000000000,
      amount_float: 0.5,
      current_price_in_underlying: 100
    },
    {
      token: '0xc00e94Cb662C3520282E6f5717214004A7f26888', // COMP
      amount: 250000000000000000,
      amount_float: 0.25,
      current_price_in_underlying: 50
    }
  ]
}

Error Handling

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

try {
  const rewards = await giza.agent.claimRewards(smartAccountAddress);
  console.log('Rewards claimed successfully');
} catch (error) {
  if (error instanceof ValidationError) {
    console.error('Invalid wallet address:', error.message);
  } else if (error instanceof GizaAPIError) {
    console.error('Failed to claim rewards:', error.message);
  }
}

Common Errors

ErrorCauseSolution
ValidationError: wallet address is requiredMissing wallet parameterProvide a valid wallet address
GizaAPIError: No rewards to claimNo accrued rewards availableWait for rewards to accumulate
GizaAPIError: Agent not activeAgent is not activeOnly active agents can claim rewards

Notes

Rewards accumulate over time from various protocols. There’s no need to claim frequently - the agent will continue earning rewards even if unclaimed.
Different protocols distribute different reward tokens. AAVE distributes AAVE tokens, Compound distributes COMP tokens, etc.

Next Steps