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

# generateTraceId

> Generates a lowercased UUID v4 for use as an X-Portal-Trace-Id value.

**Function Signature**

```swift theme={null}
public func generateTraceId() -> String
```

**Description**

Generates a trace ID for request correlation. This is a free function on the `PortalSwift` module — it is not a method on `Portal`, so no wallet or client is required to call it.

The returned value is a lowercased UUID v4. It is the same generator the SDK uses internally when you do not supply a trace ID, so IDs you generate with it match the format Portal's logs are indexed by.

Pass the result to `RequestOptions(traceId:)`, `SendAssetParams(traceId:)`, or `portal.rawSign(message:chainId:signatureApprovalMemo:traceId:)` to have the SDK send it as the `X-Portal-Trace-Id` header.

**Parameters**

* None.

**Returns**

* `String` — a lowercased UUID v4, for example `"3f2b8a1c-9d4e-4c7f-b6a2-15e8d0c34f9b"`.

**Throws**

* Nothing. This function cannot fail.

**Related Constant**

```swift theme={null}
public let PORTAL_TRACE_ID_HEADER = "X-Portal-Trace-Id"
```

The header name the SDK uses when attaching a trace ID. It is exposed so you can reference the header in your own networking code or test assertions rather than hard-coding the string.

**Example Usage**

```swift theme={null}
import PortalSwift

do {
    let portal = try Portal(
      "YOUR_CLIENT_API_KEY",
      withRpcConfig: ["eip155:11155111": "https://sepolia.infura.io/v3/YOUR_INFURA_KEY"]
    )

    // Generate one trace ID for the whole user-facing action
    let traceId = generateTraceId()
    print("Sending — \(PORTAL_TRACE_ID_HEADER): \(traceId)")

    let response = try await portal.sendAsset(
      chainId: "eip155:11155111",
      params: SendAssetParams(
        to: "0x742d35Cc6634C0532925a3b844Bc9e7595f0bEb",
        amount: "0.01",
        token: "NATIVE",
        traceId: traceId
      )
    )

    print("Submitted — traceId: \(traceId), txHash: \(response.txHash)")
} catch {
    print("Failed: \(error)")
}
```

**Notes**

* Generate one trace ID per user-facing action, not per request. Every request the operation makes reuses the ID you pass, which is what makes it useful for correlation.
* If you omit a trace ID, the SDK generates one per request. Those IDs are never returned to you, so supply your own whenever you want to correlate with your logs.
* MPC operations (generate, backup, recover, eject) and `upgradeTo7702` generate their own trace IDs and do not accept one.

**Related Documentation**

* [Request tracing](../guide/request-tracing)
* [Send tokens](../guide/send-tokens)
* [Configure log level](../guide/configure-log-level)
