> **Can't find what you're looking for?** Use `search_docs` on the docs MCP server at `https://www.openfort.io/api/mcp` to find what you need.
>
> **Have feedback?** Use `submit_feedback` on the same MCP server.

# Sign a backend-created transaction

This is the **advanced, backend-orchestrated** way to send a transaction. Your server creates a [transaction](https://www.openfort.io/docs/products/embedded-wallet/javascript/smart-wallet/send) with `POST /v2/transactions`, returns its `id` and the hash that needs signing, and the client signs that hash and submits it. Openfort then broadcasts the transaction.

:::tip
Most apps don't need this. To send a transaction directly from the client, use the [Ethereum provider's `eth_sendTransaction`](https://www.openfort.io/docs/products/embedded-wallet/swift/wallet/send) — it's a single call with no server round-trip. Reach for backend-created transactions when your backend owns transaction creation, fee sponsorship selection, or signing orchestration.
:::

## How it works

1. Your **backend** creates a transaction via `POST /v2/transactions` (or `openfort.transactions.create` in the Node SDK). The response has `status: "awaiting_signature"`, an `id` (`tin_...`) and a `nextAction.hash`.
2. Your **client** calls `sendTransactionSignatureRequest` with the id and hash. The SDK signs the hash with the embedded wallet and submits it to `POST /v2/transactions/{id}/signature`.
3. The returned transaction carries the `receipt` once mined, or `status: "submitted"` if you asked for an optimistic response.

## Usage

```swift
do {
    let params = OFSendTransactionSignatureRequestParams(
        transactionId: transactionId, // "tin_..." from your backend
        hash: nextActionHash,         // nextAction.hash from your backend; the SDK signs it
        optimistic: false
    )
    let transaction = try await OFSDK.shared.sendTransactionSignatureRequest(params: params)
    print("Status: \(transaction?.status.rawValue ?? "?")")
    print("Transaction hash: \(transaction?.receipt?.transactionHash ?? "?")")
} catch {
    print("Failed to submit transaction: \(error.localizedDescription)")
}
```

Pass `signature` instead of `hash` when the signature was produced elsewhere, for example by a session key held in your app.

:::note
Set `optimistic: true` to get a result back as soon as the transaction is broadcast (`status: "submitted"`) — useful for snappy UI, but the transaction can still fail onchain afterward. Leave it `false` (or `nil`) to wait for the receipt.
:::

## Parameters

```swift
public struct OFSendTransactionSignatureRequestParams: OFCodableSendable {
    public let transactionId: String   // tin_...
    public let hash: String?           // nextAction.hash, signed by the SDK when signature is nil
    public let signature: String?      // a ready-made signature
    public let optimistic: Bool?
}
```

## Returns

Returns an optional `OFTransactionResponse`:

```swift
public struct OFTransactionResponse: OFCodableSendable {
    public let id: String
    public let object: String                  // "transaction"
    public let createdAt: Int
    public let updatedAt: Int
    public let chainId: Int
    public let status: OFTransactionStatus     // awaitingSignature, submitted, succeeded, reverted, failed, expired
    public let accountId: String
    public let walletId: String?
    public let feeSponsorshipId: String?
    public let calls: [OFTransactionCall]?
    public let execution: OFTransactionExecution?
    public let nextAction: OFSignHashAction?    // present while status is awaitingSignature
    public let receipt: OFTransactionReceipt?   // present once the transaction was mined
    public let timeline: [OFTransactionTimelineEntry]?
    public let costUsd: String?
}
```

`receipt.transactionHash` is the onchain hash. For a `reverted` or `failed` transaction, `receipt.error` explains why. An `expired` transaction was never mined, so it has no `receipt`.

## Next steps

* [Send a transaction](https://www.openfort.io/docs/products/embedded-wallet/swift/wallet/send) — the recommended client-side flow.
* [Sponsored (gasless) transactions](https://www.openfort.io/docs/products/embedded-wallet/swift/wallet/eip-7702)
