API Reference

This page describes XPay methods and types

Methods

openTransactionModal

const openTransactionModal = async (payload: GetSwapTxPayload): Promise<Transactions | undefined>

Description: This method opens an XPay modal for selecting tokens and communicating with the XSwap backend to get the routes and required transactions calldata to make the cross-chain transaction possible. The modal implements transaction execution by default.

Parameters:

  • integratorId (string): The ID of the integrator using the SDK. Apply Here

  • dstChain (string): The destination chain ID.

  • dstToken (string): The destination token address to which the user funds will be swapped.

  • customContractCalls (ContractCall[], optional): An array of custom contract calls to be executed during the transaction on the destination chain after the swap.

  • desc (string, optional): A description of the transaction displayed for the user.

  • returnTransactions (boolean, optional): Option which allows to receive transactions calldata for execution.

Example:

const transactions = await openXPayModal({
      integratorId: "XXXXXXX",
      dstChain: "8453", // Base
      dstToken: "0x8fe815417913a93ea99049fc0718ee1647a2a07c", // XSWAP Token
});

The modal will execute the approval if needed for the user's tokens and send the cross-chain swap transaction. For a more detailed example please check the example project on Github

renderTxStatus

export const renderTxStatus = async (
  txChainId: string,
  txHash: string
): Promise<void>

Description: This method displays the transaction progress bar in the corner of the screen. It checks the transaction status and displays the appropriate information. After completion, the status bar changes to green and disappears after a few seconds.

Parameters:

  • txChainId (string): The source chain ID where the origin transaction is taking place.

  • txHash (string): The hash of the origin swap transaction signed by the user.

Example:

openTransactionStatusCheck(
    "10",
    "0x1ac2e55f6d618b1e3bdb7531cd724f4f62a92d6d0797b5b78b5e517fc0c448f5"
);

Types

GetSwapTxPayload

type GetSwapTxPayload = {
  integratorId: string;
  dstChain: string;
  dstToken: string;
  customContractCalls?: ContractCall[];
  desc?: string;
  returnTransactions?: boolean;
};

Properties:

  • integratorId (string): The ID of the integrator using the SDK. Apply Here

  • dstChain (string): The destination chain ID.

  • dstToken (string): The destination token address to which the user funds will be swapped.

  • customContractCalls (ContractCall[], optional): An array of custom contract calls to be executed during the transaction on the destination chain after the swap.

  • desc (string, optional): A description of the transaction displayed for the user.

  • returnTransactions (boolean, optional): Option which allows to receive transactions calldata for execution.

Transactions

The transactions contain data that should be executed using the integrator web3 provider. Check the TransactionRequest for more details.

type Transactions = {
  approve?: TransactionRequest;
  swap: TransactionRequest;
};

Properties:

  • approve (TransactionRequest, optional): The approval transaction calldata.

  • swap (TransactionRequest): The cross-chain swap transaction calldata.

TransactionRequest

type TransactionRequest = {
  to: string;
  data: string;
  value: string;
};

Properties:

  • to (string): The address to send the transaction to.

  • data (string): The transaction calldata.

  • value (string): The amount of native tokens for the transaction.

Last updated