Skip to content
Alchemy Logo

grantPermissions

function grantPermissions(
  client,
  params,
): Promise<{
  context: `0x${string}`;
}>;

Defined in: packages/wallet-apis/src/actions/grantPermissions.ts:82

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: 0n }],
  from: account.address,
  capabilities: {
    paymaster: {
      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,
  },
});

ParameterTypeDescription

client

InnerWalletApiClient

The wallet API client to use for the request

params

Object

The parameters for granting permissions

Promise<{ context: `0x${string}`; }>

A Promise that resolves to the result containing a context identifier

Was this page helpful?