Smart Sessions are a powerful feature that allows you to request specific permissions from your users’ wallets, before you need them. Permission requests are baked into the connection request, so you can authenticate and request permissions in one step. Then, you can use the provided session key to execute transactions under the rules you defined, without any additional pop-ups.

🔧 Complete Configuration Example

Here is a complete example of how to configure your app to request approve and transfer permissions, using the Web SDK.
import { createConfig } from '@0xsequence/connect'
import { ChainId } from '@0xsequence/network'
import { Utils } from '@0xsequence/wallet-core'

// 1. Define the addresses for your dApp
const USDC_ADDRESS = '0xaf88d065e77c8cC2239327C5EDb3A432268e5831'
const DAPP_CONTRACT_ADDRESS = '0x1234.....' // Your dApp's main contract

// 2. Add the `permissions` object to your main configuration
export const config = createConfig({
  // ... your other project configurations like projectAccessKey, defaultTheme, etc.

  // This is where you define the rules for the user's session
  permissions: { 
    // The chain where these rules apply
    chainId: ChainId.ARBITRUM,

    // The total amount of native currency (e.g., ETH) the session can spend.
    // For token permissions, this should be 0.
    valueLimit: 0n,

    // Set a time limit for how long the session is valid (e.g., 24 hours)
    deadline: BigInt(Math.floor(Date.now() / 1000) + 3600 * 24),
    
    // This array holds the specific permissions you are requesting
    permissions: [

      // Rule #1: The 'Approve' Permission
      Utils.ERC20PermissionBuilder.buildApprove(
        USDC_ADDRESS,
        DAPP_CONTRACT_ADDRESS,
        100000000n // A spending limit of 100 USDC (with 6 decimals)
      ),

      // Rule #2: The 'Transfer' Permission
      Utils.ERC20PermissionBuilder.buildTransfer(
        USDC_ADDRESS,
        100000000n // A spending limit of 100 USDC (with 6 decimals)
      )
    ]
  }
})

📋 Configuration Parameters

ParameterTypeDescription
chainIdChainIdThe blockchain where permissions apply
valueLimitbigintNative currency spending limit (use 0n for token-only permissions)
deadlinebigintSession expiration timestamp
permissionsArrayList of specific permission rules

🎯 Permission Types

Approve Permission

Utils.ERC20PermissionBuilder.buildApprove(
  tokenAddress,    // The ERC20 token contract
  spenderAddress,  // Your dApp's contract that can spend tokens
  amountLimit      // Maximum tokens that can be approved
)

Transfer Permission

Utils.ERC20PermissionBuilder.buildTransfer(
  tokenAddress,    // The ERC20 token contract
  amountLimit      // Maximum tokens that can be transferred
)

✨ Result

With this configuration:
  • One-time approval when user connects
  • Zero pop-ups for subsequent approve/transfer actions
  • Automatic expiration after 24 hours or spending limit reached
  • Secure boundaries enforced on-chain