Skip to content

Use Turnkey with ZeroDev

Turnkey is a key infrastructure provider with a great developer API and a powerful security policy engine.

By combining ZeroDev with Turnkey, you can create custodial AA wallets whose security is provided by Turnkey, with powerful functionalities such as sponsoring gas, batching transactions, etc.

Set up

To use Turnkey with ZeroDev, first create an application that integrates with Turnkey.

  • Refer to the Turnkey documentation site for instructions on setting up an application with the Turnkey.
  • For a quick start, Turnkey provides examples, available here.

Integration

Integrating ZeroDev with Turnkey is straightforward after setting up the project. Turnkey provides an Externally Owned Account (EOA) wallet to use as a signer with Kernel.

Create the TurnkeyClient and a Turnkey viem account

After following the Turnkey documentation, you will have access to a TurnkeyClient. An example is shown below:

import { TurnkeyClient } from "@turnkey/http";
import { createAccount } from "@turnkey/viem";
 
// Param options here will be specific to your project.  See the Turnkey docs for more info.
const turnkeyClient = new TurnkeyClient({ baseUrl: '' }, stamper);
 
const turnkeyAccount = createAccount({
  client: turnkeyClient,
  organizationId: subOrganizationId, // Your subOrganization id
  signWith: signWith, // Your suborganization `signWith` param.
})

Use with ZeroDev

Use the WalletClient from Turnkey to create a smart account signer, which can be passed to a validator. For detailed guidance on using a validator, refer to our documentation on creating accounts.

import { signerToEcdsaValidator } from "@zerodev/ecdsa-validator"
import { KERNEL_V3_1, getEntryPoint } from "@zerodev/sdk/constants"
import { createWalletClient, createPublicClient } from "viem";
import { polygonAmoy } from 'viem/chains';
 
const publicClient = createPublicClient({
  // Use your own RPC provider (e.g. Infura/Alchemy).
  transport: http('https://rpc-amoy.polygon.technology'),
  chain: polygonAmoy,
})
 
// Pass your `walletClient` to the validator
const ecdsaValidator = await signerToEcdsaValidator(publicClient, {
  signer: turnkeyAccount,
  entryPoint: getEntryPoint("0.7"),
  kernelVersion: KERNEL_V3_1
})
 
// You can now use this ECDSA Validator to create a Kernel account