Skip to main content

Overview

EIP-7702 introduces a new transaction type (Type-4) that allows Externally Owned Accounts (EOAs) to temporarily delegate to smart contract code. This enables account abstraction features like batched transactions, gas sponsorship, and session keys for regular wallets.

Use cases

  • Temporarily delegate an EOA to a smart contract implementation for advanced features
  • Enable batched transactions through a delegated smart account
  • Integrate with account abstraction infrastructure that leverages EIP-7702

Compatibility

  • Requires a network that supports EIP-7702 (e.g., Ethereum Mainnet, Sepolia, Arbitrum, Base, Optimism)
  • Signing an authorization is gasless; gas is only required when the signed authorization is included in an on-chain transaction

Sign an EIP-7702 Authorization

Send a POST request to /v1/wallet/sign/eip7702 with the delegation parameters.
cURL
curl -X POST 'https://tee.express.magiclabs.com/v1/wallet/sign/eip7702' \
  -H 'Content-Type: application/json' \
  -H 'Authorization: Bearer YOUR_JWT_TOKEN' \
  -H 'X-Magic-API-Key: YOUR_MAGIC_API_KEY' \
  -H 'X-OIDC-Provider-ID: YOUR_OIDC_PROVIDER_ID' \
  -H 'X-Magic-Chain: ETH' \
  -d '{
    "chain_id": 11155111,
    "address": "0x000000004F43C49e93C970E84001853a70923B03",
    "nonce": 0
  }'

Request Parameters

chain_id
integer
required
The chain ID for the authorization.
address
string
required
The smart contract implementation address to delegate to.
nonce
integer
required
The account nonce for the authorization.

Response Fields

Response:
{
  "r": "123456789012345678901234567890",
  "s": "987654321098765432109876543210",
  "y_parity": 1
}
r
string
The r component of the signature, returned as a decimal string.
s
string
The s component of the signature, returned as a decimal string.
y_parity
integer
The y_parity value of the signature (0 or 1).
The r and s values are returned as decimal strings, not hex. You need to convert them to hex before using them with libraries like viem.

Usage with viem

The response values need to be converted from decimal strings to hex to construct a SignedAuthorization object compatible with viem:
TypeScript
import type { Address, Hex, SignedAuthorization } from 'viem';

const decToHex = (dec: string): Hex =>
  `0x${BigInt(dec).toString(16).padStart(64, '0')}` as Hex;

const signEip7702Authorization = async (
  chainId: number,
  contractAddress: Address,
  nonce: number,
): Promise<SignedAuthorization<number>> => {
  const body = {
    chain_id: chainId,
    address: contractAddress,
    nonce,
  };

  const res = await fetch('https://tee.express.magiclabs.com/v1/wallet/sign/eip7702', {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json',
      'Authorization': `Bearer ${YOUR_JWT_TOKEN}`,
      'X-Magic-API-Key': 'YOUR_MAGIC_API_KEY',
      'X-OIDC-Provider-ID': 'YOUR_OIDC_PROVIDER_ID',
      'X-Magic-Chain': 'ETH',
    },
    body: JSON.stringify(body),
  });

  const { r, s, y_parity } = await res.json();

  return {
    address: contractAddress,
    chainId,
    nonce,
    r: decToHex(r),
    s: decToHex(s),
    yParity: y_parity,
  } as SignedAuthorization<number>;
};

Resources