Skip to content

Estimate payment amount

Estimate the amount that should be paid for a transaction without creating a session. Since this is only an estimate, the actual amount may vary when a session is created. If you need a firm quote, you should create a session.

Import

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

Usage

index.ts
import { estimatePaymentAmount, currencies, chains } from "@paywithglide/glide-js";
import { config } from "./config";
 
const estimate = await estimatePaymentAmount(config, {
  chainId: chains.base.id,
  account: "0xc6FfEB1298Eb33Da430d14e5Eb789256ec344625",
  paymentCurrency: currencies.usdc,
  abi: fabricAbi,
  address: "0x1169c6769c4F4B3cA1944AF0F26B36582fd5279d",
  functionName: "mintFor",
  args: ["0xc6FfEB1298Eb33Da430d14e5Eb789256ec344625", 999999907200n],
  value: 999999907200n,
});

Parameters

chainId*
number

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

account*
string

The wallet address that will be used to pay for the transaction.

paymentCurrency*
CAIP19 | Currency

The currency in which the user pays in CAIP-19 format.

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.

Return Type

paymentAmount*
string

The estimated payment amount required for the transaction in the payment currency.

paymentCurrency*
CAIP19 | Currency

The currency in which the user pays in CAIP-19 format.

currencyName*
string

The name of the payment currency.

currencySymbol*
string

The symbol of the payment currency.

currencyLogoURL*
string

The URL of the payment currency's logo.

balance*
string

The user's current balance of the payment currency.

balanceUSD*
string

The user's current balance of the payment currency in USD.