AnyAlt
  • Introduction
  • Widget
    • Overview
    • Getting Started
    • API Reference
  • Customize Theme
  • SDK
    • Overview
    • Getting Started
    • API reference
  • Iframe
    • Integration
Powered by GitBook
On this page
  • AnyaltWidget Props
  • Token Object Structure
  • ChainType
  • widgetTemplate
  • Callbacks
  • Modal Control: useModal Hook
Export as PDF
  1. Widget

API Reference

The AnyaltWidget component exposes a variety of props and callbacks that allow you to configure its behavior and integrate it smoothly into your project. Below is an overview of its API:

AnyaltWidget Props

Prop Name
Type
Description

swapResultToken

Object

An object defining the token that the user will use in the last mile transaction. This token will always be the output of the initial swap. Contains properties such as symbol, address, chainId, name, and chainType.

finalToken?

Object

An object defining the token that the user will receive or use in the last mile transaction. Includes properties like symbol, address, chainId, name, chainType, and optionally logoUrl for branding.

apiKey

String

Your project’s API key for authenticating requests to the AnyAlt backend.

widgetTemplate?

WidgetTemplateType

Defines the available modes for the widget, determining its functionality based on the selected option. Default DEPOSIT_TOKEN - Enables the widget for depositing tokens, allowing users to transfer tokens into a designated account or wallet. TOKEN_BUY - Activates the widget for purchasing tokens, adjusting the UI and logic to facilitate token acquisition.

isOpen

Boolean

A flag indicating whether the widget modal is currently open.

onClose

Function

A callback function invoked to close the widget modal.

estimateCallback

Function

An asynchronous function that is called to provide an estimation before executing the last-mile transaction. It receives the token details and should return an object with properties like amountOut and priceInUSD.

executeCallBack

Function

An asynchronous function that executes the final transaction. It receives the token details and should return transaction details such as approvalTxHash, executeTxHash, and amountOut.

minDepositAmount?

Number

Specifies the minimum deposit amount required to proceed with the transaction.

Token Object Structure

Both inputToken and finalToken follow the same structure

interface Token {
  symbol: String,       // e.g., "USDT"
  address: String,      // Blockchain address of the token
  chainId: Number,      // Identifier for the blockchain network
  name: String,         // Human-readable name of the token
  chainType: ChainType, // Type of blockchain, e.g., ChainType.EVM
  logoUrl?: String,     // (Optional) URL for the token’s logo
  amount?: string,      // (Optional) 
  decimals?: string,    // (Optional)
}

ChainType

The ChainType enum helps define the type of blockchain the token belongs to. For example:

  • ChainType.EVM for Ethereum Virtual Machine (EVM)-compatible chains.

  • ChainType.SOLANA for the Solana chain.

widgetTemplate

The widgetTemplate parameter defines the mode of the widget:

  • TOKEN_BUY: Configures the widget for token purchases. In this mode:

    • swapResultToken represents the token the user wants to buy.

    • It is highly recommended to provide the logoUrl of the token for better user experience.

    • The finalToken parameter is optional.

  • DEPOSIT_TOKEN: Enables the widget for token swapping followed by a deposit. In this mode:

    • Both swapResultToken and finalToken are required.

Callbacks

estimateCallback(inputToken)

  • Purpose: A function which will estimate the output amount and dollar value price of the last mile transaction.

  • Parameters:

    • swapResultToken(Token): the token which the user will receive as a result of the swap, same as swapResultTokenwhich was passed as a prop to <AnyaltWidget />

  • Returns: A promise that resolves to an object with:

    • amountOut (String): Estimated output amount.

    • priceInUSD (String): Estimated price in USD.

executeCallBack(token)

  • Purpose: A function which will create and present the last mile transaction for the user to sign, as well as the approval transaction if necessary

  • Parameters:

    • swapResultToken(Token): the token which the user will receive as a result of the swap, same as swapResultToken which was passed as a prop to <AnyaltWidget/>

  • Returns: A promise that resolves to an object with:

    • approvalTxHash (String): Transaction hash for the approval step (if applicable).

    • executeTxHash (String): Transaction hash for the execution step.

    • amountOut (String): Final output amount from the transaction.

Modal Control: useModal Hook

The widget package also provides a useModal hook to help manage the modal state:

const { isOpen, onOpen, onClose } = useModal();
  • isOpen: A boolean flag indicating whether the modal is currently open.

  • onOpen: Function to open the modal.

  • onClose: Function to close the modal.


This API reference should serve as a comprehensive guide to integrating and customizing the AnyAlt Widget within your project, enabling you to leverage its full capabilities for cross-chain token swaps and last-mile transactions.

PreviousGetting StartedNextCustomize Theme

Last updated 1 month ago