Skip to content
Alchemy Logo

grantPermissions

function grantPermissions<TAccount>(
  client,
  signer,
  params,
): Promise<GrantPermissionsResult>;

Defined in: account-kit/wallet-client/src/client/actions/grantPermissions.ts:94

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

// Create a session key and grant root permissions
const sessionKey = LocalAccountSigner.generatePrivateKeySigner();
const account = await client.requestAccount();
 
const permissions = await client.grantPermissions({
  account: account.address,
  expirySec: Math.floor(Date.now() / 1000) + 60 * 60, // 1 hour from now
  key: {
    publicKey: await sessionKey.getAddress(),
    type: "secp256k1",
  },
  permissions: [{ type: "root" }],
});
 
// Use the permissions to prepare a call
const preparedCalls = await client.prepareCalls({
  calls: [{ to: zeroAddress, value: "0x0" }],
  from: account.address,
  capabilities: {
    paymasterService: {
      policyId: "your-paymaster-policy-id",
    },
    permissions,
  },
});
 
// Sign with the session key
const signedCalls = await signPreparedCalls(sessionKey, preparedCalls);
 
// Send the prepared call using the session key
const result = await client.sendPreparedCalls({
  ...signedCalls,
  capabilities: {
    permissions,
  },
});

Type ParameterDefault type

TAccount extends undefined | `0x${string}`

undefined | `0x${string}`

ParameterTypeDescription

client

InnerWalletApiClient

The wallet API client to use for the request

signer

SmartWalletSigner

The signer of the smart account

params

{ [K in string | number | symbol]: (Omit<{} & {}, "account" | "chainId"> & (IsUndefined<TAccount> extends true ? { account: `0x${string}` } : { account?: undefined }))[K] }

The parameters for granting permissions

Promise<GrantPermissionsResult>

A Promise that resolves to the result containing a context identifier

Was this page helpful?