Execute session
The executeEVMSession and executeSolanaSession actions orchestrate the process required to complete a Glide session using the user's wallet. More specifically, they:
- Switch the user's wallet to the correct chain (EVM only).
- Trigger the payment transaction using the user's wallet and update Glide with the transaction hash.
- 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.
- Wait for the Glide session to be completed.
- 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
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
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
The session object returned from the createSession action.
The EIP-155 chain ID of the chain that the user's wallet is currently connected to.
A function that switches the user's wallet to the specified chain.
A function that sends a transaction to the specified chain using the user's wallet. Returns the transaction hash.
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.
A callback invoked right after the user has completed their payment transaction or signature, before waiting for the session to complete.
A callback invoked with the latest session object every time the session is polled while waiting for it to complete.
executeSolanaSession
The session object returned from the createSession action.
A function that signs and sends the Solana transaction using the user's wallet. Returns the transaction signature.
A callback invoked right after the user has completed their payment transaction, before waiting for the session to complete.
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.