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

# Turnkey

> Use a Turnkey-managed key as the owner of a Rhinestone smart account.

Turnkey can expose a viem-compatible account backed by its signing infrastructure. This example keeps the Turnkey API private key and Rhinestone API key on the server.

## Prerequisites

* A Turnkey organization
* A Turnkey API key pair
* An Ethereum wallet created in Turnkey
* A server runtime

<Steps>
  <Step title="Install the dependencies">
    ```bash theme={null}
    npm install @turnkey/http @turnkey/api-key-stamper @turnkey/viem @rhinestone/sdk viem
    ```
  </Step>

  <Step title="Create the Turnkey signer">
    ```ts theme={null}
    import { ApiKeyStamper } from '@turnkey/api-key-stamper'
    import { TurnkeyClient } from '@turnkey/http'
    import { createAccount } from '@turnkey/viem'
    import type { Address } from 'viem'

    const turnkeyClient = new TurnkeyClient(
      { baseUrl: 'https://api.turnkey.com' },
      new ApiKeyStamper({
        apiPublicKey: process.env.TURNKEY_API_PUBLIC_KEY!,
        apiPrivateKey: process.env.TURNKEY_API_PRIVATE_KEY!,
      }),
    )

    const turnkeySigner = await createAccount({
      client: turnkeyClient,
      organizationId: process.env.TURNKEY_ORGANIZATION_ID!,
      signWith: process.env.TURNKEY_WALLET_ADDRESS as Address,
    })
    ```

    Keep the Turnkey API private key in a server-side secret manager. Do not send it to a browser or log it.
  </Step>

  <Step title="Create the Rhinestone account">
    Use explicit API-key authentication on the server:

    ```ts theme={null}
    import { RhinestoneSDK } from '@rhinestone/sdk'

    const rhinestone = new RhinestoneSDK({
      auth: {
        mode: 'apiKey',
        apiKey: process.env.RHINESTONE_API_KEY!,
      },
    })

    const account = await rhinestone.createAccount({
      owners: {
        type: 'ecdsa',
        accounts: [turnkeySigner],
      },
    })

    console.log(account.getAddress())
    ```
  </Step>
</Steps>

If Turnkey signing happens in a browser, use Turnkey's browser-safe authentication flow and configure Rhinestone with short-lived JWTs as described in [security](/wallets/custom-signer/integration/security). Never bundle either service's private credential.

For sponsored transactions, follow [sponsorship setup](/transactions/sponsorship/set-up). For the transaction lifecycle, continue to [send a transaction](/transactions/multichain/send-a-transaction).

See the [Turnkey viem documentation](https://docs.turnkey.com/sdks/web3/viem) for wallet and policy configuration.
