EIP-7702 is an upgrade to EVM blockchains that enables externally owned accounts (EOAs) to set their code to that of a smart contract. In practical terms, this means that EOA wallets will gain AA (account abstraction) capabilities such as transaction bundling, gas sponsorship, and custom permissions.

Privy supports all low level interfaces required by 7702 - signing authorizations and sending type 4 transactions, allowing you to use any implementation of EIP-7702. Use the following guides to get started with EIP-7702 in your application:

Signing EIP-7702 authorizations

Privy provides methods to sign EIP-7702 authorizations using the user’s embedded wallet. This authorization is a cryptographic signature that allows an EOA to set its code to that of a smart contract, enabling the EOA to behave like a smart account.

Learn more about signing EIP-7702 authorizations in our dedicated guide.

Learn more about using the signed authorization in the integration guides below!

Using EIP-7702 capabilities

In this guide, we will transform your Privy embedded wallet into a smart wallet with features like gas sponsorship, batch transactions, granular permissions, and more using EIP-7702 support from Alchemy.

0. Install dependencies

In your app’s repository, install the required dependencies from Privy, Alchemy, and viem:

The Alchemy SDK currently requires viem to be pinned to 2.22.6
npm i @privy-io/react-auth @account-kit/smart-contracts @account-kit/infra @aa-sdk/core [email protected]

1. Create an Alchemy account and get your API key

  • Create an app: visit the Alchemy dashboard to create a new app, if you don’t already have one.

    • Make sure to enable networks that support EIP-7702 such as Ethereum Mainnet or Sepolia.
    • Save the app’s API Key that will be used later.
  • Enable gas sponsorship: visit the Gas Manager dashboard and create a new sponsorship policy for the app you created in step 1. This policy will be used to set rules on how much of user’s gas you want to sponsor.

    • Make sure to enable gas sponsorship on a chain that support EIP-7702 such as Ethereum Mainnet or Sepolia.
    • Save the Policy ID that will be used later.

Now that you have your API key and Policy ID, you can set up your smart wallets.

2. Configure Privy settings

If you’re already using a Privy embedded wallet, update your configuration to support EIP-7702 with embedded wallets. If you don’t yet have authentication configured, you can follow this guide to get set up.

Make sure your PrivyProvider has the following embeddedWallets settings and ensure you set the defaultChain and supportedChains to the 7702 supported chain you chose in step 1.

import { sepolia } from "@account-kit/infra";
<PrivyProvider
	appId={process.env.NEXT_PUBLIC_PRIVY_APP_ID || ""}
	config={{
	  embeddedWallets: {
	    showWalletUIs: false,
	    createOnLogin: "all-users",
	  },
	  defaultChain: sepolia,
	  supportedChains: [sepolia],
	}}
>

3. Adapt Privy signer to a smart account signer

Now that you have authentication working, adapt the Privy signer to be able to sign 7702 authorizations to upgrade to smart accounts.

1. Get the Privy embedded wallet

import {useWallets} from '@privy-io/react-auth';

const {wallets} = useWallets();
const embeddedWallet = wallets.find((x) => x.walletClientType === 'privy');

2. Create a SmartAccountSigner instance

import {sepolia, alchemy} from '@account-kit/infra'; // make sure to import your chain from account-kit, not viem
import {useSign7702Authorization} from '@privy-io/react-auth';
import {SmartAccountSigner, WalletClientSigner} from '@aa-sdk/core';
import {createWalletClient, custom, Hex} from 'viem';
import {Authorization} from 'viem/experimental';

const {signAuthorization} = useSign7702Authorization();

async function create7702signer() {
  const baseSigner = new WalletClientSigner(
    createWalletClient({
      account: embeddedWallet!.address as Hex,
      chain: sepolia,
      transport: custom(await embeddedWallet!.getEthereumProvider())
    }),
    'privy'
  );

  const signer: SmartAccountSigner = {
    getAddress: baseSigner.getAddress,
    signMessage: baseSigner.signMessage,
    signTypedData: baseSigner.signTypedData,
    signerType: baseSigner.signerType,
    inner: baseSigner.inner,
    signAuthorization: async (
      unsignedAuth: Authorization<number, false>
    ): Promise<Authorization<number, true>> => {
      const signature = await signAuthorization(unsignedAuth);

      return {
        ...unsignedAuth,
        ...{
          r: signature.r!,
          s: signature.s!,
          v: signature.v!
        }
      };
    }
  };

  return signer;
}

4. Upgrade to smart accounts and send sponsored transactions

Now that you have a SmartAccountSigner instance, follow this guide to create a smart account client (createModularAccountV2Client ) and start sending sponsored transactions. You’ll need:

  • the SmartAccountSigner instance defined in step 3
  • the API key and the policy ID from step 1

Once you define the client, you can send sponsored transactions with your embedded EOA and access other advanced smart account features! This client will handle all of the logic of delegating to a new smart account, if not already, and signing transactions. If you don’t yet have a signer, follow this guide to get set up.

Next steps

You just upgraded your EOA and sent your first sponsored transaction using EIP-7702!

If you want to leverage other smart account capabilities such as batching and permissions, check out the Alchemy docs.