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.
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.

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.