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

# Turnkey with Biconomy MEE and EIP-7702

This guide shows how to combine **Turnkey** and **Biconomy AbstractJS** to send secure gasless transactions using EIP-7702. You'll use Turnkey to manage your private keys, and Biconomy to abstract gas via the MEE stack.

<Steps>
  <Step title="Install Dependencies">
    Install core SDKs from Turnkey, Biconomy, and viem.

    ```bash theme={null}
    npm install @turnkey/sdk-server @turnkey/viem @biconomy/abstractjs viem dotenv
    ```
  </Step>

  <Step title="Configure .env">
    Store Turnkey credentials and signing key in environment variables.

    ```bash theme={null}
    BASE_URL=https://api.turnkey.com
    API_PRIVATE_KEY=your_api_private_key
    API_PUBLIC_KEY=your_api_public_key
    ORGANIZATION_ID=your_organization_id
    SIGN_WITH=your_private_key_id
    ```
  </Step>

  <Step title="Initialize Turnkey Client">
    Set up Turnkey client for key management and signing.

    ```ts theme={null}
    import { Turnkey } from "@turnkey/sdk-server";
    import * as dotenv from "dotenv";
    dotenv.config();

    const client = new Turnkey({
      apiBaseUrl: process.env.BASE_URL,
      apiPrivateKey: process.env.API_PRIVATE_KEY,
      apiPublicKey: process.env.API_PUBLIC_KEY,
      defaultOrganizationId: process.env.ORGANIZATION_ID,
    });
    ```
  </Step>

  <Step title="Create Wallet Client">
    Create a `viem` wallet client from the Turnkey account.

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

    const account = await createAccount({
      client: client.apiClient(),
      organizationId: process.env.ORGANIZATION_ID,
      signWith: process.env.SIGN_WITH,
    });

    const walletClient = createWalletClient({
      account,
      chain: optimism,
      transport: http(),
    });
    ```
  </Step>

  <Step title="Sign EIP-7702 Authorization">
    Sign the delegation message needed to enable smart account functionality on the EOA.

    ```ts theme={null}
    const nexusImplementationAddress = "0x000000004F43C49e93C970E84001853a70923B03";

    const authorization = await walletClient.signAuthorization({
      contractAddress: nexusImplementationAddress,
      account,
    });
    ```
  </Step>

  <Step title="Create Nexus Smart Account">
    Override `accountAddress` to match the EOA — this activates EIP-7702 delegation.

    ```ts theme={null}
    import { toMultichainNexusAccount, getMEEVersion, MEEVersion } from "@biconomy/abstractjs";
    import { base } from "viem/chains";

    const nexusAccount = await toMultichainNexusAccount({
      chainConfigurations: [
        {
          chain: optimism,
          transport: http(),
          version: getMEEVersion(MEEVersion.V2_1_0),
          accountAddress: account.address // use EOA for EIP-7702
        },
        {
          chain: base,
          transport: http(),
          version: getMEEVersion(MEEVersion.V2_1_0),
          accountAddress: account.address // use EOA for EIP-7702
        }
      ],
      signer: walletClient
    });
    ```
  </Step>

  <Step title="Create MEE Client">
    Connect to the Modular Execution Environment for gasless transaction execution.

    ```ts theme={null}
    import { createMeeClient } from "@biconomy/abstractjs";

    const meeClient = await createMeeClient({
      account: nexusAccount
    });
    ```
  </Step>

  <Step title="Send Gasless Transaction">
    Set `delegate: true` and include `authorization` to trigger execution via EIP-7702 delegation.

    ```ts theme={null}
    const { hash } = await meeClient.execute({
      authorization,
      delegate: true,
      feeToken: {
        address: "0xYourUSDCAddress",
        chainId: optimism.id,
      },
      instructions: [
        {
          chainId: optimism.id,
          calls: [
            {
              to: "0x0000000000000000000000000000000000000000",
              value: 0n
            }
          ]
        }
      ]
    });
    ```
  </Step>

  <Step title="Cross-Chain Execution (Optional)">
    Instructions can target multiple chains. Everything is handled by one user signature.

    ```ts theme={null}
    const { hash } = await meeClient.execute({
      authorization,
      delegate: true,
      instructions: [
        {
          chainId: optimism.id,
          calls: [{ to: "0x...", value: 0n }]
        },
        {
          chainId: base.id,
          calls: [{ to: "0x...", value: 0n }]
        }
      ]
    });
    ```
  </Step>
</Steps>

### Summary

* Turnkey securely manages EOA keys
* Biconomy enables EIP-7702-based smart account delegation
* Set `accountAddress` to the EOA address for EIP-7702 flow
* Use `delegate: true` + `authorization` in the execution call
* MEE handles gas payment using ERC-20s or sponsorship

This setup gives you secure, gas-abstracted, and cross-chain smart account transactions with minimal UX friction.
