Custodial Withdrawals
Overview
Custodial withdrawals let you send tokens to your users' wallets from a centralized balance your project holds. Withdrawals are funded from your Glide wallet, so you'll need to maintain a sufficient balance. Users can choose to receive funds in any supported currency, and Glide handles the conversion automatically.
The withdrawal process works in two steps:
- Create a payment session — Get a firm quote with exchange rates and fees
- Confirm the payment — Execute the transaction using your wallet secret
Setup
Custodial withdrawals run on your backend and require your Glide API key in addition to your project ID:
import { createGlideConfig } from "@paywithglide/glide-js";
import { base, polygon } from "@paywithglide/glide-js/chains";
export const config = createGlideConfig({
projectId: "<Your Project ID>",
chains: [base, polygon],
// Do not expose this key to the frontend
apiKey: "<Your Glide API Key>",
});Withdrawal Flow
Step 1: Create a payment session
Create a payment session to get a quote with exchange rates and fees. The paymentCurrency is the token in your Glide wallet, and the settleCurrency is the token the user will receive.
import { createPaymentSession } from "@paywithglide/glide-js";
import { base, polygon } from "@paywithglide/glide-js/chains";
import { usdc } from "@paywithglide/glide-js/currencies";
import { config } from "./config";
const session = await createPaymentSession(config, {
// The token in your Glide wallet that funds the withdrawal
paymentCurrency: usdc.on(base),
paymentAmount: "10.5",
// Your Glide wallet address
payerAccount: "0x97F02157be8e7c1Fe3058860cD1B6Ae069f1e594",
// The token and wallet the user will receive funds in
settleCurrency: usdc.on(polygon),
recipientWallet: "0x742d35Cc6634C0532925a3b844Bc454e4438f44e",
// Optional: attach your own identifier to the session
metadata: "withdrawal-12345",
});The returned session includes the exchange rate, fees, and settlement details. The session remains unpaid until confirmed. See the create payment session reference for all parameters and the full return type.
Step 2: Confirm the payment
After reviewing the session details (exchange rate, fees, etc.), confirm the payment using your wallet secret. There is no dedicated SDK action for this endpoint yet, so use the SDK's makeRequest helper — it applies the base URL and authentication headers from your config:
import { makeRequest } from "@paywithglide/glide-js";
import { config } from "./config";
const { success } = await makeRequest<{ success: boolean }>(config, {
url: "/sessions/pay-with-wallet",
body: {
sessionId: session.sessionId,
// Your Glide wallet address and secret
payerAccount: "0x97F02157be8e7c1Fe3058860cD1B6Ae069f1e594",
walletSecret: "<Your Glide wallet secret>",
},
});On failure, makeRequest throws a ResponseNotOkError with the response status:
| Status | Description |
|---|---|
| 401 | Invalid wallet secret |
| 404 | Session not found |
| 500 | Internal server error |
Step 3: Track completion
Once confirmed, use waitForSession to wait for the settlement transaction to complete:
import { waitForSession } from "@paywithglide/glide-js";
import { config } from "./config";
const completedSession = await waitForSession(config, {
sessionId: session.sessionId,
});
console.log("Withdrawal settled:", completedSession.sponsoredTransactionHash);You can also configure webhooks to track completion server-side — see the Payments guide for details.
Building the Withdrawal UI
You are responsible for building the withdrawal UI in your app — typically a simple form where the user picks the chain and currency they want to receive, and enters their destination wallet address.
To populate the chain and currency pickers, use the listSupportedChains and listSupportedCurrencies actions. Use currency.on(chain) to get the CAIP-19 ID for the settleCurrency parameter. Note that withdrawals are currently EVM only, so filter for chains whose id starts with eip155:.