Guide

Comprehensive Guide: Requesting a Quote

This guide will walk you through the process of requesting a quote using the bindpay API. This is typically the first step in processing a payment transaction.

What is a Quote Request?

A quote request allows you to get pricing information for a potential transaction before actually executing it. This is useful for:

  1. Showing the user how much they'll pay before they commit

  2. Understanding the current exchange rates and fees

  3. Preparing the necessary transaction details

Prerequisites

Before you start, make sure you have:

  1. A bindpay API key

  2. The details of the transaction you want to quote

If you don't have an API key yet, you can register for one here.

Step-by-Step Guide

1. Prepare Your Request

You'll need to gather the following information:

  • fromChain: The ID of the blockchain network the payment is coming from.

    • Refer to our Active Chains list to find the correct chainID.

    • Example: "1" for Ethereum Mainnet, "8453" for Base

  • fromToken: The address of the token being used for payment.

    • This is a unique address for each token on each network.

    • Example: For ETH on Ethereum, you can use "ETH" or the zero address "0x0000000000000000000000000000000000000000"

  • fromAddress: The wallet address of the person making the payment.

    • This should be a valid address on the specified chain.

    • Example: "0x742d35Cc6634C0532925a3b844Bc454e4438f44e"

  • usdAmount: The amount of the transaction in US Dollars.

    • This should be a string representing the dollar amount.

    • Example: "100" for a $100 transaction

2. Make the API Call

Now that you have all the necessary information, you can make the API call. Here's how to do it using cURL:

curl -X POST "https://api.bindpay.xyz/v1/quote" \
     -H "Content-Type: application/json" \
     -H "x-api-key: your_api_key_here" \
     -d '{
       "fromChain": "1",
       "fromToken": "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",
       "fromAddress": "0x742d35Cc6634C0532925a3b844Bc454e4438f44e",
       "usdAmount": 100
     }'

Replace your_api_key_here with your actual API key.

3. Understand the Response

The API will respond with a JSON object containing the quote details. Here's an example of what you might receive:

{
  "quoteId": "8c2b371c-4cd8-489a-804c-7864e58ab4d2:0",
  "type": "lifi",
  "tool": "across",
  "toolDetails": {
    "key": "across",
    "name": "Across",
    "logoURI": "https://raw.githubusercontent.com/lifinance/types/main/src/assets/icons/bridges/acrossv2.png"
  },
  "fromToken": {
    "address": "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",
    "chainId": 1,
    "symbol": "USDC",
    "decimals": 6,
    "name": "USD Coin",
    "priceUSD": "1.000100010001",
    "logoURI": "https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/ethereum/assets/0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48/logo.png"
  },
  "toToken": {
    "address": "0x0000000000000000000000000000000000000000",
    "chainId": 10,
    "symbol": "ETH",
    "decimals": 18,
    "name": "ETH",
    "priceUSD": "2647.99",
    "logoURI": "https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/ethereum/assets/0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2/logo.png"
  },
  "fromAmount": "999900",
  "toAmount": "378532614093794",
  "exchangeRate": 0.0003785326,
  "fromChainId": 1,
  "toChainId": 10,
  "slippage": 0.005,
  "fromAddress": "0x07422Fe02DC95327fd0093644E90c46F2e2fBC53",
  "toAddress": "0x07422Fe02DC95327fd0093644E90c46F2e2fBC53",
  "feeCosts": [
    {
      "name": "LIFI Fixed Fee",
      "amount": "2499",
      "amountUSD": "0.01",
      "percentage": "0.0025",
      "token": {
        "address": "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",
        "symbol": "USDC",
        "priceUSD": "1.000100010001"
      }
    },
    {
      "name": "Relayer Fee",
      "amount": "1509035611923",
      "amountUSD": "0.01",
      "percentage": "0.0040",
      "token": {
        "address": "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2",
        "symbol": "WETH",
        "priceUSD": "2647.99"
      }
    }
  ],
  "gasCosts": [
    {
      "type": "SEND",
      "price": "15604379721",
      "limit": "465735",
      "amount": "5590393870086018",
      "amountUSD": "14.8033",
      "token": {
        "symbol": "ETH",
        "priceUSD": "2647.99"
      }
    }
  ],
  "executionDuration": 45,
  "toolDetails": {
    "name": "Across",
    "logoURI": "https://raw.githubusercontent.com/lifinance/types/main/src/assets/icons/bridges/acrossv2.png"
  },
  "approvalAddress": "0x1231DEB6f5749EF6cE6943a275A1D3E7486F4EaE",
  "integrator": "bindpay",
  "transactionRequest": {
    "to": "0x1231DEB6f5749EF6cE6943a275A1D3E7486F4EaE",
    "from": "0x07422Fe02DC95327fd0093644E90c46F2e2fBC53",
    "data": "0x3a3f7332....",
    "value": "0x0",
    "chainId": 1,
    "gasPrice": "0x3a217f049",
    "gasLimit": "0x71b47"
  },
  "approvalTxParams": {
    "from": "0x07422Fe02DC95327fd0093644E90c46F2e2fBC53",
    "to": "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",
    "gas": "0xda81",
    "gasPrice": "0x451ac210f",
    "data": "0x095ea7b3....",
    "value": "0x0",
    "nonce": "0x8"
  }
}
  • quoteId: A unique identifier for this quote. You'll need this if you decide to execute the transaction.

  • exchangeRate: The current exchange rate between the from token and USD.

  • fromAmount: The amount of the from token that will be sent.

  • toAmount: The amount in USD that will be received.

  • fee: These fees are varible based on your sub-payee takerate

  • estimatedGas: An estimate of the gas required for the transaction.

  • validUntil: The time until which this quote is valid.

  • Approval Transaction Parameters (approvalTxParams):

    • from: The address of the user initiating the transaction.

    • to: The address of the contract that needs approval (USDC token contract in this case).

    • gas: Estimated gas limit for the approval transaction.

    • gasPrice: Gas price for the transaction.

    • data: The encoded data for the approval transaction (standard ERC-20 approval format).

    • value: The value in wei being sent with the transaction (usually 0 for approval transactions).

    • nonce: The transaction count from the from address (to prevent double-spends).

  • Transaction Request (transactionRequest):

    • to: The address that the transaction is being sent to (could be a smart contract or user address).

    • from: The user's address initiating the transaction.

    • data: Encoded call data for the transaction (typically contains function selectors and parameters for smart contract calls).

    • value: The amount of ETH (in wei) sent with the transaction.

    • chainId: The chain ID of the network.

    • gasPrice: The gas price for the transaction.

    • gasLimit: The maximum gas allowed for this transaction.

4. Next Steps

Once you have the quote:

  1. Display the relevant information to your user.

  2. If the user agrees to the quote, you can proceed to execute the transaction using the approval and transaction data.

  3. If the user wants to change something, you can request a new quote with updated parameters.

Common Issues and Troubleshooting

  • Invalid API Key: Make sure your API key is correct and active.

  • Unsupported Chain or Token: Check our documentation for supported chains and tokens.

  • Insufficient Balance: Ensure the fromAddress has enough balance for the transaction.

  • Rate Limiting: If you're making too many requests, you might hit our rate limits. Space out your requests if this happens.

Best Practices

  1. Always validate user input before sending it to the API.

  2. Handle API errors gracefully and provide meaningful feedback to your users.

  3. Consider implementing retry logic with exponential backoff for failed requests.

  4. Keep your API key secure and never expose it in client-side code.

By following this guide, you should be able to successfully request quotes for transactions using the bindpay API. If you encounter any issues or have questions, don't hesitate to reach out to our support team.

Last updated