Send User Operations

Once your users have been authenticated, you can start sending user operations!

Single user operation

In the below example, we use LightAccount as the underlying Smart Contract type. You can also use MultiOwnerModularAccount if you want to provide your users with an ERC-6900 compliant modular account, or you can use MultiOwnerLightAccount if you want to support an account with multiple owners.

1import { watchSmartAccountClient } from "@account-kit/core";
2import { config } from "./config.js";
3
4// How you actually store this state variable
5// depends on the framework you're using
6let clientState;
7
8// The watch smart account client will handle all of the possible state changes
9// that can impact this client:
10// - Signer status
11// - Account instantiation
12// - Chain changes
13const clientSubscription = watchSmartAccountClient(
14 {
15 type: "LightAccount",
16 },
17 config
18)((clientState_) => {
19 clientState = clientState_;
20});
21
22if (clientState == null || clientState.isLoadingClient) {
23 console.log("Loading...");
24}
25
26const client = clientState.client;
27
28await client.sendUserOperation({
29 uo: {
30 target: "0xtarget",
31 data: "0x",
32 value: 0n,
33 },
34});

Batch user operation

It’s also possible to send user operations in batch using the same approach!

1import { watchSmartAccountClient } from "@account-kit/core";
2import { config } from "./config.js";
3
4// How you actually store this state variable
5// depends on the framework you're using
6let clientState;
7
8// The watch smart account client will handle all of the possible state changes
9// that can impact this client:
10// - Signer status
11// - Account instantiation
12// - Chain changes
13const clientSubscription = watchSmartAccountClient(
14 {
15 type: "LightAccount",
16 },
17 config
18)((clientState_) => {
19 clientState = clientState_;
20});
21
22if (clientState == null || clientState.isLoadingClient) {
23 console.log("Loading...");
24}
25
26const client = clientState.client;
27
28await client.sendUserOperation({
29 uo: [
30 {
31 target: "0xtarget",
32 data: "0x",
33 value: 0n,
34 },
35 {
36 target: "0xtarget",
37 data: "0x",
38 value: 0n,
39 },
40 ],
41});