Skip to content
LogoLogo

tempo.session

Sessions client method

Choose a signing account

Create a server-only wallet.ts module, then import account wherever an example creates a local signing account.

wallet.ts
import { privateKeyToAccount } from 'viem/accounts'

export const account = privateKeyToAccount(process.env.PRIVATE_KEY as `0x${string}`)

Creates the low-level Tempo Sessions client method for Mppx.create.

Usage

With charge and session

Use the tempo() convenience function when you want the default Tempo charge and Sessions methods.

With Legacy Sessions

Use tempo.sessionLegacy.method() only for servers that still issue Legacy Sessions Challenges.

If a client must support both current and Legacy Sessions during migration, register both methods:

Return type

import type { Method } from 'mppx'
 
type ReturnType = Method.Client

Parameters

account (optional)

  • Type: Account

Account to sign channel transactions and vouchers with. You can override this per call using the context.

autoSwap (optional)

  • Type: boolean | { slippage?: number; tokenIn?: Address[] }

Automatically acquire the session currency from fallback stablecoins before opening or topping up a channel. Use the object form to set a maximum slippage percentage and the fallback token order.

channelStore (optional)

  • Type: ChannelStore

Pluggable persistence for reusable channels. Defaults to an in-memory store.

decimals (optional)

  • Type: number
  • Default: 6

Token decimals for parsing human-readable amounts.

escrow (optional)

  • Type: Address

Reserve precompile address override.

getClient (optional)

  • Type: (parameters: { chainId?: number }) => MaybePromise<Client>

Function that returns a viem client for the given chain ID.

maxDeposit (optional)

  • Type: string

Maximum deposit in human-readable units. Caps server-suggested channel opens and automatic top-ups.

onChannelUpdate (optional)

  • Type: (entry: ChannelEntry) => void

Called whenever channel state changes.

resolveAccount (optional)

  • Type: ResolveAccount

Selects the account that signs this session Credential after the Challenge is known.

topUpAmount (optional)

  • Type: string

Preferred automatic top-up size in human-readable units. When omitted, mppx uses a bounded server suggestedDeposit, then the exact shortfall.

Credential context

Most clients should omit context and let tempo.session() open, recover, top up, and voucher automatically from server Challenges. Advanced callers can pass context to method.createCredential() for manual Credentials or per-call overrides.

type SessionContext = {
  account?: Account
  action?: 'open' | 'topUp' | 'voucher' | 'close'
  channelId?: Hex
  cumulativeAmount?: string
  cumulativeAmountRaw?: string
  transaction?: Hex
  descriptor?: ChannelDescriptor
  additionalDeposit?: string
  additionalDepositRaw?: string
  depositRaw?: string
}
FieldDescription
accountAccount override for this Credential only.
actionManual Credential action. Omit for automatic session management.
channelIdChannel ID to reuse or manually operate on.
descriptorTIP-1034 descriptor required for recovery and manual Credentials.
transactionSigned Tempo transaction for manual open or topUp Credentials.
cumulativeAmountHuman-readable cumulative voucher authorization, parsed with decimals.
cumulativeAmountRawRaw cumulative voucher authorization. Takes precedence over cumulativeAmount.
additionalDepositHuman-readable top-up amount, parsed with decimals.
additionalDepositRawRaw top-up amount. Takes precedence over additionalDeposit.
depositRawRaw opening deposit override for automatic open Credentials.