docs: fix missing userOp declaration - #452
Conversation
## Issue
The ERC-4337 gasless execution example references `userOp` and `packUserOp` without declaring or importing them, causing `ReferenceError` when users copy the example.
## Impact
- Developers cannot successfully implement gasless ERC-4337 transfers using the documentation
- Poor developer experience for a core Relay feature
## Fix
- Added import: `import { packUserOp } from "viem/account-abstraction")`
- Added `userOp` object declaration with placeholder values and inline comments guiding replacement
## Validation
- Code now compiles without `ReferenceError`
- Example structure follows ERC-4337 specification
- Placeholder comments clarify required user modifications
## Related
- `features/gasless-execution.mdx` (lines 581-590)
|
…eration and getUserOperationHash
| initCode: "0x", | ||
| callData: "0x", // Replace with the actual call data for the operation | ||
| callGasLimit: 50000n, | ||
| verificationGasLimit: 100000n, | ||
| preVerificationGas: 50000n, | ||
| maxFeePerGas: 0n, | ||
| maxPriorityFeePerGas: 0n, | ||
| paymasterAndData: "0x", |
There was a problem hiding this comment.
This example requests EntryPoint v0.7 but defines initCode and paymasterAndData, which are v0.6 fields. viem accepts the locally declared object structurally, then ignores both values while hashing and packing. A copied account-deployment or sponsored-operation flow therefore signs and submits an operation without its documented factory or paymaster data. Define the v0.7 fields (factory, factoryData, paymaster, paymasterVerificationGasLimit, paymasterPostOpGasLimit, and paymasterData) in both the example and UserOperation type.
Artifacts
Focused viem ERC-4337 reproduction source
- TypeScript source created in a disposable project to compile and run the docs-shaped and correct v0.7 user operations, showing the legacy fields are ignored.
Type-check log for the docs-shaped user operation
- Executed `npx tsc --noEmit` against the docs-shaped reproduction and captured exit code 0, showing the local documentation type permits the incorrect v0.7 call.
Runtime log for viem 2.56.3 ERC-4337 reproduction
- Executed the focused reproduction with viem 2.56.3 and captured empty packed legacy fields, unchanged legacy-only hash, and correct v0.7 packing, proving the documented fields are ignored.
| factory: "0x", | ||
| factoryData: "0x", | ||
| callData: "0x", // Replace with the actual call data for the operation | ||
| callGasLimit: 50000n, | ||
| verificationGasLimit: 100000n, | ||
| preVerificationGas: 50000n, | ||
| maxFeePerGas: 0n, | ||
| maxPriorityFeePerGas: 0n, | ||
| paymaster: "0x", | ||
| paymasterVerificationGasLimit: 0n, | ||
| paymasterPostOpGasLimit: 0n, | ||
| paymasterData: "0x", |
There was a problem hiding this comment.
| paymaster: "0x", | ||
| paymasterVerificationGasLimit: 0n, | ||
| paymasterPostOpGasLimit: 0n, | ||
| paymasterData: "0x", |
There was a problem hiding this comment.
|
I am closing this PR. Initially, I only wanted to fix the example in |
Issue
The ERC-4337 gasless execution example references
userOpandpackUserOpwithout declaring or importing them, causingReferenceErrorwhen users copy the example.Impact
Fix
import { packUserOp } from "viem/account-abstraction")userOpobject declaration with placeholder values and inline comments guiding replacementValidation