Hyphen Widget
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
yarn
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 "tag" 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.
1
import * as HyphenWidget from "@biconomy/hyphen-widget";
2
import "@biconomy/hyphen-widget/dist/index.css";
3
​
4
const hyphenWidget = HyphenWidget.default.init(document.getElementById("widget"), {
5
// Unique identifier for your application - Please Put the name of your dApp/Project,
6
// this is a required field.
7
tag: string,
8
});
Copied!
1
<!DOCTYPE html>
2
<html lang="en">
3
<head>
4
<meta charset="UTF-8" />
5
<link rel="icon" type="image/svg+xml" href="favicon.svg" />
6
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
7
<title>Vite App</title>
8
</head>
9
<body>
10
<div class="widget-container">
11
<div id="widget"></div>
12
</div>
13
<script type="module" src="/main.js"></script>
14
</body>
15
</html>
Copied!

Optional Configuration

The following additional configuration options can be passed while initializing the widget:
1
{
2
env: string, // can be test, staging or production. Default: "staging"
3
showWidget: boolean, // should the widget be shown by default or not. Default: false
4
showCloseButton: boolean, // should the widget have a close button to close it. Default: false
5
showChangeAddress: boolean, // should the widget allow ability to change receiver address. Default: true
6
// API keys for using Gasless.
7
apiKeys: {
8
Ethereum: string,
9
Polygon: string,
10
Avalanche: string,
11
},
12
// Custom RPC URLs for the supported networks.
13
rpcUrls: {
14
Ethereum: string,
15
Polygon: string,
16
Avalanche: string,
17
},
18
// NOTE: following 2 callback emit when tx is *sent*, you should check the status by yourself
19
onDeposit: (e) => console.log("Deposit " + e), // emit when depost tx is sent
20
onExit: (e) => console.log("Exit " + e), // emit when exit tx (receiver will receive tokens) is sent
21
/*
22
input: {
23
sourceChain?: string;
24
destinationChain?: string;
25
token?: string;
26
amount?: string;
27
receiver?: string;
28
gasless: boolean;
29
}
30
*/
31
onChange: (input) => console.log("Input " + JSON.stringify(input)),
32
}
Copied!
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:
1
import * as HyphenWidget from "@biconomy/hyphen-widget";
2
import "@biconomy/hyphen-widget/dist/index.css";
3
​
4
const hyphenWidget = HyphenWidget.default.init(document.getElementById("widget"), {
5
tag: "my-awesome-dapp",
6
env: "test",
7
// Other options.
8
...
9
});
Copied!

Methods

open

Use the open method to open the modal:
1
import * as HyphenWidget from "@biconomy/hyphen-widget";
2
import "@biconomy/hyphen-widget/dist/index.css";
3
​
4
const hyphenWidget = HyphenWidget.default.init(
5
document.getElementById("widget"),
6
{
7
tag: "my-awesome-dapp",
8
}
9
);
10
​
11
hyphenWidget.open();
Copied!

close

Use the close method to close the modal:
1
import * as HyphenWidget from "@biconomy/hyphen-widget";
2
import "@biconomy/hyphen-widget/dist/index.css";
3
​
4
const hyphenWidget = HyphenWidget.default.init(
5
document.getElementById("widget"),
6
{
7
tag: "my-awesome-dapp",
8
}
9
);
10
​
11
hyphenWidget.close();
Copied!

Demo

You can check out the demo repository here. The hosted versions of the demo can be checked over here: mainnet and testnet.
We also have a video going through the widget's integration: