The createSessionClient
function creates a new SessionClient
instance directly, without requiring an existing AbstractClient.
If you have an existing AbstractClient, use the toSessionClient method instead.
Usage
import { createSessionClient } from "@abstract-foundation/agw-client/sessions";
import { abstractTestnet } from "viem/chains";
import { http, parseAbi } from "viem";
import { privateKeyToAccount, generatePrivateKey } from "viem/accounts";
// The session signer (from createSession)
const sessionPrivateKey = generatePrivateKey();
const sessionSigner = privateKeyToAccount(sessionPrivateKey);
// Create a session client directly
const sessionClient = createSessionClient({
account: "0x1234...", // The Abstract Global Wallet address
chain: abstractTestnet,
signer: sessionSigner,
session: {
// ... See createSession docs for session configuration options
},
transport: http(), // Optional - defaults to http()
});
// Use the session client to make transactions
const hash = await sessionClient.writeContract({
address: "0xC4822AbB9F05646A9Ce44EFa6dDcda0Bf45595AA",
abi: parseAbi(["function mint(address,uint256) external"]),
functionName: "mint",
args: [address, BigInt(1)],
});
Parameters
account
Account | Address
required
The Abstract Global Wallet address or Account object that the session key will act on behalf of.
The chain configuration object that supports EIP-712.
The session key account that will be used to sign transactions. Must match the signer address in the session configuration.
The transport configuration for connecting to the network. Defaults to HTTP if not provided.
Returns
A new SessionClient instance that uses the session key for signing transactions. All transactions will be validated against the session’s policies.