> **Can't find what you're looking for?** Use `search_docs` on the docs MCP server at `https://www.openfort.io/api/mcp` to find what you need.
>
> **Have feedback?** Use `submit_feedback` on the same MCP server.

# `useGrantPermissions`

Grant permissions to session keys using EIP-7715 for scoped, time-limited transactions.
Both `useGrantPermissions` and `useRevokePermissions` use the Ethereum bridge directly (no SIWE dependency). External wallets (e.g. MetaMask) connected via wagmi work for session key grant/revoke.

## Usage

```tsx
import { generatePrivateKey, privateKeyToAccount } from 'viem/accounts';
import { useGrantPermissions } from '@openfort/react';

function CreateSessionKey() {
  const { grantPermissions, isLoading } = useGrantPermissions();

  const handleCreate = async () => {
    const sessionKey = generatePrivateKey();
    const sessionAccount = privateKeyToAccount(sessionKey);

    // Store the session key. You need it later to sign transactions.
    localStorage.setItem('sessionKey', sessionKey);

    const result = await grantPermissions({
      sessionKey: sessionKey,
      request: {
        signer: {
          type: 'account',
          data: { id: sessionAccount.address },
        },
        expiry: 60 * 60 * 24, // 24 hours
        permissions: [
          {
            type: 'contract-call',
            data: {
              address: '0x2522f4fc9af2e1954a3d13f7a5b2683a00a4543a',
              calls: [],
            },
            policies: [],
          },
        ],
      },
    });

    console.log('Permissions granted:', result.address);
  };

  return <button onClick={handleCreate} disabled={isLoading}>Create Session Key</button>;
}
```

## Return type

```ts
type UseGrantPermissionsReturn = {
  grantPermissions(params: GrantPermissionsParams, options?: GrantPermissionsHookOptions): Promise<GrantPermissionsHookResult>
  data: GrantPermissionsResult | null
  reset(): void
  isLoading: boolean
  isError: boolean
  isSuccess: boolean
  error: OpenfortError | null | undefined
}

type GrantPermissionsResult = {
  address: `0x${string}`  // Wallet that granted permissions
} & GrantPermissionsReturnType  // From viem/experimental

type GrantPermissionsHookResult = {
  error?: OpenfortError
} & Partial<GrantPermissionsResult>
```

## Hook options

Configure default behavior when initializing the hook.

```ts
type GrantPermissionsHookOptions = {
  onSuccess?: (data: GrantPermissionsHookResult) => void
  onError?: (error: OpenfortError) => void
  throwOnError?: boolean
}
```

## Parameters

### grantPermissions

Both hooks support an optional `walletClient` override for non-wagmi external wallets. Resolution order: explicit `walletClient` → wagmi bridge → embedded wallet fallback.

```ts
type GrantPermissionsParams = {
  request: GrantPermissionsParameters  // From viem/experimental
  sessionKey: Hex                      // Required session key (hex-encoded private key)
}

// GrantPermissionsParameters includes:
type GrantPermissionsParameters = {
  signer: {
    type: 'account'
    data: { id: string }  // Session account address
  }
  expiry: number  // Duration in seconds
  permissions: Permission[]
}

type Permission = {
  type: 'contract-call' | 'native-token-transfer' | 'erc20-transfer' | 'erc721-transfer' | 'erc1155-transfer'
  data: {
    address: string
    calls?: []
  }
  policies?: []
}
```

## Related

* [Session Keys Guide](https://www.openfort.io/docs/products/embedded-wallet/react/wallet/actions/session-keys)
* [useRevokePermissions](https://www.openfort.io/docs/products/embedded-wallet/react/hooks/useRevokePermissions)
