npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@biconomy/hyphen-widget

v1.0.6

Published

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!

Downloads

26

Readme

Hyphen Widget

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

or

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.
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 (should ideally contain your dApp name),
    // this is a required field.
    tag: 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"),
      {
        tag: "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, these are optional and can be skipped:

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

const hyphenWidget = HyphenWidget.default.init(document.getElementById("widget"), {
  tag: "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"),
  {
    tag: "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"),
  {
    tag: "my-awesome-dapp",
  }
);

hyphenWidget.close();

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:

https://www.youtube.com/watch?v=1ErNhH6TKj0