> ## 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

> A tutorial on how to use Turnkey with the Glider API

The Glider API is wallet agnostic. This means that as long as you can get an [EIP-191 signature](https://eips.ethereum.org/EIPS/eip-191) from the EOA that will own the portfolio, you can use the Glider API.

If you've followed along with the [Quickstart](/quickstart) guide you will notice there's two cases where your wallet architecture will need to interface with Glider. The first is when you're creating a portfolio, and the second is when you're funding a portfolio.

## Creating a Portfolio with Turnkey

<Steps titleSize="h3">
  <Step title="Get the Message to Sign">
    Fetch the data to be signed by calling the `https://api.glider.fi/v1/portfolio/create/signature` endpoint.

    ```javascript theme={null}
    // First, get the message to sign
    const signDataResponse = await fetch(
      `https://api.glider.fi/strategies/sign-data/${strategy.strategyId}`,
      {
        method: "GET",
        headers: {
          "X-API-KEY": "your_api_key_here",
        },
      }
    );

    const signData = await signDataResponse.json();
    const messageToSign = signData.message;
    ```
  </Step>

  <Step title="Sign the Message">
    Sign the payload using the owner's wallet. The Turnkey SDK can be used to sign the message like so:

    ```javascript turnkey.js theme={null}
    import { useTurnkey } from "@turnkey/sdk-react";

    const { walletClient } = useTurnkey();

    const signature = await walletClient.signRawPayload({
        payload: messageToSign,
        signWith: wallet.address,
        encoding: "PAYLOAD_ENCODING_TEXT_UTF8",
        hashFunction: "HASH_FUNCTION_KECCAK256"
    });
    ```
  </Step>
</Steps>

## Funding a Portfolio with Turnkey

Funding a portfolio is done by sending funds to a portfolio's vault address.

<Steps titleSize="h3">
  <Step title="Get the Portfolio's Vault Address">
    Fetch the portfolio's vault address by calling the `https://api.glider.fi/v1/portfolio/{portfolioId}` endpoint.

    <FetchStrategyDataCodeblock />
  </Step>

  <Step title="Send Funds to the Portfolio's Vault">
    Turnkey has integrations with both `ethers.js` and `Viem` to send funds using Turnkey. An example with Viem is highlighted below:

    ```javascript theme={null}
    import { createTurnkeyClient } from "@turnkey/viem";
    import { createPublicClient, createWalletClient, http } from "viem";
    import { mainnet } from "viem/chains";
    import { useTurnkey } from "@turnkey/sdk-react";

    const { getActiveClient } = useTurnkey();

    const publicClient = createPublicClient({
      chain: mainnet,
      transport: http("YOUR_RPC_URL")
    });

    const walletClient = createWalletClient({
      chain: mainnet,
      transport: http("YOUR_RPC_URL"),
      account: createTurnkeyClient({
        client: await getActiveClient(),
        address: wallet.address
      })
    });

    const hash = await walletClient.sendTransaction({
      to: "0xRecipientAddress",
      value: parseEther("0.1")
    });
    ```
  </Step>
</Steps>
