useClientActions
Import
import { useClientActions } from "@alchemy/aa-alchemy/react";
Usage
import { sessionKeyPluginActions } from "@alchemy/aa-accounts";
import {
useClientActions,
useSmartAccountClient,
} from "@alchemy/aa-alchemy/react";
import { zeroAddress } from "viem";
export function ComponentWithClientActions() {
const { client } = useSmartAccountClient({
type: "MultiOwnerModularAccount",
});
const { executeAction, data } = useClientActions({
client,
actions: sessionKeyPluginActions,
});
return (
<div>
<p>Is Session Key: {data != null ? !!data : "Click Button"}</p>
<button
onClick={() =>
executeAction({
functionName: "isAccountSessionKey",
args: [{ key: zeroAddress }],
})
}
>
Check Key
</button>
</div>
);
}
Params
import { type UseClientActionsProps } from "@alchemy/aa-alchemy/react";
client
The SmartAccountClient instance returned from useSmartAccountClient
actions
a function that accepts as input the above client and returns an object containing functions that you can call to execute actions on the client.
You can optionally specify any of the React Query useMutation
parameters as parameters to this hook.
Return Type
import { type UseClientActionsResult } from "@alchemy/aa-alchemy/react";
executeAction
A function that allows you to execute one of the client actions passed into the hook.
functionName
string
one of the functions passed into the hook
args
an array of the arguments to pass to the function
executeActionAsync
A function that allows you to execute one of the client actions passed into the hook. It also returns a Promise
containing the result of the executed action.
functionName
string
one of the functions passed into the hook
args
an array of the arguments to pass to the function
data
The result of the executed action if one was executed
isExecutingAction
A boolean that is true when an action is executing.
error
An error object that is populated when the authentication fails.