> ## Documentation Index
> Fetch the complete documentation index at: https://docs.dynamic.xyz/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# claimYieldRewards

# claimYieldRewards

Claims a wallet's accrued bonus [rewards](/docs/overview/yield#key-concepts) in an [Earn](/docs/overview/yield) vault, then signs and sends the transaction for you. You only pass a `vaultId` — Dynamic resolves everything else needed to process the claim.

This is separate from base yield, which never needs claiming. Rewards are an optional bonus some vaults pay out in addition to base yield, and they sit unclaimed until you call this function.

Rejects when there's nothing claimable for this vault right now — no active reward campaign, or everything has already been claimed. Check [`getYieldRewards`](/docs/javascript/reference/client/get-yield-rewards) first, and only show a claim action when it returns a non-zero `accrued` amount.

## Usage

```javascript theme={"system"}
import { claimYieldRewards } from '@dynamic-labs-sdk/client';

const { transactionHash } = await claimYieldRewards({
  vaultId: 'fb-eth-galaxy-usdc-fw-01',
  walletAccount,
});

console.log('Transaction hash:', transactionHash);
```

## Parameters

| Parameter       | Type                       | Description                                                                                        |
| --------------- | -------------------------- | -------------------------------------------------------------------------------------------------- |
| `vaultId`       | `string`                   | Opaque vault identifier, from [`listYieldVaults`](/docs/javascript/reference/client/list-yield-vaults). |
| `walletAccount` | `WalletAccount`            | The wallet account whose accrued rewards are being claimed. Must be an EVM wallet account.         |
| `client`        | `DynamicClient` (optional) | The Dynamic client instance. Only required when using multiple Dynamic clients.                    |

## Returns

`Promise<{ transactionHash: string }>` - The hash of the claim transaction.

<Warning>
  A resolved `claimYieldRewards` call means the claim transaction was **sent**, not that it finished. See [Waiting for confirmation](#waiting-for-confirmation) before showing a success state to the user.
</Warning>

## Waiting for confirmation

`transactionHash` is returned as soon as the claim is broadcast to the network — it can still fail or revert after that. Wait for a receipt before telling the user their claim succeeded:

```typescript theme={"system"}
import { claimYieldRewards, getActiveNetworkData } from '@dynamic-labs-sdk/client';
import { createPublicClientFromNetworkData } from '@dynamic-labs-sdk/evm/viem';

const { transactionHash } = await claimYieldRewards({ vaultId, walletAccount });

const { networkData } = await getActiveNetworkData({ walletAccount });
const publicClient = createPublicClientFromNetworkData({ networkData });

const receipt = await publicClient.waitForTransactionReceipt({
  hash: transactionHash as `0x${string}`,
});

if (receipt.status !== 'success') {
  throw new Error('Claim transaction reverted');
}
```

## Examples

### Only offer claim when something is claimable

```javascript theme={"system"}
import { claimYieldRewards, getYieldRewards } from '@dynamic-labs-sdk/client';

async function claimIfAvailable(vaultId, walletAccount) {
  const rewards = await getYieldRewards({ vaultId, walletAccount });
  const claimable = rewards.some(
    (reward) => reward.accrued && reward.accrued !== '0'
  );

  if (!claimable) {
    return null;
  }

  return claimYieldRewards({ vaultId, walletAccount });
}
```

## Supported Chains

`claimYieldRewards` only supports EVM wallet accounts — vault actions are EVM-only today. Calling it with a non-EVM `walletAccount` throws a `WalletProviderMethodUnavailableError`, since only EVM wallet providers implement the underlying `executeYieldTransaction` method.

## React

This hides the button entirely when there's nothing to claim, rather than showing it and reporting the resulting rejection as a normal outcome:

```tsx theme={"system"}
import { useClaimYieldRewards, useGetYieldRewards } from '@dynamic-labs-sdk/react-hooks';

function ClaimButton({ vaultId, walletAccount }) {
  const { data: rewards = [] } = useGetYieldRewards({ vaultId, walletAccount });
  const { mutate: claim, isPending, error } = useClaimYieldRewards();

  const claimable = rewards.some((reward) => reward.accrued && reward.accrued !== '0');
  if (!claimable) {
    return null;
  }

  return (
    <>
      <button
        onClick={() => claim({ vaultId, walletAccount })}
        disabled={isPending}
      >
        Claim rewards
      </button>
      {error && <p>Something went wrong claiming your rewards. Please try again.</p>}
    </>
  );
}
```

`useClaimYieldRewards` invalidates [`useGetYieldRewards`](/docs/javascript/reference/client/get-yield-rewards) on success, so rewards refetch automatically. That refetch can still briefly show the old amount, since the claim transaction may not be mined yet — see [Waiting for confirmation](#waiting-for-confirmation).

## Related

* [`getYieldRewards`](/docs/javascript/reference/client/get-yield-rewards) - Check accrued rewards before claiming
* [`depositToYieldVault`](/docs/javascript/reference/client/deposit-to-yield-vault) - Deposit into a vault
