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

# EVM signing

> Parse the JSON unsignedTransaction and sign it with ethers.js or viem without changing its target, data or value.

On EVM networks, `unsignedTransaction` is a JSON string. Parse it, pass `to`, `data` and `value` to your signer unchanged, sign, and submit. This applies to Ethereum, Base, Arbitrum, Optimism, Polygon, and every other EVM-compatible network Yield.xyz supports.

## Prerequisites

* An action's `transactions[]`; see [Transaction signing](https://docs.yield.xyz/guides/transaction-signing/index.md) for decoding by chain family and [Enter and exit flows](https://docs.yield.xyz/guides/earn/enter-exit-flows.md) for the request and poll loop.
* An EOA private key (server-side) or a connected browser wallet, for the target network.

## The unsignedTransaction shape

```json theme={null}
{
  "to": "0xContractAddress",
  "data": "0xEncodedCallData",
  "gasLimit": "0xdd94",
  "nonce": 42,
  "chainId": 8453,
  "maxFeePerGas": "0x02627940",
  "maxPriorityFeePerGas": "0x00",
  "type": 2
}
```

| Field | Type | Notes |
| - | - | - |
| `to` | string | Contract or recipient address |
| `data` | string | Hex-encoded calldata |
| `value` | string, hex | Present only for native-token transfers; absent for ERC-20 and other token operations |
| `gasLimit` | string, hex | |
| `type` | number | `0` for a legacy transaction (paired with `gasPrice`), `2` for EIP-1559 (paired with `maxFeePerGas` and `maxPriorityFeePerGas`) |
| `gasPrice` | string, hex | Only on a `type: 0` transaction |
| `maxFeePerGas`, `maxPriorityFeePerGas` | string, hex | Only on a `type: 2` transaction |
| `nonce` | number | |
| `chainId` | number | Must match the network your signer is connected to |

> [!WARNING]
>
> Never change `to`, `data` or `value`. When an action returns one transaction, also keep its gas values and `nonce` as returned. When an action returns several transactions, every step carries the nonce from when the action was built, so let your signer assign the nonce (or read the wallet's pending transaction count) for each step after the first. Re-estimate gas only where a guide tells you to, for example the `REDEEM` of a first [Zama private exit](https://docs.yield.xyz/guides/zama/index.md#8-exit-privately). Renaming a key so a library accepts the object, for example `gasLimit` to `gas`, is not a value change and is fine; changing what any field points to or how much it's worth is not.

## Sign and submit

> [tab] ethers.js v6
>
> ```typescript theme={null}
> import { ethers } from "ethers";
>
> const provider = new ethers.JsonRpcProvider(process.env.RPC_URL);
> const wallet = new ethers.Wallet(process.env.EVM_PRIVATE_KEY!, provider);
>
> for (const [index, tx] of transactions.entries()) {
>   const parsed = JSON.parse(tx.unsignedTransaction as string);
>
>   // Every step carries the nonce from when the action was built.
>   // After the first step, drop it so ethers reads the wallet's pending nonce.
>   if (index > 0) delete parsed.nonce;
>
>   // ethers maps gasLimit and the gas fields automatically; pass the other fields through as-is.
>   const response = await wallet.sendTransaction(parsed);
>   const receipt = await response.wait();
>
>   await fetch(`https://api.yield.xyz/v1/transactions/${tx.id}/submit-hash`, {
>     method: "PUT",
>     headers: { "x-api-key": process.env.YIELD_API_KEY!, "content-type": "application/json" },
>     body: JSON.stringify({ hash: receipt!.hash }),
>   });
> }
> ```

> [tab] viem
>
> ```typescript theme={null}
> import { createWalletClient, http } from "viem";
> import { privateKeyToAccount } from "viem/accounts";
> import { base } from "viem/chains";
>
> const account = privateKeyToAccount(process.env.EVM_PRIVATE_KEY as `0x${string}`);
> const client = createWalletClient({ account, chain: base, transport: http(process.env.RPC_URL) });
>
> for (const tx of transactions) {
>   const parsed = JSON.parse(tx.unsignedTransaction as string);
>
>   // viem uses `gas`, not `gasLimit`; re-key without changing the value.
>   const hash = await client.sendTransaction({
>     to: parsed.to,
>     data: parsed.data,
>     ...(parsed.value !== undefined ? { value: BigInt(parsed.value) } : {}),
>     gas: BigInt(parsed.gasLimit),
>     ...(parsed.type === 2
>       ? {
>           maxFeePerGas: BigInt(parsed.maxFeePerGas),
>           maxPriorityFeePerGas: BigInt(parsed.maxPriorityFeePerGas),
>         }
>       : { gasPrice: BigInt(parsed.gasPrice) }),
>   });
>
>   await fetch(`https://api.yield.xyz/v1/transactions/${tx.id}/submit-hash`, {
>     method: "PUT",
>     headers: { "x-api-key": process.env.YIELD_API_KEY!, "content-type": "application/json" },
>     body: JSON.stringify({ hash }),
>   });
> }
> ```

> [tab] wagmi (browser)
>
> wagmi's `useWalletClient` only returns a client for a chain the connected wallet is currently on. Switch chains before sending, using the transaction's own `chainId`:
>
> ```typescript theme={null}
> import { switchChain, getWalletClient } from "@wagmi/core";
> import { config } from "./wagmi-config";
>
> const parsed = JSON.parse(tx.unsignedTransaction as string);
> const chainId = Number(parsed.chainId);
>
> await switchChain(config, { chainId });
> const walletClient = await getWalletClient(config, { chainId });
>
> const hash = await walletClient.sendTransaction({
>   to: parsed.to,
>   data: parsed.data,
>   ...(parsed.value !== undefined ? { value: BigInt(parsed.value) } : {}),
>   gas: BigInt(parsed.gasLimit),
>   ...(parsed.type === 2
>     ? {
>         maxFeePerGas: BigInt(parsed.maxFeePerGas),
>         maxPriorityFeePerGas: BigInt(parsed.maxPriorityFeePerGas),
>       }
>     : { gasPrice: BigInt(parsed.gasPrice) }),
> });
> ```
>
> `chainId` must also be in your wagmi `config.chains`, or the switch fails. Submit the resulting `hash` through `submit-hash` as in the other tabs.

Alternatively, hand Yield.xyz the signed transaction and let it broadcast: `POST /v1/transactions/{tx.id}/submit` with `{ "signedTransaction": await wallet.signTransaction(parsed) }`. Use one path per transaction, never both. See [Transaction signing](https://docs.yield.xyz/guides/transaction-signing/index.md#sign-and-choose-a-submission-path) for when each fits.

## Batched execution

When a yield's `mechanics.arguments.enter.fields` (or `.exit.fields`) offers `executionMode`, you can pass `executionMode: "batched"` instead of the default `"individual"`. A batched action collapses what would otherwise be an `APPROVAL` plus a `SUPPLY`, `STAKE`, or similar call into a single `BATCH` transaction, whose `unsignedTransaction` is a JSON array of calls rather than one transaction object:

```json theme={null}
[
  { "to": "0xTokenAddress", "data": "0xApproveCalldata", "value": "0" },
  { "to": "0xPoolAddress", "data": "0xSupplyCalldata", "value": "0" }
]
```

Each call has only `to`, `data`, and `value`; there is no `gasLimit`, `nonce`, or `chainId` to sign against, because the batch is meant for a smart account or wallet that executes all calls atomically (for example EIP-5792 `wallet_sendCalls`), not a single EOA-signed transaction. Sign it with whatever batch-call method your smart account SDK exposes, then submit the resulting hash the same way as any other transaction.

## Next steps

> [card] [Transaction signing](https://docs.yield.xyz/guides/transaction-signing/index.md)
>
> The shared contract across chain families: decode, validate, sign, submit.

> [card] [Enter and exit flows](https://docs.yield.xyz/guides/earn/enter-exit-flows.md)
>
> Build the request, branch on executionPattern, and poll to a terminal status.


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