Skip to content

Pay with Glide

Add Glide to your dapp or wallet in just a few mins

The payWithGlide action is the fastest way to integrate Glide into your dapp. It orchestrates the entire process required to make a cross-chain, cross-token, and gasless payment using Glide.

Import

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

Usage

index.ts
import { payWithGlide, chains } from "@paywithglide/glide-js";
import { config } from "./config";
 
const transactionHash = await payWithGlide(config, {
  chainId: chains.base.id,
  account: "0xc6FfEB1298Eb33Da430d14e5Eb789256ec344625",
 
  abi: fabricABI,
  address: "0x1169c6769c4F4B3cA1944AF0F26B36582fd5279d",
  functionName: "mintFor",
  args: ["0xc6FfEB1298Eb33Da430d14e5Eb789256ec344625", 999999907200n],
  value: 999999907200n,
 
  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
  },
  signTypedDataAsync: async (data) => {
    // sign typed data using the user's wallet
    // return the signature
  },
});

Parameters

chainId*
number

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

currentChainId
nullable number

The EIP-155 chain id of the chain that the user's wallet is currently connected to. Defaults to chainId.

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 option returned from listPaymentOptions.

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.

switchChainAsync*
({chainId: number}) => Promise<unknown>

A function that switches the user's wallet to the specified chain.

sendTransactionAsync*
({chainId: number, to: string, data?: string, value?: bigint}) => Promise<string>

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

signTypedDataAsync
nullable (EIP712TypedData) => Promise<string>

A function that signs typed data using the user's wallet. Returns the signature. Used to enable gasless transactions.

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.
expired*
boolean
A boolean indicating whether the session has expired.
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 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.
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.
paymentAction*
'signAndSendTransaction' | 'signTypedData'
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`.
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`.
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.
sponsoredTransactionHash
nullable Hex | null
The hash of the transaction that Glide sent to the chain on behalf of the user.
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.
totalFeeUSD*
string
The total fee covers the relayer fee and the destination transaction gas cost paid by the relayer.

Behavior

The payWithGlide function orchestrates the entire process required to make a payment using Glide. Here's what it does:

  1. If no payment currency is provided, list the payment options and pick the best one.
  2. Create a new Glide session for the given transaction and the chosen payment currency.
  3. Switch the user's wallet to the required chain.
  4. Send the payment transaction to the chain using the user's wallet and update the payment transaction hash for the Glide session.
  5. If gasless payment is available, instead of step 4, sign the required typed data using the user's wallet and make the payment with the signature.
  6. Wait for the session to be completed.
  7. Return the sponsoredTransactionHash from the completed session object.

If you need more control over the process, you can use the advanced functions mentioned in each step.