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 executeEVMSession action to complete the payment process.

Import

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

Usage

index.ts
import { createSession } from "@paywithglide/glide-js";
import { base } from "@paywithglide/glide-js/chains";
import { usdc } from "@paywithglide/glide-js/currencies";
import { config } from "./config";
import { encodeFunctionData } from "viem";
 
const fabricAbi = [/* your contract's ABI */];
 
const session = await createSession(config, {
  chainId: base.id,
  account: "0xc6FfEB1298Eb33Da430d14e5Eb789256ec344625",
 
  paymentCurrency: usdc,
 
  evm: {
    address: "0x1169c6769c4F4B3cA1944AF0F26B36582fd5279d",
    value: 999999907200n,
    data: encodeFunctionData({
      abi: fabricAbi,
      functionName: "mintFor",
      args: ["0xc6FfEB1298Eb33Da430d14e5Eb789256ec344625", 999999907200n],
    }),
  },
});

Parameters

chainId*
CAIP2

The CAIP-2 chain ID of the chain where the transaction will be executed (e.g., eip155:8453 for Base). Use the id field of a chain imported from @paywithglide/glide-js/chains.

account
nullable string

The wallet address that will be used to pay for the transaction. Required when paymentCurrency is not set, so the best payment option can be selected based on the user's balances.

paymentCurrency
nullable CAIP19 | Currency

The currency in which the user pays, either in the CAIP-19 format or as a currency object imported from @paywithglide/glide-js/currencies. Defaults to the first currency returned by listPaymentOptions for the user's account.

paymentAmount
nullable string

The amount the user wants to pay, denominated in the paymentCurrency, can be set for transactions that support variable payment amounts (ex. p2p transfers).

paymentAmountUSD
nullable string

The amount the user wants to pay, denominated in USD. Alternative to paymentAmount.

paymentMethod
nullable PaymentMethod

How the user pays for the session: wallet, transfer, coinbase_onramp, coinbase_app, moonpay, onramp, or onramper. Defaults to wallet.

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.

evm
nullable object

The EVM transaction to be executed on the destination chain. Exactly one of evm, solana, or transfer must be provided.

address*
Hex

The contract's address, or the recipient's address if the transaction is not a contract call.

value
nullable bigint

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

data
nullable Hex

The encoded calldata for the transaction. Use viem's encodeFunctionData to encode a contract call.

approval
nullable object

The approval object, required if the transaction requires spending of an ERC-20 token. Contains token (the token's contract address as Hex) and amount (the amount to approve, as bigint in the token's smallest unit).

solana
nullable object

The Solana transaction to be executed on the destination chain. Exactly one of evm, solana, or transfer must be provided.

message*
string

The base64-encoded Solana transaction message to be executed.

transfer
nullable object

A simple token transfer to be executed on the destination chain, instead of a contract call. Exactly one of evm, solana, or transfer must be provided.

token*
string

The token to send to the recipient on the destination chain.

recipient*
string

The address that will receive the tokens.

amount*
string

The amount to transfer, in a human-readable format.

commissionUSD
nullable string

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

commissionRates
nullable CommissionRates

Commission rates per currency tier (tier1, tier2, tier3) that will be added on top of the transaction cost and paid out to the developer, as a percentage of the transaction amount (e.g., "0.5" = 0.5%). Cannot be used with commissionUSD.

walletSecret
nullable string

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

metadata
nullable string

Custom string metadata to attach to the session (e.g., order ID, user ID, JSON-encoded objects).

gasRefuelAmount
nullable string

The amount of native gas currency to send to the user on the destination chain along with the transaction, in a human-readable format.

allowArbitraryDeposit
nullable boolean

When set to true and the payment method is transfer, any amount deposited to the deposit address is accepted, instead of requiring the exact payment amount.

stableDepositAddressKey
nullable string

An identifier for generating a stable deposit address. When the payment method is transfer, providing a consistent key ensures the same deposit address is returned for repeat sessions.

depositOwnerAddress
nullable string

The wallet address that owns the deposit. Used with transfer payments to attribute the deposit address to a specific user.

enableRefundEmails
nullable boolean

When set to true, the payer will receive an email if their payment is refunded.

payerEmail
nullable string

The email address of the payer, used for refund notifications.

widgetConfig
nullable object

Configuration for Glide-hosted payment pages. Contains an optional appMetadata object (id, name, logoUrl, faviconUrl) and an optional theme object with custom theme values.

routePriority
nullable 'speed' | 'cost'

The priority to use when selecting a route for the payment: optimize for the fastest route or the cheapest route.

Return Type

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.