> ## 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.

# executeEarnTransaction

> Executes an Earn signing payload with an EVM wallet

## Function Signature

```typescript theme={"system"}
executeEarnTransaction(params: {
  signingPayload: EarnSigningPayload;
  walletMetadata: WalletMetadata;
  password?: string;
  externalServerKeyShares?: ServerKeyShare[];
  sponsored?: boolean;
  chain?: Chain;
  rpcUrl?: string;
  onStepChange?: (step: EarnExecutionStep) => void;
  traceContext?: TraceContext;
}): Promise<EarnTransactionResult>
```

## Description

Executes an [Earn](https://www.dynamic.xyz/docs/earn/overview.md) signing payload returned by the `client.earn.prepare*` methods, signing and sending it with the wallet identified by `walletMetadata`. When the payload carries an `evmApproval` and the current allowance is short, the ERC-20 approval is sent first and waited on before the vault transaction. With `sponsored: true`, the approval and vault call are relayed as one gasless batch through Dynamic gas sponsorship.

For a single call that prepares and executes, use [`depositToEarnVault`](https://www.dynamic.xyz/docs/node/reference/evm/deposit-to-earn-vault), [`withdrawFromEarnVault`](https://www.dynamic.xyz/docs/node/reference/evm/withdraw-from-earn-vault), or [`claimEarnRewards`](https://www.dynamic.xyz/docs/node/reference/evm/claim-earn-rewards).

## Parameters

### Required Parameters

* **`signingPayload`** (`EarnSigningPayload`): The payload from [`prepareDeposit`](https://www.dynamic.xyz/docs/node/reference/earn/prepare-deposit), [`prepareWithdrawal`](https://www.dynamic.xyz/docs/node/reference/earn/prepare-withdrawal), or [`prepareClaimRewards`](https://www.dynamic.xyz/docs/node/reference/earn/prepare-claim-rewards).
* **`walletMetadata`** ([`WalletMetadata`](https://www.dynamic.xyz/docs/node/reference/types/wallet-metadata)): Non-sensitive wallet metadata persisted from `createWalletAccount()` / `importPrivateKey()`. Its `chainName` must be `'EVM'`.

### 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. If omitted, the SDK recovers from backup using `password`.
* **`sponsored`** (`boolean`): When `true`, relays the approval and vault call as one gasless batch. See [EVM Gas Sponsorship](https://www.dynamic.xyz/docs/node/wallets/server-wallets/gas-sponsorship-evm.md).
* **`chain`** (`Chain`): The viem chain for the vault. Its `id` must match the payload's `chainId`. When omitted, the chain is built from the payload's `chainId` and `rpcUrl`, so one of `chain` or `rpcUrl` is required.
* **`rpcUrl`** (`string`): RPC endpoint for the vault's chain. Also used by the relayer to read the wallet's on-chain state when `sponsored` is set.
* **`onStepChange`** (`(step: EarnExecutionStep) => void`): Reports `approval` then `transaction` as execution proceeds.
* **`traceContext`** (`TraceContext`): Trace context forwarded to the Dynamic API.

## Returns

* **`Promise<EarnTransactionResult>`**: An object with `transactionHash`, the hash of the vault transaction.

## Example

```typescript theme={"system"}
import { authenticatedEvmClient } from './client';
import { base } from 'viem/chains';

const evmClient = await authenticatedEvmClient();

const signingPayload = await evmClient.earn.prepareDeposit({
  vaultId: 'steakhouse-prime-usdc',
  ownerAddress: walletMetadata.accountAddress,
  amount: '12.5',
});

const { transactionHash } = await evmClient.executeEarnTransaction({
  signingPayload,
  walletMetadata,
  externalServerKeyShares,
  password: 'user-password',
  chain: base,
  onStepChange: (step) => console.log(`Step: ${step}`),
});
```

## Error Handling

Throws when `walletMetadata.chainName` is not `'EVM'`, when the payload carries no `evmTransaction`, when `chain.id` mismatches the payload's `chainId`, when neither `chain` nor `rpcUrl` is given, or when the approval or vault transaction reverts.

## See Also

* [Earn](https://www.dynamic.xyz/docs/node/earn.md)
* [depositToEarnVault](https://www.dynamic.xyz/docs/node/reference/evm/deposit-to-earn-vault.md)
* [withdrawFromEarnVault](https://www.dynamic.xyz/docs/node/reference/evm/withdraw-from-earn-vault.md)
* [claimEarnRewards](https://www.dynamic.xyz/docs/node/reference/evm/claim-earn-rewards.md)


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