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

# Sign a transaction

> Sign an Ethereum transaction with a 0xkey wallet account and broadcast it with your own RPC provider.

03 / QUICKSTART

You send 0xkey an **unsigned** transaction and the account address to sign with. The enclave checks your [policies](https://docs.0xkey.io/policies/overview.md), signs, and returns the signed transaction. You broadcast it yourself.

**Before you start:** [create a wallet](https://docs.0xkey.io/getting-started/create-wallet.md) and note its Ethereum address.

## 1. Build the unsigned transaction

Use any Ethereum library. The result is an RLP-encoded, hex-encoded unsigned transaction.

```ts theme={"theme":{"light":"github-light","dark":"github-dark"}}
import { serializeTransaction, parseEther, parseGwei } from "viem";

const unsignedTransaction = serializeTransaction({
  type: "eip1559",
  chainId: 11155111, // Sepolia
  nonce: 0,          // read the account's nonce from your RPC provider
  to: "<destination address>",
  value: parseEther("0.001"),
  gas: 21000n,
  maxFeePerGas: parseGwei("30"),
  maxPriorityFeePerGas: parseGwei("1"),
});
```

## 2. Sign it

```ts TypeScript theme={"theme":{"light":"github-light","dark":"github-dark"}}
// `api` and `addresses` come from the previous step.
const { signedTransaction } = await api.signTransaction({
  signWith: addresses[0],
  unsignedTransaction,
  type: "TRANSACTION_TYPE_ETHEREUM",
});
```

```swift Swift theme={"theme":{"light":"github-light","dark":"github-dark"}}
let signed = try await ctx.signTransaction(
    signWith: address,
    unsignedTransaction: unsignedHex,
    type: .TRANSACTION_TYPE_ETHEREUM)
```

```kotlin Kotlin theme={"theme":{"light":"github-light","dark":"github-dark"}}
import io.zeroxkey.types.V1TransactionType

val signed = ZeroXKeyContext.signTransaction(
    signWith = address,
    unsignedTransaction = unsignedHex,
    type = V1TransactionType.TRANSACTION_TYPE_ETHEREUM,
)
```

```bash cURL theme={"theme":{"light":"github-light","dark":"github-dark"}}
BODY='{
  "type": "ACTIVITY_TYPE_SIGN_TRANSACTION_V2",
  "timestampMs": "'"$(date +%s)000"'",
  "organizationId": "'"$ZEROXKEY_ORG_ID"'",
  "parameters": {
    "signWith": "<your Ethereum address>",
    "unsignedTransaction": "<unsigned transaction hex>",
    "type": "TRANSACTION_TYPE_ETHEREUM"
  }
}'

curl -s https://api.0xkey.io/public/v1/submit/sign_transaction \
  -H "Content-Type: application/json" \
  -H "X-Stamp: $STAMP" \
  -d "$BODY"
```

With cURL, the result is in `activity.result.signTransactionResult.signedTransaction`.

> [!TIP]
>
> Use transaction signing (`sign_transaction`) rather than raw-payload signing for transactions. Transaction-field policies such as `eth.tx.to` and `eth.tx.value` are evaluated on transaction-signing activities, so this is what lets you restrict where funds can go.

## 3. Broadcast

```ts theme={"theme":{"light":"github-light","dark":"github-dark"}}
import { createPublicClient, http } from "viem";
import { sepolia } from "viem/chains";

const client = createPublicClient({ chain: sepolia, transport: http("<your RPC URL>") });
const raw = signedTransaction.startsWith("0x") ? signedTransaction : `0x${signedTransaction}`;
const hash = await client.sendRawTransaction({ serializedTransaction: raw as `0x${string}` });
```

For Solana and Tron, set `type` to `TRANSACTION_TYPE_SOLANA` or `TRANSACTION_TYPE_TRON` and see [Networks](https://docs.0xkey.io/networks/overview.md).

## Next

> [card] [Add a policy](https://docs.0xkey.io/getting-started/add-policy.md)
>
> Restrict which addresses an API user can send to


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