Skip to main content

useCreateSessionKey

Hook that allows you to create a session key (or signer) for a smart wallet account.

 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>
);
};

Usage

Provide the smart wallet account contract address as the argument.

import { useAccountAdminsAndSigners } from "@thirdweb-dev/react";

const keyAddress = "{{key_address}}";

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>
);
};

Configuration

address (required)

address

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

approvedCallTargets

approvedCallTargets

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

nativeTokenLimitPerTransaction

nativeTokenLimitPerTransaction

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

startDate

startDate

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

endDate

startDate

The date when the session key expires as a Date.