Implement session keys

It is strongly advised to only implement session keys in a project using starknetkit.

1. Installation

npm install @argent/x-sessions

2. 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

  1. Set appropriate expiry times based on your use case

  2. Limit allowed methods to only necessary functions

  3. Set reasonable token spending limits

  4. Implement proper error handling for session operations

  5. Consider implementing session refresh mechanisms for long-running applications

Last updated

Was this helpful?