Skip to content

Create session

Create a new Glide session to make a cross-chain, cross-token, or gasless payment

A Glide session should be created once a user has shown intent to pay for a transaction using Glide.

A session is valid for 10 minutes, during which the user should complete the payment process. If the user does not complete the payment within this time, the session will expire and the user will need to create a new session. If a payment is made for an expired session, the payment will be refunded automatically.

Once a session is created, use the executeSession action to complete the payment process.

Import

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

Usage

index.ts
import { createSession, currencies, chains } from "@paywithglide/glide-js";
import { config } from "./config";
 
const session = await createSession(config, {
  chainId: chains.base.id,
  account: "0xc6FfEB1298Eb33Da430d14e5Eb789256ec344625",
 
  paymentCurrency: currencies.usdc,
  preferGaslessPayment: true,
 
  abi: fabricAbi,
  address: "0x1169c6769c4F4B3cA1944AF0F26B36582fd5279d",
  functionName: "mintFor",
  args: ["0xc6FfEB1298Eb33Da430d14e5Eb789256ec344625", 999999907200n],
  value: 999999907200n,
});

Parameters

chainId*
number

The EIP-155 chain ID of the chain where the transaction will be executed.

account*
string

The wallet address that will be used to pay for the transaction.

paymentCurrency
nullable CAIP19 | Currency

The currency in which the user pays in CAIP-19 format. Defaults to the first currency returned by listPaymentOptions.

preferGaslessPayment
nullable boolean

When set to true and if supported by the payment currency, the user will be able to pay with a signature only, requiring no gas. Defaults to false.

abi*
object[]

The contract's ABI.

address*
string

The contract's address.

functionName*
string

The name of the function to be called on the contract.

args
nullable unknown[]

Arguments to be passed when calling the function.

value
nullable bigint

Value in the smallest unit (ex. wei) to be sent with the transaction.

commissionUSD
nullable number

The commission amount in USD that will be added on top of the transaction cost and will be paid out to the developer.

walletSecret
nullable string

The wallet secret that was used when creating the wallet. Required if the account wallet was created on Glide.

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.