Create session
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
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
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.
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.
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.
The amount the user wants to pay, denominated in the paymentCurrency, can be set for transactions that support variable payment amounts (ex. p2p transfers).
The amount the user wants to pay, denominated in USD. Alternative to paymentAmount.
How the user pays for the session: wallet, transfer, coinbase_onramp, coinbase_app, moonpay, onramp, or onramper. Defaults to wallet.
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.
The EVM transaction to be executed on the destination chain. Exactly one of evm, solana, or transfer must be provided.
The contract's address, or the recipient's address if the transaction is not a contract call.
Value in the smallest unit (ex. wei) to be sent with the transaction.
The encoded calldata for the transaction. Use viem's encodeFunctionData to encode a contract call.
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).
The Solana transaction to be executed on the destination chain. Exactly one of evm, solana, or transfer must be provided.
The base64-encoded Solana transaction message to be executed.
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.
The token to send to the recipient on the destination chain.
The address that will receive the tokens.
The amount to transfer, in a human-readable format.
The commission amount in USD that will be added on top of the transaction cost and will be paid out to the developer.
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.
The wallet secret that was used when creating the wallet. Required if the account wallet was created on Glide.
Custom string metadata to attach to the session (e.g., order ID, user ID, JSON-encoded objects).
The amount of native gas currency to send to the user on the destination chain along with the transaction, in a human-readable format.
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.
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.
The wallet address that owns the deposit. Used with transfer payments to attribute the deposit address to a specific user.
When set to true, the payer will receive an email if their payment is refunded.
The email address of the payer, used for refund notifications.
Configuration for Glide-hosted payment pages. Contains an optional appMetadata object (id, name, logoUrl, faviconUrl) and an optional theme object with custom theme values.
The priority to use when selecting a route for the payment: optimize for the fastest route or the cheapest route.