Deposits / Withdrawals
If your users hold a self-custodial balance in your app — for example, in an embedded or connected wallet — Glide lets them move funds in and out across any supported chain and token:
- Deposits — the user brings funds into your app from any wallet or exchange, in any supported token. Your app receives your canonical token on your chain.
- Withdrawals — the user sends funds from their in-app wallet to an external address, receiving any supported token on any chain.
This is the headless equivalent of the Deposit / Withdrawal widget — use it when you want full control over the UI.
Deposits
The user deposits from anywhere — their exchange account, another wallet, a friend's wallet — and your app receives the token it credits balances in.
Step 1: Create a payment session
The settleCurrency is the token your app credits balances in, and the recipientWallet is the user's in-app wallet address.
import { createPaymentSession } from "@paywithglide/glide-js";
import { base, ethereum } from "@paywithglide/glide-js/chains";
import { usdc } from "@paywithglide/glide-js/currencies";
import { config } from "./config";
const userId = "user-123";
const userInAppWalletAddress = "0x742d35Cc6634C0532925a3b844Bc454e4438f44e";
const session = await createPaymentSession(config, {
// The token the user will deposit with
paymentCurrency: usdc.on(ethereum),
// The token and chain your app credits balances in
settleCurrency: usdc.on(base),
recipientWallet: userInAppWalletAddress,
// Omit paymentAmount to let the user deposit any amount
// A consistent key returns the same deposit address for this
// user across sessions, so they can save it in their exchange
stableDepositAddressKey: `deposit-${userId}`,
});Step 2: Show the deposit address
When the session's paymentAction is transfer, show the user the depositAddress along with the payment currency and chain. The user sends funds to it from their exchange or wallet:
if (session.paymentAction === "transfer" && session.depositAddress) {
console.log("Send", session.paymentCurrencySymbol, "on", session.paymentChainName);
console.log("To:", session.depositAddress);
}With a stableDepositAddressKey, the same address is returned every time for that key — users can save it as a withdrawal address in their exchange and deposit repeatedly without creating a new session each time.
Step 3: Credit the deposit
Track the session until the funds arrive at the user's in-app wallet, then credit their balance. Use waitForSession in your app:
import { waitForSession } from "@paywithglide/glide-js";
const completedSession = await waitForSession(config, {
sessionId: session.sessionId,
});
// Funds have arrived at the user's in-app wallet
creditBalance(userId, completedSession.sponsoredTransactionAmount);Or configure webhooks to credit balances server-side — see the Payments guide for details.
Withdrawals
The user withdraws from their own wallet to an external address — for example, sending their in-app USDC balance on Base to their exchange deposit address on Arbitrum. The user signs the withdrawal transaction themselves.
Step 1: Create a payment session
The paymentCurrency is the token the user holds in your app, and the settleCurrency is what the destination address receives.
import { createPaymentSession } from "@paywithglide/glide-js";
import { arbitrum, base } from "@paywithglide/glide-js/chains";
import { usdc } from "@paywithglide/glide-js/currencies";
import { config } from "./config";
const userWalletAddress = "0x742d35Cc6634C0532925a3b844Bc454e4438f44e";
const destinationAddress = "0x82D83c72590f745fe734c64DcD8c37179C6D98C7";
const session = await createPaymentSession(config, {
// The token and chain the user holds in your app
paymentCurrency: usdc.on(base),
payerAccount: userWalletAddress,
// The token, chain, and address the user withdraws to
settleCurrency: usdc.on(arbitrum),
recipientWallet: destinationAddress,
// The amount to withdraw. Use settleAmount instead if the
// destination should receive an exact amount.
paymentAmount: "50",
});The session includes the exchange rate and fees, so you can show the user exactly what the destination will receive (session.sponsoredTransactionAmount) before they sign.
Step 2: Execute from the user's wallet
Use executeEVMSession to complete the withdrawal with the user's wallet. It switches to the right chain, prompts the user to sign, and waits for the funds to arrive at the destination:
import { executeEVMSession } from "@paywithglide/glide-js";
const { sponsoredTransactionHash } = await executeEVMSession(config, {
session,
currentChainId,
switchChainAsync,
sendTransactionAsync,
signTypedDataAsync, // optional, enables gasless withdrawals
});
console.log("Withdrawal settled:", sponsoredTransactionHash);That's it — once executeEVMSession resolves, the funds have arrived at the destination address.