diff --git a/features/gasless-execution.mdx b/features/gasless-execution.mdx index 483069e..38f1a96 100644 --- a/features/gasless-execution.mdx +++ b/features/gasless-execution.mdx @@ -553,6 +553,11 @@ If Relay cannot map a custom error selector to a known contract error, the respo encodeAbiParameters, toHex, } from "viem"; + import { + toPackedUserOperation, + getUserOperationHash, + entryPoint07Abi, + } from "viem/account-abstraction"; import { base } from "viem/chains"; import { UserOperation } from "./types.ts"; import { entryPointAbi, smartAccountAbi } from "./abis.ts"; @@ -576,29 +581,42 @@ If Relay cannot map a custom error selector to a known contract error, the respo transport: http() }); - const userOpPackHash = keccak256(packUserOp(userOp)); - - const encoded = encodeAbiParameters( - [ - { type: "bytes32" }, // userOp hash - { type: "address" }, // entryPoint - { type: "uint256" }, // chainId - ], - [userOpPackHash, ENTRY_POINT, BigInt(base.id)], - ); + const userOp: UserOperation = { + sender: YOUR_WALLET_ADDRESS, + nonce: 0n, // Replace with actual nonce from smartAccountAbi.getNonce() + 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", + signature: "0x", + }; - const userOpHash = keccak256(encoded); + const userOpHash = getUserOperationHash({ + chainId: base.id, + entryPointAddress: ENTRY_POINT, + entryPointVersion: "0.7", + userOperation: userOp, + }); const signature = await walletClient.signMessage({ message: { raw: userOpHash }, }); const signedUserOp: UserOperation = { ...userOp, signature }; + const packedSignedUserOp = toPackedUserOperation(signedUserOp); const handleOpsData = encodeFunctionData({ - abi: entryPointAbi, + abi: entryPoint07Abi, functionName: "handleOps", - args: [[signedUserOp], BENEFICIARY], + args: [[packedSignedUserOp], BENEFICIARY], }); ``` ```typescript types.ts