diff --git a/.changeset/kip-redundant-7702-auth.md b/.changeset/kip-redundant-7702-auth.md new file mode 100644 index 00000000..9d3eb1ad --- /dev/null +++ b/.changeset/kip-redundant-7702-auth.md @@ -0,0 +1,6 @@ +--- +"permissionless": patch +--- + +Skip adding `authorization` to `sendTransaction` when the account is already 7702-attached to the same address. +This prevents redundant Type-4 overhead in UserOps and reduces calldata/gas; no changes required for consumers. diff --git a/packages/permissionless/actions/smartAccount/sendTransaction.ts b/packages/permissionless/actions/smartAccount/sendTransaction.ts index 15a50d38..ef1e8b4d 100644 --- a/packages/permissionless/actions/smartAccount/sendTransaction.ts +++ b/packages/permissionless/actions/smartAccount/sendTransaction.ts @@ -3,7 +3,8 @@ import type { Client, Hash, SendTransactionParameters, - Transport + Transport, + getCode } from "viem" import { type SendUserOperationParameters, @@ -95,6 +96,21 @@ export async function sendTransaction< if (!to) throw new Error("Missing to address") + if ("authorization" in args && args.authorization) { + const bytecode = await getCode(client, { address: account.address }) + + if (bytecode) { + const bc = bytecode.toLowerCase() + // "0x" + "ef0100" + 40 hex (address) + if (bc.startsWith("0xef0100") && bc.length >= 48) { + const attachedAddress = "0x" + bc.slice(8, 48) // <-- exact 20 bytes + const target = (args.authorization as any).address?.toLowerCase?.() + if (target && attachedAddress === target) { + delete (args as any).authorization + } + } + } + } userOpHash = await getAction( client, sendUserOperation,