> ## 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](https://docs.dynamic.xyz/docs/earn/overview.md#key-concepts) in an [Earn](https://docs.dynamic.xyz/docs/earn/overview.md) vault, then signs and sends the transaction for you. You only pass a `vaultId`, and 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.

This function currently supports vaults from these providers: Morpho and Kamino. For a vault from any other provider, such as an Aave vault, the call rejects because the API responds with an HTTP 400 error, so check the vault's `provider` from [`getYieldDetails`](https://docs.dynamic.xyz/docs/javascript/reference/client/get-yield-details) first.

A Morpho claim is a single EVM transaction. A Kamino claim is an ordered sequence of Solana transactions, one for each of the vault's reward farms that has something pending, so a user can be asked to approve more than one signature. `claimYieldRewards` signs, sends, and confirms each transaction before it starts the next, and `onTransactionStepChange` reports progress through the sequence. If a later transaction fails or expires, the earlier ones have already confirmed, so read [`getYieldRewards`](https://docs.dynamic.xyz/docs/javascript/reference/client/get-yield-rewards) again before retrying.

For a supported vault, the call rejects when there's nothing claimable for this vault right now, either because no reward campaign is active or because everything has already been claimed. Check [`getYieldRewards`](https://docs.dynamic.xyz/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`](https://docs.dynamic.xyz/docs/javascript/reference/client/list-yield-vaults). |
| `walletAccount` | `WalletAccount` | The wallet account whose accrued rewards are being claimed. Must be an EVM wallet account for an EVM vault, or a Solana wallet account for a Solana vault. |
| `onStepChange` | `(step: 'approval' \| 'transaction') => void` (optional) | Callback invoked when the execution step changes. `'approval'` never fires for a claim. For a Solana vault, `'transaction'` fires once per transaction in the sequence. |
| `onTransactionStepChange` | `(progress: YieldTransactionProgress) => void` (optional) | Callback invoked as each transaction of a multi-transaction claim begins, which only happens for Solana vaults. `progress` has `ordinal` (zero-based position), `total` (number of transactions), and an optional `label` such as `'claim-vault-farm'`. |
| `client` | `DynamicClient` (optional) | The Dynamic client instance. Only required when using multiple Dynamic clients. |

## Returns

`Promise<{ transactionHash: string }>` - The hash of the claim transaction. For a Solana vault, this is the signature of the last transaction in the sequence.

> [!WARNING]
>
> For an EVM vault, 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.

## Waiting for confirmation

For an EVM vault, `transactionHash` is returned as soon as the claim is broadcast to the network, and 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');
}
```

### Solana vaults

For a Solana vault, `claimYieldRewards` polls each transaction until it reaches the `confirmed` commitment level before it starts the next one, and it resolves only after the last transaction has confirmed. A resolved call therefore means every transaction in the sequence landed, although a `confirmed` transaction is not yet `finalized`. You do not need to wait for a receipt the way you do for an EVM vault.

## 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 });
}
```

### Follow a multi-transaction Solana claim

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

const { transactionHash } = await claimYieldRewards({
  vaultId: 'kamino-usdc-steakhouse',
  walletAccount: solanaWalletAccount,
  onTransactionStepChange: ({ ordinal, total, label }) => {
    console.log(`Approve transaction ${ordinal + 1} of ${total}: ${label ?? 'claim'}`);
  },
});
```

## Supported Chains

`claimYieldRewards` supports EVM wallet accounts for EVM vaults and Solana wallet accounts for Solana vaults. Calling it with a wallet account from a chain family that does not implement the underlying `executeYieldTransaction` method throws a `WalletProviderMethodUnavailableError`. A wallet account from the other chain family than the vault's is rejected with an HTTP 400 error.

## 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`](https://docs.dynamic.xyz/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`](https://docs.dynamic.xyz/docs/javascript/reference/client/get-yield-rewards) - Check accrued rewards before claiming
* [`depositToYieldVault`](https://docs.dynamic.xyz/docs/javascript/reference/client/deposit-to-yield-vault) - Deposit into a vault


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.