Examples
Basic authorization
This will set the EOA code to the Simple7702Account
implementation.
example.ts
import { walletClient } from "./client.js";
const accountImplementation = "0x4Cd241E8d1510e30b2076397afc7508Ae59C66c9";
const authorization = await walletClient.signAuthorization({
contractAddress: accountImplementation,
executor: "self",
});
const hash = await walletClient.sendTransaction({
authorizationList: [authorization],
data: "0x",
to: walletClient.account.address,
});
console.log(`Delegated at tx ${hash}`);
Transaction batching
Once the EOA code is delegated to a smart account implementation, you can start making batched transactions.
example.ts
import { zeroAddress } from "viem";
import accountAbi from "./abi.js";
import { account, walletClient } from "./client.js";
const hash = await walletClient.writeContract({
abi: accountAbi,
address: account.address,
functionName: "executeBatch",
args: [
[
{
target: zeroAddress,
value: 1n,
data: "0x",
},
{
target: "0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045",
value: 0n,
data: "0xdeadbeef",
},
],
],
});
console.log(`Transaction hash ${hash}`);
Sending a user operation
Signs and sends a UserOp using the ERC-4337 flow. Assumes the account is already initialized, and the EOA is the owner of the account.
This way, you can also sponsor the transactions by using a paymaster.
Note that the process is exactly the same as when using a regular smart account. To minimize the code surface, you can use a convenience library like permissionless.js.
example.ts
import { zeroAddress } from "viem";
import { smartAccount } from "./account.js";
import { bundlerClient } from "./client.js";
const userOpHash = await bundlerClient.sendUserOperation({
account: smartAccount,
calls: [
{
to: zeroAddress,
value: 1n,
},
{
to: "0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045",
data: "0xdeadbeef",
},
],
});
console.log(`User operation sent ${userOpHash}`);