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

# delegatedSignSponsoredTransaction

> Sign a gas-sponsored EVM transaction intent on behalf of a delegated wallet's owner without relaying it.

`delegatedSignSponsoredTransaction` signs an EIP-712 `AuthorizedExecutions` intent for a batch of calls, auto-signing a one-time EIP-7702 authorization when the wallet is not delegated yet. The returned `SignedSponsoredTransaction` can be relayed later with `sendSponsoredTransaction` on a `DynamicEvmWalletClient`.

<Info>
  EVM Gas Sponsorship is an enterprise-only feature and works with V3 MPC embedded wallets only.
</Info>

## Function signature

```typescript theme={"system"}
delegatedSignSponsoredTransaction(
  client: DelegatedEvmWalletClient,
  params: {
    walletId: string;
    walletApiKey: string;
    keyShare: ServerKeyShare;
    walletAddress: Hex;
    userId: string;
    shareSetId?: string;
    chainId: number;
    rpcUrl?: string;
    calls: SponsoredTransactionCall[];
    authorization?: SerializedAuthorization;
    autoDelegate?: boolean;
    nonce?: bigint;
    validForSeconds?: number;
    traceContext?: TraceContext;
  }
): Promise<SignedSponsoredTransaction>
```

## Parameters

### Required

| Parameter       | Type                         | Description                                                                                                             |
| --------------- | ---------------------------- | ----------------------------------------------------------------------------------------------------------------------- |
| `client`        | `DelegatedEvmWalletClient`   | The delegated client from [`createDelegatedEvmWalletClient()`](/docs/node/reference/evm/create-delegated-evm-wallet-client). |
| `walletId`      | `string`                     | The wallet ID from the delegation webhook.                                                                              |
| `walletApiKey`  | `string`                     | The wallet-specific API key from the delegation webhook.                                                                |
| `keyShare`      | `ServerKeyShare`             | The delegated server key share from the delegation webhook.                                                             |
| `walletAddress` | `Hex`                        | The wallet's EOA address (`publicKey` from the webhook).                                                                |
| `userId`        | `string`                     | UUID of the end user who owns the wallet. Validated at runtime.                                                         |
| `chainId`       | `number`                     | Target chain ID.                                                                                                        |
| `calls`         | `SponsoredTransactionCall[]` | The batch of calls to execute.                                                                                          |

### Optional

| Parameter         | Type                      | Description                                                                                                                             |
| ----------------- | ------------------------- | --------------------------------------------------------------------------------------------------------------------------------------- |
| `shareSetId`      | `string`                  | The `shareSetId` from the `wallet.delegation.created` webhook payload. Omit and the server resolves the correct share set by wallet ID. |
| `rpcUrl`          | `string`                  | RPC URL used to read the wallet's delegation state and EOA nonce. Required on first use unless you pass a pre-signed `authorization`.   |
| `authorization`   | `SerializedAuthorization` | Pre-signed EIP-7702 authorization. Takes priority over `autoDelegate`.                                                                  |
| `autoDelegate`    | `boolean`                 | Whether to auto-sign an EIP-7702 authorization when the wallet is not delegated. Defaults to `true`.                                    |
| `nonce`           | `bigint`                  | Bitmap nonce for the signed intent. A random unused one is generated when omitted.                                                      |
| `validForSeconds` | `number`                  | How long the signed intent stays valid. Defaults to `600` (10 minutes).                                                                 |
| `traceContext`    | `TraceContext`            | Distributed tracing context.                                                                                                            |

Each entry in `calls` is a `SponsoredTransactionCall`:

| Field    | Type     | Description                                                                    |
| -------- | -------- | ------------------------------------------------------------------------------ |
| `target` | `Hex`    | The address you are sending to or the contract to call.                        |
| `data`   | `Hex`    | Calldata to execute on the target. Use `0x` for a plain native-token transfer. |
| `value`  | `bigint` | Amount of native token (in wei) to send with the call.                         |

## Returns

`Promise<SignedSponsoredTransaction>` — a JSON-serializable payload containing `calls`, `chainId`, `deadline`, `nonce`, `relayer`, `signature`, `walletAddress`, and an optional `authorization`. Pass it to `sendSponsoredTransaction` on a `DynamicEvmWalletClient` with `userId` to relay it.

## Example

```typescript theme={"system"}
import {
  createDelegatedEvmWalletClient,
  createEvmWalletClient,
  delegatedSignSponsoredTransaction,
} from '@dynamic-labs-wallet/node-evm';
import { parseEther } from 'viem';

const client = createDelegatedEvmWalletClient({
  environmentId: process.env.DYNAMIC_ENVIRONMENT_ID,
  apiKey: process.env.DYNAMIC_SERVER_API_KEY,
});

// A DynamicEvmWalletClient from createEvmWalletClient, used in the relay process
const evmClient = createEvmWalletClient({
  environmentId: process.env.DYNAMIC_ENVIRONMENT_ID,
  apiKey: process.env.DYNAMIC_SERVER_API_KEY,
});

const endUser = { id: 'user-uuid' };
const recipientAddress = '0xRecipientAddress';
// Replace with the decrypted delegation payload from your webhook handler
const credentials = {
  walletId: 'wallet-id',
  walletApiKey: 'wallet-api-key',
  keyShare: 'encrypted-key-share',
  publicKey: '0xWalletAddress',
};

const signedTransaction = await delegatedSignSponsoredTransaction(client, {
  walletId: credentials.walletId,
  walletApiKey: credentials.walletApiKey,
  keyShare: credentials.keyShare,
  walletAddress: credentials.publicKey,
  userId: endUser.id,
  chainId: 8453,
  rpcUrl: process.env.BASE_RPC_URL,
  calls: [{
    target: recipientAddress,
    data: '0x',
    value: parseEther('0.01'),
  }],
});

// Relay from another process or service
const { transactionHash } = await evmClient.sendSponsoredTransaction({
  signedTransaction,
  userId: endUser.id,
});
```

## Error handling

If signing cannot complete, `delegatedSignSponsoredTransaction` throws. Wrap the call in a `try/catch` so you can surface a message and decide what to do next.

```typescript theme={"system"}
try {
  const signedTransaction = await delegatedSignSponsoredTransaction(client, params);
} catch (error) {
  console.error('Signing failed:', error.message);
}
```

## Related

* [`delegatedSendSponsoredTransaction`](/docs/node/reference/evm/delegated-send-sponsored-transaction) — sign, relay, and wait in one call
* [`delegatedSign7702Authorization`](/docs/node/reference/evm/delegated-sign-7702-authorization) — manage the one-time EIP-7702 delegation step
* [EVM Gas Sponsorship](/docs/node/wallets/server-wallets/gas-sponsorship-evm) — full guide
