Send user operations
Once your users have been authenticated, you can start sending user operations!
Single user operation
example.ts
import { watchSmartAccountClient } from "@account-kit/core";
import { config } from "./config.js";
// How you actually store this state variable
// depends on the framework you're using
let clientState;
// The watch smart account client will handle all of the possible state changes
// that can impact this client:
// - Signer status
// - Account instantiation
// - Chain changes
const clientSubscription = watchSmartAccountClient(
{
type: "LightAccount",
},
config
)((clientState_) => {
clientState = clientState_;
});
if (clientState == null || clientState.isLoadingClient) {
console.log("Loading...");
}
const client = clientState.client;
await client.sendUserOperation({
uo: {
target: "0xtarget",
data: "0x",
value: 0n,
},
});
Batch user operation
It's also possible to send user operations in batch using the same approach!
example.ts
import { watchSmartAccountClient } from "@account-kit/core";
import { config } from "./config.js";
// How you actually store this state variable
// depends on the framework you're using
let clientState;
// The watch smart account client will handle all of the possible state changes
// that can impact this client:
// - Signer status
// - Account instantiation
// - Chain changes
const clientSubscription = watchSmartAccountClient(
{
type: "LightAccount",
},
config
)((clientState_) => {
clientState = clientState_;
});
if (clientState == null || clientState.isLoadingClient) {
console.log("Loading...");
}
const client = clientState.client;
await client.sendUserOperation({
uo: [
{
target: "0xtarget",
data: "0x",
value: 0n,
},
{
target: "0xtarget",
data: "0x",
value: 0n,
},
],
});