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

# Turnkey Tutorial

> Use a Turnkey EVM account to authorize Glider B2B API enrollment.

A Turnkey Viem account can create the EIP-191 signature for the default EVM
`ECDSA` enrollment path.

## Create the Viem account

```javascript theme={null}
import { createAccount } from "@turnkey/viem";
import { createWalletClient, http } from "viem";
import { mainnet } from "viem/chains";

const account = await createAccount({
  client: turnkeyClient,
  organizationId,
  signWith: ownerAddress,
  ethereumAddress: ownerAddress,
});

const walletClient = createWalletClient({
  account,
  chain: mainnet,
  transport: http(RPC_URL),
});
```

Configure Turnkey authentication and stamping for the security model of your
application.

## Prepare and sign enrollment

On your backend, call `POST /v2/enroll/signature`:

```javascript theme={null}
const ownerAccountId = `eip155:0:${ownerAddress.toLowerCase()}`;
const chainIds = [1];

const response = await fetch(
  "https://api.glider.fi/v2/enroll/signature",
  {
    method: "POST",
    headers: {
      "content-type": "application/json",
      "x-api-key": process.env.GLIDER_API_KEY,
    },
    body: JSON.stringify({
      ownerAccountId,
      strategyId,
      chainIds,
      accountType: "ECDSA",
    }),
  },
);

const { data: prepared } = await response.json();
```

Sign the raw payload:

```javascript theme={null}
const signature = await walletClient.signMessage({
  account,
  message: { raw: prepared.message.raw },
});
```

## Complete enrollment

Send the unchanged stage-1 fields and the signature from your backend:

```javascript theme={null}
const response = await fetch("https://api.glider.fi/v2/enroll", {
  method: "POST",
  headers: {
    "content-type": "application/json",
    "x-api-key": process.env.GLIDER_API_KEY,
  },
  body: JSON.stringify({
    ownerAccountId,
    strategyId,
    chainIds,
    accountType: prepared.accountType,
    accountIndex: prepared.accountIndex,
    agentAccountId: prepared.agentAccountId,
    flowId: prepared.flowId,
    signature,
    portfolioName,
  }),
});

const { data: portfolio } = await response.json();
```

The B2B API returns the chain-bound smart accounts for the portfolio. Use the
Turnkey wallet client to fund these accounts. The B2B API does not have a
deposit-builder route. See [Fund a portfolio](/guides/portfolio-deposit).

<Warning>
  Keep the Glider API key and the Turnkey credentials on trusted systems. Do not
  put these secrets in public client code.
</Warning>
