Skip to content

Execute session

The executeSession action orchestrates the process required to make a cross-chain, cross-token, and gasless payment using Glide. More specifically, it:

  1. Switches the user's wallet to the correct chain.
  2. Triggers the payment transaction using the user's wallet and updates Glide with the transaction hash.
  3. If gasless payment is available, instead of a payment transaction, the user is prompted to sign a message to authorize the payment. The signature is submitted to Glide.
  4. Waits for the Glide session to be completed.
  5. Returns a complete session object.

Import

import { executeSession } from "@paywithglide/glide-js";

Usage

index.ts
import { createSession, executeSession currencies, chains } from "@paywithglide/glide-js";
import { config } from "./config";
 
const session = await createSession(config, {...});
 
const { sponsoredTransactionHash } = await executeSession(glideConfig, {
  session,
  currentChainId: 1,
 
  switchChainAsync: async (chainId) => {
    // switch current chain to chainId on the user's wallet
  },
  sendTransactionAsync: async (tx) => {
    // send tx to the chain using the user's wallet
  },
  signTypedDataAsync: async (data) => {
    // sign typed data using the user's wallet
    // return the signature
  },
});

Parameters

session*
Session

The session object returned from the createSession action.

currentChainId*
number

The EIP-155 chain ID of the chain that the user's wallet is currently connected to.

switchChainAsync*
({chainId: number}) => Promise<unknown>

A function that switches the user's wallet to the specified chain.

sendTransactionAsync*
({chainId: number, to: string, data?: string, value?: bigint}) => Promise<string>

A function that sends a transaction to the specified chain using the user's wallet. Returns the transaction hash.

signTypedDataAsync
nullable (EIP712TypedData) => Promise<string>

A function that signs typed data using the user's wallet. Returns the signature. Used to enable gasless transactions.

Return Type

sessionId *
string
The unique identifier of the session.
expiresAt*
string
The timestamp at which the session will expire. Generally, this will be 10 minutes after the session is created.
paymentStatus*
PaymentStatus
The current status of the payment for the session. The session begins in the unpaid state and transitions to paid when the user complets their payment transaction.
paymentCurrency*
CAIP19 | Currency
The currency in which the user pays in the CAIP-19 format.
paymentAmount*
string
The amount of the payment required by the user to complete the transaction in a human-readable format.
paymentTransactionHash
nullable string
The hash of the transaction that the user made to complete the payment.
paymentAction*
enum
The action that the user must take to complete the payment. Either `signAndSendTransaction` or `signTypedData`.
unsignedTransaction
nullable EVMTransaction
The transaction that the user must sign and send to the chain to complete the payment. It is set when the `paymentAction` is set to `signAndSendTransaction`.
chainId*
string
The CAIP-2 chain ID of the chain where the transaction will be executed.
from*
string
The user's wallet address from which the transaction will be sent.
to*
string
The address of the contract to which the transaction will be sent.
value*
string
The hex-encoded amount of the payment in the smallest unit of the currency.
input*
string
The hex-encoded data to be sent to the contract.
unsignedTypedData
nullable EIP712TypedData
The typed data that the user must sign to complete the payment. It is set when the `paymentAction` is set to `signTypedData`.
sponsoredTransactionStatus*
TransactionStatus
The current status of the transaction that Glide is sending to the chain on behalf of the user.
sponsoredTransactionHash
nullable string
The hash of the transaction that Glide sent to the chain on behalf of the user.