useGrantPermissions

1function 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.

Example

import { 
function useGrantPermissions(params: UseGrantPermissionsParams): UseGrantPermissionsResult

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.

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.Element
PermissionsComponent
() {
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<...>; } | undefined
client
} =
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: boolean
isGrantingPermissions
} =
function useGrantPermissions(params: UseGrantPermissionsParams): UseGrantPermissionsResult

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.

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<...>; } | { ...; } | { ...; } | { ...; } | undefined
client
,
}); const
const handleGrantPermissions: () => void
handleGrantPermissions
= () => {
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) => void
grantPermissions
({
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: string
amount
: "1000000000000000000", // 1 ETH in wei
}, }, ],
expiry: number
expiry
:
var Math: Math

An intrinsic object that provides basic mathematics functionality and constants.

Math
.
Math.floor(x: number): number

Returns the greatest integer less than or equal to its numeric argument.

floor
(
var Date: DateConstructor

Enables basic storage and retrieval of dates and times.

Date
.
DateConstructor.now(): number

Returns 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> | undefined
onClick
={
const handleGrantPermissions: () => void
handleGrantPermissions
}
React.ButtonHTMLAttributes<HTMLButtonElement>.disabled?: boolean | undefined
disabled
={
const isGrantingPermissions: boolean
isGrantingPermissions
}>
{
const isGrantingPermissions: boolean
isGrantingPermissions
? "Granting..." : "Grant Permissions"}
</
React.JSX.IntrinsicElements.button: React.DetailedHTMLProps<React.ButtonHTMLAttributes<HTMLButtonElement>, HTMLButtonElement>
button
>
); }

Parameters

ParameterTypeDescription

params

UseGrantPermissionsParams

Configuration object containing the smart account client

Returns

UseGrantPermissionsResult

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