delegatedSignSponsoredTransaction - Dynamic

delegatedSignSponsoredTransaction

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.

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

Function signature

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().
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

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,
});

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

const endUser = { id: 'user-uuid' };
const recipientAddress = '0xRecipientAddress';
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'),
  }],
});

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.

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