useGrantPermissions
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.
Example
import { function useGrantPermissions(params: UseGrantPermissionsParams): UseGrantPermissionsResultReact 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.
useGrantPermissions, function useSmartAccountClient<TChain extends Chain | undefined = Chain | undefined, TAccount extends SupportedAccountTypes | undefined = "ModularAccountV2">(args: UseSmartAccountClientProps<TChain, TAccount>): UseSmartAccountClientResult<TChain, SupportedAccount<TAccount extends undefined ? "ModularAccountV2" : TAccount>>useSmartAccountClient } from "@account-kit/react"; function function PermissionsComponent(): JSX.ElementPermissionsComponent() { const { const client: { account: ModularAccountV2<AlchemySigner>; batch?: { multicall?: boolean | Prettify<MulticallBatchOptions> | undefined; } | undefined; cacheTime: number; ccipRead?: false | { request?: (parameters: CcipRequestParameters) => Promise<CcipRequestReturnType>; } | undefined; chain: Chain | undefined; experimental_blockTag?: BlockTag | undefined; ... 82 more ...; extend: <const client extends { ...; } & ExactPartial<...>>(fn: (client: Client<...>) => client) => Client<...>; } | undefinedclient } = useSmartAccountClient<Chain | undefined, "ModularAccountV2">(args: UseSmartAccountClientProps<Chain | undefined, "ModularAccountV2">): UseSmartAccountClientResult<Chain | undefined, ModularAccountV2<AlchemySigner>>useSmartAccountClient({}); const { const grantPermissions: UseMutateFunction<GrantPermissionsResult, Error, { key: { type: "secp256k1" | "ecdsa" | "contract"; publicKey: `0x${string}`; }; expirySec?: number | undefined; permissions: ({ type: "native-token-transfer"; data: { allowance: `0x${string}`; }; } | { type: "erc20-token-transfer"; data: { address: `0x${string}`; allowance: `0x${string}`; }; } | { type: "gas-limit"; data: { limit: `0x${string}`; }; } | { type: "contract-access"; data: { address: `0x${string}`; }; } | { type: "account-functions"; data: { functions: `0x${string}`[]; }; } | { type: "functions-on-all-contracts"; data: { functions: `0x${string}`[]; }; } | { ...; } | { ...; })[]; }, unknown>grantPermissions, const isGrantingPermissions: booleanisGrantingPermissions } = function useGrantPermissions(params: UseGrantPermissionsParams): UseGrantPermissionsResultReact 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.
useGrantPermissions({ client: { account: SupportedAccounts; batch?: { multicall?: boolean | Prettify<MulticallBatchOptions> | undefined; } | undefined; cacheTime: number; ccipRead?: false | { request?: (parameters: CcipRequestParameters) => Promise<CcipRequestReturnType>; } | undefined; chain: Chain | undefined; experimental_blockTag?: BlockTag | undefined; key: string; ... 81 more ...; extend: <const client extends { ...; } & ExactPartial<...>>(fn: (client: Client<...>) => client) => Client<...>; } | { ...; } | { ...; } | { ...; } | undefinedclient, }); const const handleGrantPermissions: () => voidhandleGrantPermissions = () => { const grantPermissions: (variables: { key: { type: "secp256k1" | "ecdsa" | "contract"; publicKey: `0x${string}`; }; expirySec?: number | undefined; permissions: ({ type: "native-token-transfer"; data: { allowance: `0x${string}`; }; } | { type: "erc20-token-transfer"; data: { address: `0x${string}`; allowance: `0x${string}`; }; } | { type: "gas-limit"; data: { limit: `0x${string}`; }; } | { type: "contract-access"; data: { address: `0x${string}`; }; } | { type: "account-functions"; data: { functions: `0x${string}`[]; }; } | { type: "functions-on-all-contracts"; data: { functions: `0x${string}`[]; }; } | { type: "functions-on-contract"; data: { address: `0x${string}`; functions: `0x${string}`[]; }; } | { ...; })[]; }, options?: MutateOptions<...> | undefined) => voidgrantPermissions({ permissions: ({ type: "native-token-transfer"; data: { allowance: `0x${string}`; }; } | { type: "erc20-token-transfer"; data: { address: `0x${string}`; allowance: `0x${string}`; }; } | { type: "gas-limit"; data: { limit: `0x${string}`; }; } | { type: "contract-access"; data: { address: `0x${string}`; }; } | { type: "account-functions"; data: { functions: `0x${string}`[]; }; } | { type: "functions-on-all-contracts"; data: { functions: `0x${string}`[]; }; } | { type: "functions-on-contract"; data: { address: `0x${string}`; functions: `0x${string}`[]; }; } | { data?: undefined; type: "root"; })[]permissions: [ { type: "native-token-spending-limit"type: "native-token-spending-limit", data: { amount: string; }data: { amount: stringamount: "1000000000000000000", // 1 ETH in wei }, }, ], expiry: numberexpiry: var Math: MathAn intrinsic object that provides basic mathematics functionality and constants.
Math.Math.floor(x: number): numberReturns the greatest integer less than or equal to its numeric argument.
floor(var Date: DateConstructorEnables basic storage and retrieval of dates and times.
Date.DateConstructor.now(): numberReturns the number of milliseconds elapsed since midnight, January 1, 1970 Universal Coordinated Time (UTC).
now() / 1000) + 3600, // 1 hour from now }); }; return ( <React.JSX.IntrinsicElements.button: React.DetailedHTMLProps<React.ButtonHTMLAttributes<HTMLButtonElement>, HTMLButtonElement>button React.DOMAttributes<HTMLButtonElement>.onClick?: React.MouseEventHandler<HTMLButtonElement> | undefinedonClick={const handleGrantPermissions: () => voidhandleGrantPermissions} React.ButtonHTMLAttributes<HTMLButtonElement>.disabled?: boolean | undefineddisabled={const isGrantingPermissions: booleanisGrantingPermissions}> {const isGrantingPermissions: booleanisGrantingPermissions ? "Granting..." : "Grant Permissions"} </React.JSX.IntrinsicElements.button: React.DetailedHTMLProps<React.ButtonHTMLAttributes<HTMLButtonElement>, HTMLButtonElement>button> ); }
Parameters
Returns
Object containing mutation functions, loading state, result, and error