Before doing anything with the SessionKeyValidatorSDK, you must ensure that the walletPrivateKey being used must have a etherspot-modular-account. SessionKeys can be created on an existing etherspotModularWallet with ERC20SessionKeyValidator installed to it

For Steps to install ERC20SessionKeyValidator, please follow instructions in: install-module

Step 1. set .env variables via export or in your .env If you chose to use them directly skip to Step-2

export WALLET_PRIVATE_KEY=''
export CHAIN_ID=
export API_KEY=''

Step 2. Import the Etherspot Modular SDK.

  import { ModularSdk, SessionKeyValidator } from '@etherspot/modular-sdk';

Step 3. Instantiate the SDK with below initialisation properties using this block of code.

  • privateKey
  • ChainID
  • bundlerProvider
  • bundlerApiKey
  • customBundlerUrl (can be left empty)

import { EtherspotBundler, ModularSdk, SessionKeyValidator, KeyStore, sleep } from '@etherspot/modular-sdk';
import * as dotenv from 'dotenv';

dotenv.config();

const bundlerApiKey = process.env.API_KEY as string;
const chainId = Number(process.env.CHAIN_ID);
const privateKey = process.env.WALLET_PRIVATE_KEY as string;
const customBundlerUrl = '';

const modularSdk = new ModularSdk(
  { 
    privateKey: privateKey 
  }, 
  { 
    chainId: chainId, 
    bundlerProvider: new EtherspotBundler(chainId, 
    bundlerApiKey, customBundlerUrl) 
  }
);

// get instance  of SessionKeyValidator
const sessionKeyModule = await SessionKeyValidator.create(
  modularSdk,
  new EtherspotBundler(chainId, bundlerApiKey)
)

And that’s it! You’re now ready to call any of the SessionKeyValidator SDK functions.

You can also pass in different parameters when instantiating the SDK.

  • chainId : The chain ID of the blockchain.
  • customBundlerUrl : The bundler you wish to use.

In the next page we’ll take a look at the various functions the SessionKeyValidator SDK offers.