Skip to content

Execute session

The executeEVMSession and executeSolanaSession actions orchestrate the process required to complete a Glide session using the user's wallet. More specifically, they:

  1. Switch the user's wallet to the correct chain (EVM only).
  2. Trigger the payment transaction using the user's wallet and update Glide with the transaction hash.
  3. If gasless payment is available (EVM only), instead of a payment transaction, the user is prompted to sign a message to authorize the payment. The signature is submitted to Glide.
  4. Wait for the Glide session to be completed.
  5. Return the completed session object, including the sponsoredTransactionHash.

If the session is expired, or is about to expire in the next 30 seconds, a SessionExpiredError is thrown without prompting the user.

Import

import { executeEVMSession, executeSolanaSession } from "@paywithglide/glide-js";

Usage

EVM

index.ts
import { createSession, executeEVMSession } from "@paywithglide/glide-js";
import { config } from "./config";
 
const session = await createSession(config, {...});
 
const { sponsoredTransactionHash } = await executeEVMSession(config, {
  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
    // return the transaction hash
  },
  signTypedDataAsync: async (typedData) => {
    // sign the typed data using the user's wallet
    // return the signature
  },
});

Solana

index.ts
import { createSession, executeSolanaSession } from "@paywithglide/glide-js";
import { config } from "./config";
 
const session = await createSession(config, {...});
 
const { sponsoredTransactionHash } = await executeSolanaSession(config, {
  session,
 
  signAndSendTransaction: async (tx) => {
    // sign and send the VersionedTransaction using the user's Solana wallet
    // return the transaction signature
  },
});

Parameters

executeEVMSession

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, account?: Hex, to: Hex, data?: Hex, value?: bigint}) => Promise<Hex>

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

signTypedDataAsync
nullable (PermitTypedData) => Promise<Hex>

A function that signs typed data using the user's wallet. Returns the signature. Required for gasless payments, i.e. when the session's paymentAction is signTypedData.

onCompletePayment
nullable () => void

A callback invoked right after the user has completed their payment transaction or signature, before waiting for the session to complete.

onSessionUpdate
nullable (session: Session) => void

A callback invoked with the latest session object every time the session is polled while waiting for it to complete.

executeSolanaSession

session*
Session

The session object returned from the createSession action.

signAndSendTransaction*
(tx: VersionedTransaction) => Promise<string>

A function that signs and sends the Solana transaction using the user's wallet. Returns the transaction signature.

onCompletePayment
nullable () => void

A callback invoked right after the user has completed their payment transaction, before waiting for the session to complete.

onSessionUpdate
nullable (session: Session) => void

A callback invoked with the latest session object every time the session is polled while waiting for it to complete.

Return Type

Returns the completed session object with sponsoredTransactionHash guaranteed to be set.

sessionId*
string
The unique identifier of the session.
createdAt*
string
The timestamp at which the session was created.
expiresAt*
string
The timestamp at which the session will expire. Generally, this will be 10 minutes after the session is created.
expired*
boolean
A boolean indicating whether the session has expired.
etaInSeconds*
number
Number of seconds it is expected to take for the sponsored transaction after the user has paid for the transaction.
payerAccount
nullable string
The account id that will pay for the transaction. It can be the wallet address when the payment method is wallet.
paymentStatus*
PaymentStatus
The current status of the payment for the session, one of `unpaid`, `waiting_confirmations`, `paid`, `pending_refund`, or `refunded`. The session begins in the unpaid state and transitions to paid when the user completes their payment transaction.
paymentChainId*
CAIP2
The chain id on which the user will pay for the transaction.
paymentChainName*
string
The chain name on which the user will pay for the transaction.
paymentChainLogoUrl*
string
The chain logo URL on which the user will pay for the transaction.
paymentCurrency*
CAIP19
The currency in which the user pays in the CAIP-19 format.
paymentCurrencySymbol*
string
The currency symbol in which the user pays.
paymentCurrencyLogoUrl*
string
The currency logo URL in which the user pays.
paymentCurrencyTier*
'tier1' | 'tier2' | 'tier3'
The currency tier in which the user pays.
paymentAmount*
string
The amount of the payment required by the user to complete the transaction in a human-readable format.
paymentAmountUSD*
string
The amount of the payment required by the user to complete the transaction in USD.
paymentTransactionHash
nullable Hex | null
The hash of the transaction that the user made to complete the payment.
paymentTransactionUrl
nullable string | null
The explorer URL for the payment transaction.
paymentAction*
'signAndSendTransaction' | 'signTypedData' | 'redirectToUrl' | 'transfer'
The action that the user must take to complete the payment.
unsignedTransaction
nullable EVMTransactionResponse | null
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`.
unsignedSolanaTransaction
nullable { message: string } | { transaction: string } | null
The base64-encoded Solana message or transaction that the user must sign and send to complete the payment. It is set when the payment is made on Solana and the `paymentAction` is set to `signAndSendTransaction`.
unsignedTypedData
nullable PermitTypedData<Hex> | null
The typed data that the user must sign to complete the payment. It is set when the `paymentAction` is set to `signTypedData`.
redirectUrl
nullable string | null
The URL that the user must be redirected to complete the payment. It is set when the `paymentAction` is set to `redirectToUrl`.
depositAddress
nullable Hex | null
The deposit address that the payment must be sent to. It is set when the `paymentAction` is set to `transfer`.
sponsoredTransactionChainId*
CAIP2
The chain id on which the transaction will be executed.
sponsoredTransactionChainName*
string
The chain name on which the transaction will be executed.
sponsoredTransactionChainLogoUrl*
string
The chain logo URL on which the transaction will be executed.
sponsoredTransactionStatus*
TransactionStatus
The current status of the transaction that Glide is sending to the chain on behalf of the user, one of `created`, `submitted`, `signed`, `pending`, `success`, `failed`, or `dropped`.
sponsoredTransactionHash
nullable Hex | null
The hash of the transaction that Glide sent to the chain on behalf of the user.
sponsoredTransactionUrl
nullable string | null
The explorer URL for the sponsored transaction.
sponsoredTransaction
nullable EVMTransaction | null
The transaction that Glide sent to the chain on behalf of the user.
sponsoredTransactionAmount*
string
The amount required by the sponsored transaction, in a human-readable format.
sponsoredTransactionCurrency*
CAIP19
The currency in which the sponsored transaction is executed, in CAIP-19 format.
sponsoredTransactionCurrencySymbol*
string
The currency symbol in which the sponsored transaction will be executed.
sponsoredTransactionCurrencyLogoUrl*
string
The currency logo URL in which the sponsored transaction will be executed.
sponsoredTransactionAmountUSD*
string
The amount required by the sponsored transaction, in USD.
serviceFeeUSD*
string
The Glide service fee in USD for this transaction.
gasFeeUSD*
string
The gas fee, estimated required for the transaction, in USD.
paymentTransactionGasFeeUSD*
string
The gas fee the user pays to execute their payment transaction, in USD.
totalFeeUSD*
string
The total fee including gas fee, service fee, commission, and payment transaction gas fee, in USD.
metadata*
string
The metadata associated with the session.
gasRefuelAmount
nullable string
The amount of gas refueled, in the native currency.
gasRefuelUSD
nullable string
The USD value of the gas refueled.
gasRefuelTransactionStatus
nullable TransactionStatus
The status of the gas refuel transaction.
gasRefuelTransactionHash
nullable Hex
The hash of the gas refuel transaction.
gasRefuelTransactionUrl
nullable string
The explorer URL for the gas refuel transaction.
refundTransactionHash
nullable string
The hash of the refund transaction, if the payment was refunded.
refundTransactionUrl
nullable string
The explorer URL for the refund transaction.
refundAddress
nullable string
The address the refund was sent to.