grantPermissions

Grants permissions to a smart account by creating a session. This allows another key to perform operations on behalf of the account.

Import

1import { grantPermissions } from "@account-kit/wallet-client";

Usage

1// Create a session key and grant root permissions
2const sessionKey = LocalAccountSigner.generatePrivateKeySigner();
3const account = await client.requestAccount();
4
5const permissions = await client.grantPermissions({
6 account: account.address,
7 expirySec: Math.floor(Date.now() / 1000) + 60 * 60, // 1 hour from now
8 key: {
9 publicKey: await sessionKey.getAddress(),
10 type: "secp256k1",
11 },
12 permissions: [{ type: "root" }],
13});
14
15// Use the permissions to prepare a call
16const preparedCalls = await client.prepareCalls({
17 calls: [{ to: zeroAddress, value: "0x0" }],
18 from: account.address,
19 capabilities: {
20 paymasterService: {
21 policyId: "your-paymaster-policy-id",
22 },
23 permissions,
24 },
25});
26
27// Sign with the session key
28const signedCalls = await signPreparedCalls(sessionKey, preparedCalls);
29
30// Send the prepared call using the session key
31const result = await client.sendPreparedCalls({
32 ...signedCalls,
33 capabilities: {
34 permissions,
35 },
36});

Parameters

client

InnerWalletApiClient

  • The wallet API client to use for the request

signer

SmartAccountSigner

  • The signer of the smart account

params

GrantPermissionsParams

  • The parameters for granting permissions

params.account

Address

  • The account address (required if client was not initialized with an account)

params.expirySec

number

  • Unix timestamp when the permissions expire

params.key

sessionKeyData

  • The session key information

params.key.publicKey

string

  • The public key of the session key

params.key.type

string

  • The type of the key (e.g., “secp256k1”)

params.permissions

Array

  • Array of permission objects defining what the session key can do

Returns

Promise<GrantPermissionsResult> A Promise that resolves to the result containing a context identifier