useGrantPermissions

React hook for granting permissions on the smart account to a given keypair This enables dapps to request specific permissions from smart accounts, such as spending limits or execution permissions. Returns an error if called with an EOA wallet connection.

Import

1import { useGrantPermissions } from "@account-kit/react";

Usage

1import { useGrantPermissions, useSmartAccountClient } from "@account-kit/react";
2
3function PermissionsComponent() {
4 const { client } = useSmartAccountClient({});
5 const { grantPermissions, isGrantingPermissions } = useGrantPermissions({
6 client,
7 });
8
9 const handleGrantPermissions = () => {
10 grantPermissions({
11 permissions: [
12 {
13 type: "native-token-spending-limit",
14 data: {
15 amount: "1000000000000000000", // 1 ETH in wei
16 },
17 },
18 ],
19 expiry: Math.floor(Date.now() / 1000) + 3600, // 1 hour from now
20 });
21 };
22
23 return (
24 <button onClick={handleGrantPermissions} disabled={isGrantingPermissions}>
25 {isGrantingPermissions ? "Granting..." : "Grant Permissions"}
26 </button>
27 );
28}

Parameters

params

UseGrantPermissionsParams Configuration object containing the smart account client

Returns

UseGrantPermissionsResult Object containing mutation functions, loading state, result, and error