Skip to content
LogoLogo

Guest checkout

A visitor pays from a guest account, whose key pair the app keeps in its store, with no Tempo ID user.

Overview

A guest session signs a visitor in with no Tempo ID user. The instance keeps a P256 key pair in its store, and the key pair owns a root Tempo Account, the guest account.

Tempo ID issues a guest session no tokens and no access key. The key pair signs each payment and transaction of the visitor in the app. Guest sessions describes the side of Tempo ID.

The demo signs a visitor in as a guest, and pays 1 OUSD from the guest account. A new guest account holds no funds, so Deposit on the payment page offers the testnet faucet.

Pay as a guestDemo

Walkthrough

These steps build a React app that signs a visitor in as a guest, and takes a payment from the guest account.

Install the packages

Create the instance

With guest: true, each sign-in offers Continue as guest, beside the passkey and the emailed code. An instance without it never holds a guest session.

In a browser, the default store is IndexedDB. It keeps the key pair as a non-extractable CryptoKey.

tempo.config.ts
import { Accounts } from 'accounts'
import { viem } from 'accounts/plugins'
import { react } from 'accounts/react'
 
export const accounts = Accounts.create({
  chain: 'testnet',
  guest: true, 
  plugins: [react(), viem()],
})

Sign the visitor in

dialog.signIn opens the sign-in of Tempo ID. If the visitor selects Continue as guest, the instance loads or creates the key pair, and resolves with a guest session.

A guest session holds the address of the guest account, and its kind is 'guest'. The store keeps the key pair under its own entry, so the session holds no private key.

import { Checkout } from './Checkout.js'
import { accounts } from './tempo.config.js'
 
export function App() {
  const { session } = accounts.useSession()
 
  if (!session)
    return (
      <button onClick={() => accounts.dialog.signIn()} type="button">
        Sign in with Tempo
      </button>
    )
 
  const label =
    session.kind === 'guest'
      ? `Guest account ${session.address}`
      : `Signed in as ${session.user.email}`
 
  return (
    <main>
      <p>{label}</p>
      <Checkout />
    </main>
  )
}

A call that reads Tempo ID, such as a read of the access token, throws Accounts.GuestSessionError with a guest session.

Pay

With a guest session, accounts.pay opens the payment page of Tempo ID for the guest account, in a dialog. The visitor selects Pay, and the key pair signs the transfer in the page of the app.

The token is a symbol that the chain lists, such as ousd, or the address of a TIP-20 token. The key pair signs one transaction for each call, which makes exactly the requested transfer.

import { useState } from 'react'
import { accounts } from './tempo.config.js'
 
export function Checkout() {
  const [transaction, setTransaction] = useState<string>()
 
  return (
    <>
      <button
        onClick={async () => {
          const { transaction } = await accounts.pay({
            amount: '5',
            to: '0x000000000000000000000000000000000000dEaD',
            token: 'ousd',
          })
          setTransaction(transaction)
        }}
        type="button"
      >
        Pay 5 OUSD
      </button>
      {transaction && <p>Paid in {transaction}.</p>}
    </>
  )
}

A new guest account holds no funds. If it holds less than the payment, Deposit on the payment page opens the deposit pages of Tempo ID for the guest account.

Deposit methodFor a guest
Tempo transferOffered on every chain, to the guest account's address
EVM bridgeOffered on Tempo mainnet, for an OUSD payment
Buy MACHNot offered, since its cards and receipts need a user
Swap from the balanceNot offered, since the key pair signs only the payment

Done returns to the same checkout, and Pay enables once the funds arrive. On a test chain, the deposit pages also offer the faucet of the token.

Use cases

Pay without a session

With guest: true and no session, accounts.pay opens the signed-out payment page, which offers Continue as guest. That selection starts the guest session, and the same page pays from the guest account.

If the visitor signs in instead, the page pays from the account of the user. A call with challenge, or an instance with the siwe plugin, offers no guest.

import { accounts } from './tempo.config.js'
 
export function Checkout() {
  return (
    <button
      onClick={async () => {
        // With no session, the payment page signs the visitor in, or starts a guest session.
        const { transaction } = await accounts.pay({
          amount: '5',
          to: '0x000000000000000000000000000000000000dEaD',
          token: 'ousd',
        })
        console.log(transaction)
      }}
      type="button"
    >
      Pay 5 OUSD
    </button>
  )
}

Offer a guest in each sign-in flow

With guest: true, each sign-in plugin offers Continue as guest, and resolves with a guest session after that selection.

Sign-inReturns the selection
dialog.signIn, in a frame or a popupThe frame's or the popup's message
redirect.signInThe redirect URI with guest=1, which the next load of the page completes
device.signInThe refusal guest_selected of the next poll, which the plugin turns into the session

Outside a browser, Store.file keeps the key pair in a file that only the user reads. The expo preset keeps it in the secure store of the device.

A store that other parties read, such as Store.postgres, refuses the key pair. So does Store.memory in a page, since a reload loses the funds.

tempo.config.ts
import { Accounts, Store } from 'accounts'
import { device } from 'accounts/plugins'
 
export const accounts = Accounts.create({
  chain: 'testnet',
  clientId: 'cli:acme-example',
  guest: true, 
  plugins: [
    device({
      onCode: (code) =>
        console.log(
          `Open ${code.verificationUriComplete} and confirm the code ${code.userCode}.`,
        ),
    }),
  ],
  // The key pair of the guest account stays in this file.
  store: Store.file('~/.acme/accounts.json'),
})

Sign a guest in to the app

With the siwe plugin on the page, dialog.signIn offers Continue as guest too. After that selection, the guest key pair signs the plugin's message, and the call posts the signature to the verify route before it sets the guest session.

The call returns the verify route's JSON object as auth, as for a Tempo ID sign-in. The guest account is a root Tempo Account, so the route verifies its P256 signature as the account's own. Sign in with the plugin on the page describes the routes.

import { accounts } from './tempo.config.js'
 
export function SignIn() {
  return (
    <button
      onClick={async () => {
        // A guest or a Tempo ID user, signed in to the app's routes either way.
        const { auth } = await accounts.dialog.signIn()
        console.log(auth)
      }}
      type="button"
    >
      Sign in
    </button>
  )
}

Pay from a CLI

Outside a page, accounts.pay pays from the guest account through the routes of Tempo ID, with no page. Actions.guest.pay describes each request and check.

Guest accountWhat pay does
Holds the paymentPays at once
Short, on a test chainRequests the chain's faucet, then pays
Short, on another chainPasses a funding code to the device plugin's onCode, waits for the funds until the code expires, then pays
Short, without deviceRejects with Accounts.RequestError and the reason insufficient_balance

If Tempo ID and the chain confirm no outcome, the call rejects with Actions.guest.PendingError, which names the checkout. The store keeps no record of the checkout, so the app confirms its outcome before it pays again.

import { accounts } from './tempo.config.js'
 
const session = (await accounts.session.get()) ?? (await accounts.device.signIn())
if (session.kind === 'guest') console.log(`Paying as guest ${session.address}.`)
 
const { transaction } = await accounts.pay({
  amount: '5',
  to: '0x000000000000000000000000000000000000dEaD',
  token: 'ousd',
})
console.log(`Paid in ${transaction}.`)

Send a transaction with Viem

The viem plugin's client signs each transaction of a guest session with the key pair, as the root account. Its relay pays fees as for any session. Viem covers the client.

import { parseUnits } from 'viem'
import { Addresses } from 'viem/tempo'
import { accounts } from './tempo.config.js'
 
export function Send() {
  return (
    <button
      onClick={async () => {
        const { receipt } = await accounts.viem.token.transferSync({
          amount: parseUnits('1', 6),
          to: '0x000000000000000000000000000000000000dEaD',
          token: Addresses.ousd,
        })
        console.log(receipt.transactionHash)
      }}
      type="button"
    >
      Send 1 OUSD
    </button>
  )
}

Pay MPP charges

With a guest session, the mpp plugin pays each charge and voucher with the key pair. No access key limits the guest account, so a charge needs maxAmount, and a payment session maxDeposit.

Without the capError
A charge above 0mpp.MaxAmountRequiredError, before the key pair signs
A payment sessionmpp.MaxDepositRequiredError, before any request
A malformed maxDepositmpp.MaxDepositInvalidError, for a value other than a decimal above 0 with at most 6 decimals
import { accounts } from './tempo.config.js'
 
export function Fortune() {
  return (
    <button
      onClick={async () => {
        const response = await accounts
          .mpp({ maxAmount: '0.05' }) 
          .fetch('https://api.example.com/fortune')
        console.log(await response.json())
      }}
      type="button"
    >
      Fetch a fortune
    </button>
  )
}

Forget the guest account

accounts.signOut ends the guest session and keeps the key pair, so the next guest session holds the same guest account. accounts.guest.get returns its address.

accounts.guest.disconnect removes the key pair from the store, and signs out a guest session. The funds stay on the address, and no key signs for it again.

import { accounts } from './tempo.config.js'
 
export function Forget() {
  return (
    <button
      onClick={async () => {
        const address = await accounts.guest.get()
        if (!address) return
        // The funds of `address` stay there, with no signer.
        await accounts.guest.disconnect() 
      }}
      type="button"
    >
      Forget the guest account
    </button>
  )
}

Limitations

  • A guest pays only in the token of the payment. A payment that needs a swap shows a shortfall.
  • The deposit pages offer a guest no Buy MACH and no swap. The EVM bridge pays only an OUSD payment on Tempo mainnet.
  • A guest session holds no access key. It takes no accessKey or challenge sign-in, and pays no MPP subscription.
  • The guest key pair signs the siwe plugin's message only in dialog.signIn. A payment with the plugin and without a session offers no guest.
  • A sign-in through the backend plugin never offers a guest.
  • A guest account has no passkey and no Tempo ID user. No sign-in turns it into a configurable account.
  • Outside a page, a short guest account on a chain without a faucet needs the device plugin's onCode to show its funding code.

Next steps