Implement session keys
It is strongly advised to only implement session keys in a project using starknetkit.
1. Installation
npm install @argent/x-sessions2. Import packages
import {
SignSessionError,
CreateSessionParams,
createSession,
buildSessionAccount,
bytesToHexString
} from "@argent/x-sessions"
import { ec } from "starknet"3. Session Configuration
The dapp will need to create a sessionKey . This is simply a private/public key pair.
const privateKey = ec.starkCurve.utils.randomPrivateKey();
const sessionKey: SessionKey = {
privateKey, //string
publicKey: ec.starkCurve.getStarkKey(privateKey), //string
};Define your session parameters:
The allowedMethods params represents which contracts calls the user will authorize the dapp to send on his behalf.
Expiry is a security measure. After the expiry date, the session becomes invalid.
3. Creating a Session
4. Executing Transactions
Best Practices
Set appropriate expiry times based on your use case
Limit allowed methods to only necessary functions
Set reasonable token spending limits
Implement proper error handling for session operations
Consider implementing session refresh mechanisms for long-running applications
Last updated
Was this helpful?