Insert our Plug & Play Widget to get instant cross chain transfers in-dApp
Getting started with the Hyphen widget is quite easy, no need to worry about building your own UI. Having seamless bridging inside your dApp has never been easier!
Installation
npm install @biconomy/hyphen-widget
yarn add @biconomy/hyphen-widget
Importing & Instantiation
To use the widget import the HyphenWidget component and initialize it in your JavaScript file by passing a "dAppName" value in its configuration. This is the only mandatory parameter, other parameters are optional.
Add an element in your HTML with an appropriate ID which will render the widget.
import*as HyphenWidget from"@biconomy/hyphen-widget";import"@biconomy/hyphen-widget/dist/index.css";consthyphenWidget=HyphenWidget.default.init(document.getElementById("widget"), {// Unique identifier for your application - Please Put the name of your dApp/Project,// this is a required field. dAppName: string,});
The following additional configuration options can be passed while initializing the widget:
{// can be test, staging or production. Default: "staging" env: string,// should the widget be shown by default or not. Default: false showWidget: boolean,// should the widget have a close button to close it. Default: false showCloseButton: boolean,// should the widget allow ability to change receiver address. Default: true showChangeAddress: boolean,// allows ability to swap for gas tokens while making a transfer. showGasTokenSwap: boolean,// array of chain ids to specify the possible source chains. Chains not in this list will be excluded. allowedSourceChains: number[],// array of chain ids to specify the possible destination chains. Chains not in this list will be excluded. allowedDestinationChains: number[],// array of token symbols to specify the possible tokens. Tokens not in this list will be excluded. allowedTokens: string[],// chain id to specify the default source chain which should be selected. defaultSourceChain: number,// chain id to specify the default destination chain which should be selected. defaultDestinationChain: number,// token symbol to specify the default token which should be selected. defaultToken: string,// API keys for using Gasless. apiKeys: { Ethereum: string, Polygon: string, Avalanche: string, },// Custom RPC URLs for the supported networks. rpcUrls: { Ethereum: string, Polygon: string, Avalanche: string, },// NOTE: following 2 callback emit when tx is *sent*, you should check the status by yourself onDeposit: (e) =>console.log("Deposit "+ e),// emit when depost tx is sent onExit: (e) =>console.log("Exit "+ e),// emit when exit tx (receiver will receive tokens) is sent/* input: { sourceChain?: string; destinationChain?: string; token?: string; amount?: string; receiver?: string; gasless: boolean; } */ onChange: (input) =>console.log("Input "+JSON.stringify(input)),}
Note: For using Gasless obtain Biconomy api keys from Biconomy and pass those during initialization using apiKeys object. Similarly for passing custom RPC URLs obtain RPC endpoints from providers like Infura or Alchemy and pass them using rpcUrls object.
For testnets the initialization would look something like this:
import*as HyphenWidget from"@biconomy/hyphen-widget";import"@biconomy/hyphen-widget/dist/index.css";consthyphenWidget=HyphenWidget.default.init(document.getElementById("widget"), { dAppName:"my-awesome-dapp", env:"test",// Other options....});