What We’re Building
By the end of this tutorial, you’ll have a backend service that can:- Securely manage private keys with Turnkey
- Execute transactions without holding ETH for gas
- Perform operations across multiple chains
How it works: Turnkey stores and manages private keys in secure enclaves. When you need to sign a transaction, Turnkey signs it without ever exposing the private key. We then route the signed transaction through Biconomy’s MEE for gas abstraction.
Step 1: Install Dependencies
@turnkey/sdk-server— Turnkey’s server SDK for key management@turnkey/viem— Adapter to use Turnkey with viem@biconomy/abstractjs— Biconomy’s SDK for smart accounts and MEEviem— Ethereum library for building transactions
Step 2: Set Up Environment Variables
Create a.env file with your Turnkey credentials:
Step 3: Initialize Turnkey Client
Set up the Turnkey client that will handle all signing operations:Step 4: Create a Wallet Client
Create a viem wallet client using the Turnkey account:What’s happening here? The
createAccount function creates an adapter that lets viem use Turnkey for signing. The actual private key never leaves Turnkey’s secure infrastructure.Step 5: Sign EIP-7702 Authorization
Sign the authorization that upgrades the EOA to a smart account:What is this authorization? It’s a signed message saying “I authorize my wallet address to execute code from this smart contract.” This enables smart account features while keeping the same address.
Step 6: Create the Smart Account
Create a Nexus account that works across multiple chains:Step 7: Create the MEE Client
The MEE client handles transaction execution with gas abstraction:Step 8: Execute a Gasless Transaction
Now execute a transaction with gas paid in any ERC-20:Step 9: Wait for Confirmation
Complete Example
Here’s a full Node.js script:Cross-Chain Execution
Execute on multiple chains with one signature:Key Takeaways
- Turnkey manages keys securely — Private keys never leave Turnkey’s secure infrastructure
- EIP-7702 adds smart features — The wallet gets upgraded without deploying a new contract
- MEE handles gas — Pay with any ERC-20 token or sponsor gas entirely
- Cross-chain ready — Add chains to
chainConfigurationsand include them in instructions