useCreateSessionKey

Create and add a session key for the smart wallet account

Example

const Component = () => {
const {
mutate: createSessionKey,
isLoading,
error,
} = useCreateSessionKey();
if (error) {
console.error("failed to create session key", error);
}
return (
<button
disabled={isLoading}
onClick={() => createSessionKey(
keyAddress,
{
approvedCallTargets: ["0x..."], // the addresses of contracts that the session key can call
nativeTokenLimitPerTransaction: 0.1, // the maximum amount of native token (in ETH) that the session key can spend per transaction
startDate: new Date(), // the date when the session key becomes active
expirationDate = new Date(Date.now() + 24 * 60 * 60 * 1000); // the date when the session key expires
}
)}
>
Create Session Key
</button>
);
};
function useCreateSessionKey(): UseMutationResult<
unknown,
CreateSessionKeyInput
>;

Returns

let returnType: UseMutationResult<
unknown,
CreateSessionKeyInput
>;

Mutation object to create and add a session key for the smart wallet

const { mutateAsync, isLoading, error } = useCreateSessionKey();

options

The mutation function takes an object with the following properties as argument:

address

The address to add as an admin on the account as a string .

approvedCallTargets

An array of addresses that the session key can call as a string[] .

nativeTokenLimitPerTransaction

The maximum amount of native token (in ETH) that the session key can spend per transaction as a number .

startDate

The date when the session key becomes active as a Date .

startDate

The date when the session key expires as a Date .