Documentation Index
Fetch the complete documentation index at: https://docs.sequence.xyz/llms.txt
Use this file to discover all available pages before exploring further.
Import
import { useExplicitSessions } from '@0xsequence/connect'
Usage
import { createContractPermission, useExplicitSessions, type ExplicitSessionParams, type ExplicitSession } from '@0xsequence/connect'
import { useEffect, useState } from 'react'
import { parseUnits } from 'viem'
function App() {
const {
isLoading,
error,
addExplicitSession,
modifyExplicitSession,
getExplicitSessions
} = useExplicitSessions()
const [sessions, setSessions] = useState<ExplicitSession[]>([])
// Load existing sessions
useEffect(() => {
const loadSessions = async () => {
try {
const existingSessions = await getExplicitSessions()
setSessions(existingSessions)
} catch (err) {
console.error('Failed to load sessions:', err)
}
}
loadSessions()
}, [getExplicitSessions])
// Function to handle modifying an existing explicit session
const handleModifySession = () => {
const newPermission = createContractPermission({
address: '0x...',
functionSignature: 'function testContract() public'
})
const currentSession = sessions[0]
const modifiedSession = { ...currentSession, permissions: [...currentSession.permissions!, newPermission] }
modifyExplicitSession(modifiedSession)
}
// Handle creating a new explicit session
const handleCreateSession = async () => {
try {
const tokenSpendingSession: ExplicitSessionParams = {
chainId: 42161,
nativeTokenSpending: {
valueLimit: 0n,
},
expiresIn: {
days: 3
},
permissions: [
createContractPermission({
address: '0x...',
functionSignature: 'function transfer(address to, uint256 amount)',
rules: [
{
param: 'amount',
type: 'uint256',
condition: 'LESS_THAN_OR_EQUAL',
value: parseUnits('100', 6), // Max cumulative amount of 100 USDC
cumulative: true
}
]
})
]
}
await addExplicitSession(tokenSpendingSession)
// Refresh sessions after creating a new one
const updatedSessions = await getExplicitSessions()
setSessions(updatedSessions)
} catch (err) {
console.error('Failed to create session:', err)
}
}
if (isLoading) {
return <div>Creating session...</div>
}
if (error) {
return <div>Error: {error.message}</div>
}
return (
<div>
<h2>Explicit Sessions</h2>
<button onClick={handleCreateSession}>
Create New Session
</button>
<button onClick={handleModifySession}>
Modify Session
</button>
<div>
<h3>Existing Sessions ({sessions.length})</h3>
{sessions.map((session, index) => (
<div key={index}>
<p>Session Address: {session.sessionAddress}</p>
<p>Chain ID: {session.chainId}</p>
<p>Permissions: {session.permissions?.map(permission => permission.target).join(', ')}</p>
</div>
))}
</div>
</div>
)
}
Return Type
The hook returns an object with the following properties:
type UseExplicitSessionsReturnType = {
isLoading: boolean
error: Error | null
addExplicitSession: (params: ExplicitSessionParams, includeFeeOptionPermissions?: boolean) => Promise<void>
modifyExplicitSession: (explicitSession: ExplicitSession) => Promise<void>
getExplicitSessions: () => Promise<ExplicitSession[]>
}
Properties
isLoading
boolean
A boolean indicating if the session request operation is in progress.
error
Error | null
An error object if the last operation failed, otherwise null.
addExplicitSession
(params: ExplicitSessionParams, includeFeeOptionPermissions?: boolean) => Promise<void>
type ExplicitSession = {
sessionAddress: Address.Address
valueLimit: bigint
deadline: bigint
permissions: Permission.Permission[]
chainId: number
type: 'explicit'
}
Function to create a new explicit session.
modifyExplicitSession
(explicitSession: ExplicitSession) => Promise<void>
type ExplicitSession = {
sessionAddress: Address.Address
valueLimit: bigint
deadline: bigint
permissions: Permission.Permission[]
chainId: number
type: 'explicit'
}
Function to modify an existing explicit session.
getExplicitSessions
() => Promise<ExplicitSession[]>
Function to get all explicit sessions for the connected wallet.
Notes
This hook provides functionality for managing explicit sessions in Sequence V3 wallet connections.
Key features:
- Create new explicit sessions with custom permissions and spending limits
- Retrieve all existing explicit sessions for the connected wallet
- Modify existing explicit sessions
- Built-in error handling for common connection issues
- Loading states for better user experience
- Automatic session filtering to only show explicit sessions