Skip to content

Granting Smart Sessions Permissions

Grant specific permissions to validators across multiple chains using Smart Sessions.

Installation and Setup

import { 
  toSmartSessionsModule,
  toNexusAccount,
  createSmartAccountClient,
  getSudoPolicy
} from '@biconomy/abstractjs';
 
// Initialize your signer
const signer = yourSignerAccount;
 
// Create Nexus account
const nexusAccount = await toNexusAccount({
  signer,
  chain,
  transport: http(rpcUrl)
});
 
// Create client with your Nexus account
const nexusClient = createSmartAccountClient({
  chain,
  transport: http(rpcUrl),
  account: nexusAccount,
});

Install Smart Sessions Module

First, you need to install the Smart Sessions module on your account:

const smartSessionsModule = toSmartSessionsModule({ signer });
 
// Install the module on the Nexus client's smart contract account
const hash = await nexusClient.installModule({
  module: smartSessionsModule
});
 
// Wait for the module installation transaction to be mined
const { success } = await nexusClient.waitForUserOperationReceipt({ hash });

Grant Permission Example

Once the module is installed, you can grant permissions:

// Extend client with Smart Sessions actions
const smartSessionsClient = nexusClient.extend(smartSessionActions());
 
// Grant permission to a specific address (redeemer)
const sessionDetails = await smartSessionsClient.grantPermission({
  redeemer: redeemerAddress, // Address that will use the permission
  actions: [
    {
      actionTarget: targetContractAddress, // Target contract address
      actionTargetSelector: "0x273ea3e3", // Function selector (e.g., increment())
      actionPolicies: [getSudoPolicy()] // getSpendingLimitsPolicy, getUsageLimitPolicy, getValueLimitPolicy
    }
  ]
});
 
// Save the sessionDetails for later use when redeeming the permission. 
// Can be saved against a users smart account address on local storage or database
// for later redemption
console.log('Permission granted:', sessionDetails);

Multi-chain Permission Usage

Coming Soon