Skip to content
Alchemy Logo

useGrantPermissions

function useGrantPermissions(params): UseGrantPermissionsResult;

Defined in: account-kit/react/src/hooks/useGrantPermissions.ts:98

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 { useGrantPermissions, useSmartAccountClient } from "@account-kit/react";
 
function PermissionsComponent() {
  const { client } = useSmartAccountClient({});
  const { grantPermissions, isGrantingPermissions } = useGrantPermissions({
    client,
  });
 
  const handleGrantPermissions = () => {
    grantPermissions({
      permissions: [
        {
          type: "native-token-spending-limit",
          data: {
            amount: "1000000000000000000", // 1 ETH in wei
          },
        },
      ],
      expiry: Math.floor(Date.now() / 1000) + 3600, // 1 hour from now
    });
  };
 
  return (
    <button onClick={handleGrantPermissions} disabled={isGrantingPermissions}>
      {isGrantingPermissions ? "Granting..." : "Grant Permissions"}
    </button>
  );
}

ParameterTypeDescription

params

UseGrantPermissionsParams

Configuration object containing the smart account client

UseGrantPermissionsResult

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

Was this page helpful?