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

# claimEarnRewards

> Prepares and executes a claim of accrued Earn vault rewards with an SVM wallet

## Function Signature

```typescript theme={"system"}
claimEarnRewards(params: {
  vaultId: string;
  walletMetadata: WalletMetadata;
  password?: string;
  externalServerKeyShares?: ServerKeyShare[];
  sponsored?: boolean;
  rpcUrl?: string;
  chainId?: string;
  context?: SignMessageContext;
  onStepChange?: (step: EarnExecutionStep) => void;
  onTransactionStepChange?: (step: EarnTransactionStepProgress) => void;
  traceContext?: TraceContext;
}): Promise<EarnTransactionResult>
```

## Description

Prepares and executes a claim of every reward the wallet has accrued in an [Earn](https://www.dynamic.xyz/docs/earn/overview.md) vault: it builds the payload with [`prepareClaimRewards`](https://www.dynamic.xyz/docs/node/reference/earn/prepare-claim-rewards) and executes its ordered Solana transaction sequence with [`executeEarnTransaction`](https://www.dynamic.xyz/docs/node/reference/svm/execute-earn-transaction). Rewards are supported only for vaults from some providers; for any other provider the API rejects the request with an HTTP 400 error. See [Provider support](https://www.dynamic.xyz/docs/earn/overview.md#provider-support).

## Parameters

### Required Parameters

* **`vaultId`** (`string`): The vault identifier from [`listVaults`](https://www.dynamic.xyz/docs/node/reference/earn/list-vaults).
* **`walletMetadata`** ([`WalletMetadata`](https://www.dynamic.xyz/docs/node/reference/types/wallet-metadata)): Non-sensitive wallet metadata persisted from `createWalletAccount()` / `importPrivateKey()`. Its `chainName` must be `'SVM'`.

### Optional Parameters

* **`password`** (`string`): Required if the wallet was created with `backUpToDynamic: true`. Used for backup decryption when `externalServerKeyShares` is not provided.
* **`externalServerKeyShares`** ([`ServerKeyShare[]`](https://www.dynamic.xyz/docs/node/reference/types/server-key-share)): Caller-supplied plaintext shares.
* **`sponsored`** (`boolean`): When `true`, sponsors every transaction in the sequence. See [SVM Gas Sponsorship](https://www.dynamic.xyz/docs/node/wallets/server-wallets/gas-sponsorship-svm.md).
* **`rpcUrl`** (`string`): Solana RPC endpoint. Defaults to the public cluster for the payload's `chainId` (101 mainnet, 103 devnet).
* **`chainId`** (`string`): The Solana chain identifier.
* **`context`** (`SignMessageContext`): Signing context forwarded to the transaction signer.
* **`onStepChange`** (`(step: EarnExecutionStep) => void`): Reports `transaction` once per transaction in the sequence.
* **`onTransactionStepChange`** (`(step: EarnTransactionStepProgress) => void`): Invoked as each transaction is about to be signed, with its `ordinal`, the `total`, and an optional `label`.
* **`traceContext`** (`TraceContext`): Trace context forwarded to the Dynamic API.

## Returns

* **`Promise<EarnTransactionResult>`**: An object with `transactionHash`, the signature of the last transaction in the sequence.

## Example

```typescript theme={"system"}
import { authenticatedSvmClient } from './client';

const svmClient = await authenticatedSvmClient();

const { transactionHash } = await svmClient.claimEarnRewards({
  vaultId: 'kamino-usdc-steakhouse',
  walletMetadata,
  externalServerKeyShares,
  password: 'user-password',
});
```

## Error Handling

Fails with an HTTP 403 error when Earn is not enabled for your environment, an HTTP 400 error when the vault's provider does not support rewards, or an HTTP 422 error when the wallet has nothing to claim. Throws when `walletMetadata.chainName` is not `'SVM'`, when the payload carries no `transactions` sequence, or when a sequence step expires or fails; see [`executeEarnTransaction`](https://www.dynamic.xyz/docs/node/reference/svm/execute-earn-transaction) for `EarnSolanaStepError`.

## See Also

* [Earn](https://www.dynamic.xyz/docs/node/earn.md)
* [getRewards](https://www.dynamic.xyz/docs/node/reference/earn/get-rewards.md)
* [executeEarnTransaction](https://www.dynamic.xyz/docs/node/reference/svm/execute-earn-transaction.md)


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