Skip to content

EIP-7702 Integration

EIP-7702 allows an Externally Owned Account (EOA) to temporarily "become" a smart contract. CommissionRoad leverages this to allow users to authorize the CommissionRoadExecutor to act on their behalf.

WHEN TO USE

Use this for Gas Sponsoring or Identity Preservation.

  • Example: "A Relayer pays gas for the user's transaction."
  • Example: "User wants to mint + stake without two approval signatures."
  • Example: "Target protocol checks msg.sender and requires it to be the User."

Why EIP-7702?

  • No Approvals: Since the user is the executor, the contract can move the user's tokens without a prior approve() transaction.
  • Atomic: You can perform Mint, Approve, Swap, and Pay Commission in one single atomic transaction.
  • Identity: The transactions originate from the User's address, not the CommissionRoad contract.

Implementation

1. Sign Authorization

The user signs a message authorizing the CommissionRoadExecutor code to run in their account context.

typescript
import { verifyAuthorization } from "viem/experimental";

const authorization = await walletClient.signAuthorization({
  contractAddress: commissionRoadExecutorAddress,
  chainId: 1,
  nonce: 0,
});

2. Broadcast Transaction

The transaction can be sent by anyone (the user or a relayer). The payload is a self-call to the user's address, executing the batchCall function of the adopted code.

typescript
// Encode the 'batchCall' function of the Executor
const data = encodeFunctionData({
  abi: executorAbi,
  functionName: "batchCall",
  args: [batchData]
});

// Send transaction
await walletClient.sendTransaction({
  to: userAddress, // Self-call!
  data: data,
  authorizationList: [authorization] // EIP-7702 Magic
});