Skip to content

Grant Permission (Deferred)

grantDeferredPermission

This method is similar to grantPermission, but it allows you to create a session key with specific permissions that will only be activated on-chain at the moment they are first used. Unlike grantPermission which activates permissions immediately, grantDeferredPermission delays the on-chain activation until the exact moment the session key holder attempts to use it - providing a "just in time" permission grant.

Key Benefits

  • Gas Efficiency: No gas is spent until the permission is actually needed
  • Just-in-Time Activation: Permissions are only activated on-chain when first used
  • Flexible Deployment: Create session keys in advance without immediate blockchain costs

For example, you could create a session key for a future NFT mint, but the actual permission won't be registered on-chain until the user attempts to use it during the mint.

Usage

example.ts
import { usersNexusClient } from "./client"
import { smartSessionCreateActions } from "@biconomy/sdk"
 
const moduleData = await nexusSessionClient.grantDeferredPermission({
  sessionRequestedInfo: [
    {
      sessionPublicKey, // Public key of the session
      // sessionValidUntil: number
      // sessionValidAfter: number
      // chainIds: bigint[]
      actionPoliciesInfo: [
        {
          abi: CounterAbi,
          contractAddress: testAddresses.Counter
          // validUntil?: number
          // validAfter?: number
          // valueLimit?: bigint
        }
      ]
    }
  ]
})
 
const sessionData = {
  granter: nexusClient.account.address,
  sessionPublicKey,
  description: `Permission to increment a counter for ${testAddresses.Counter}`,
  moduleData
}
 
// Zip the session data, and store it for later use by a dapp
const stringifiedSessionDatum = stringify(sessionData)
 
// Later the dapp wants to use the session, it can use the stringified session data to use the permission

Parameters

ParameterTypeRequiredDescription
sessionPublicKeyAddressYesThe public key that will be authorized to use this session
sessionValidUntilnumberNoTimestamp when the session expires
sessionValidAfternumberNoTimestamp when the session becomes valid
chainIdsbigint[]NoArray of chain IDs where the session is valid
actionPoliciesInfoArrayYesContract permissions

Action Policies Info Structure

FieldTypeRequiredDescription
abiAbiYesContract ABI
contractAddressAddressYesContract address
validUntilnumberNoTimestamp when the permission expires
validAfternumberNoTimestamp when the permission becomes valid
valueLimitbigintNoMaximum value that can be transferred

Response

Returns a SessionData["moduleData"] object containing:

FieldTypeDescription
permissionIdsstring[]IDs of the granted permissions
actionobjectAction configuration
modeSmartSessionModeSession mode (typically UNSAFE_ENABLE)
sessionsSession[]Array of session configurations
enableSessionDataobjectSession enablement data