Biconomy Gasless SDK (EOA)
DashboardMediumWebsite
  • 🚀Getting Started
  • Introduction
    • 🤘Why Biconomy?
    • 🙂How we simplify transactions
  • Products
    • 💸Gasless Transactions
      • Choose An Approach to Enable Gasless
        • Standard EIP 2771 Approach
          • 1. Register Artifacts on the Dashboard
          • 2. Code Changes
            • Using SDK
            • Using API
        • Custom Implementation Approach
          • 1. Register Artifacts on the Dashboard
          • 2. Code Changes
            • Using SDK
            • Using API
        • Smart Contract Wallet Approach
          • Gnosis
        • Network Agnostic Transactions
          • EIP-2771 Approach
          • Custom Approach
      • Conditional Whitelisting
      • Gasless SDK (EOA) 3
      • Networks Supported
    • ↔️Hyphen - Instant Cross-Chain Transfers
      • SDK
        • DepositManager
        • TransferManager
        • TokenManager
      • APIs
      • Helper Methods
      • Migrating from Hyphen V1
      • Contract Addresses
      • Hyphen Widget
  • Guides
    • 💻Dashboard
      • DApp Statistics
    • ⛽Gas Tank Deposits
      • Via Dashboard
      • Via Smart Contract
  • api
    • 🔧Native Meta Transaction
      • Get Retried Hashes
    • 🌎Dashboard APIs
    • ⚪Whitelist API
      • Whitelist Destination Address
      • Whitelist Proxy Contracts
    • 〰️ Check Limits
    • 💿Biconomy Data API
      • 👨‍🚀Unique User Data
      • 🧑‍🔧Per User Limits Data
      • ⛽Gas Tank Balance Data
  • SDK
    • 📙Gasless SDK (EOA)
      • Configuration
  • Tutorials
    • 🔰Native Meta Transactions
      • How To Build Your First DApp
        • Write Your First Smart Contract
        • Initialize Web3 on Client Side
        • Executing First Blockchain Transaction
      • Enable Native Meta Transactions
        • Smart Contract
          • Describe Your Structs
          • Declare Your Variables
          • Modify Respective Function
        • Client Side
          • Design Your JSON structure
          • Design Your Domain Separator
          • Design Data Types
          • Define Data To Sign
          • Generate Signatures
      • Integrate Biconomy
        • Register On Dashboard
        • Integrate Gasless SDK (EOA)
      • Summary
  • BICO Staking
    • 🪁Safety Module
  • Get in touch
    • 👥Contact Us
  • Misc
    • 🧩Projects on Biconomy
    • 🌐Supported Networks
    • 📫Contract Addresses
    • ✔︎ Smart Contracts Audit
    • ❓FAQs
Powered by GitBook
On this page
  • Installation
  • Importing & Instantiation
  • Optional Configuration
  • Methods
  • Demo

Was this helpful?

  1. Products
  2. Hyphen - Instant Cross-Chain Transfers

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 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";

const hyphenWidget = 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,
});
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <link rel="icon" type="image/svg+xml" href="favicon.svg" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Vite App</title>
  </head>
  <body>
    <div class="widget-container">
      <div id="widget"></div>
    </div>
    <script type="module" src="/main.js"></script>
  </body>
</html>

Using the Widget in React

import { useState, useEffect } from "react";
import * as HyphenWidget from "@biconomy/hyphen-widget";
import "@biconomy/hyphen-widget/dist/index.css";

function App() {
  const [hyphenWidget, setHyphenWidget] = useState();

  useEffect(() => {
    const widget = HyphenWidget.default.init(
      document.getElementById("widget"),
      {
        dAppName: "expecto-patronum",
        showWidget: true,
        showCloseButton: true,
      }
    );

    if (widget) {
      setHyphenWidget(widget);
    }
  }, []);

  function handleOpen() {
    hyphenWidget.open();
  }

  function handleClose() {
    hyphenWidget.close();
  }

  return <div className="App">
    <button onClick={handleOpen}>Open Widget</button>
    <button onClick={handleClose}>Close Widget</button>

    <div id="widget"></div>
  </div>;
}

export default App;

Optional Configuration

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)),
}

For testnets the initialization would look something like this:

import * as HyphenWidget from "@biconomy/hyphen-widget";
import "@biconomy/hyphen-widget/dist/index.css";

const hyphenWidget = HyphenWidget.default.init(document.getElementById("widget"), {
  dAppName: "my-awesome-dapp",
  env: "test",
  // Other options.
  ...
});

Methods

open

Use the open method to open the modal:

import * as HyphenWidget from "@biconomy/hyphen-widget";
import "@biconomy/hyphen-widget/dist/index.css";

const hyphenWidget = HyphenWidget.default.init(
  document.getElementById("widget"),
  {
    dAppName: "my-awesome-dapp",
  }
);

hyphenWidget.open();

close

Use the close method to close the modal:

import * as HyphenWidget from "@biconomy/hyphen-widget";
import "@biconomy/hyphen-widget/dist/index.css";

const hyphenWidget = HyphenWidget.default.init(
  document.getElementById("widget"),
  {
    dAppName: "my-awesome-dapp",
  }
);

hyphenWidget.close();

Demo

We also have a video going through the widget's integration:

PreviousContract AddressesNextDashboard

Last updated 2 years ago

Was this helpful?

Note: For using Gasless obtain Biconomy api keys from and pass those during initialization using apiKeys object. Similarly for passing custom RPC URLs obtain RPC endpoints from providers like or and pass them using rpcUrls object.

You can check out the demo repository . The hosted versions of the demo can be checked over here: and .

↔️
Biconomy
Infura
Alchemy
here
mainnet
testnet