Pay with Glide
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
Parameters
The EIP-155 chain ID of the chain where the transaction will be executed.
The EIP-155 chain id of the chain that the user's wallet is currently connected to. Defaults to chainId
.
The wallet address that will be used to pay for the transaction.
The currency in which the user pays in CAIP-19 format. Defaults to the first option returned from listPaymentOptions
.
The contract's ABI.
The contract's address.
The name of the function to be called on the contract.
Arguments to be passed when calling the function.
Value in the smallest unit (ex. wei) to be sent with the transaction.
The commission amount in USD that will be added on top of the transaction cost and will be paid out to the developer.
A function that switches the user's wallet to the specified chain.
A function that sends a transaction to the specified chain using the user's wallet. Returns the transaction hash.
A function that signs typed data using the user's wallet. Returns the signature. Used to enable gasless transactions.
Return Type
Behavior
The payWithGlide
function orchestrates the entire process required to make a payment using Glide. Here's what it does:
- If no payment currency is provided, list the payment options and pick the best one.
- Create a new Glide session for the given transaction and the chosen payment currency.
- Switch the user's wallet to the required chain.
- Send the payment transaction to the chain using the user's wallet and update the payment transaction hash for the Glide session.
- 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.
- Wait for the session to be completed.
- 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.