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

cardano-connect

v2.1.1

Published

Web component that facilitates connecting to Cardano browser based wallets

Downloads

27

Readme

Cardano Connect web component

This component provides a button, a list of browser based Cardano wallets. When the user selects a wallet, it will attempt to connect via the browser plugin. If successful it will emit an event CardanoConnectWallet or in the case of an error CardanoConnectWalletError.

Make a donation addr1qyv48l03e9gap3vxxvuc60l8d4hpgx7cf86p3tmjte70sc75dl8x2jk2urg38kkrpcmlkdn020cjqckma0t8favg62mqnjlu30

Supported Cardano wallets

Component API

Component documentation

How to use

Include the script

<script src="dist/cardano-connect.js"></script>

Override CSS (optional)

<style>
  cardano-connect {
    --btn-bg-color: purple;
    --btn-text-color: white;
    --btn-hover-bg-color: #995799;
    --btn-hover-text-color: white;
  }
</style>

Embed component

<cardano-connect 
  text="Connect wallet"></cardano-connect>
<cardano-connect 
  text="Connect wallet"
  json="true"></cardano-connect>

text attribute is optional, the default value is Connect wallet

json attribute is optional, the default value is false, returns a json list of supported wallets

How does it work?

When a user clicks the button a dropdown list of Cardano browser based wallets is displayed. The user selects one, then they are prompted by the wallet's browser plugin to sign and connect. Once connected, the element will emit an event CardanoConnectWallet which contains the following:

  • address: selected wallet address
  • name: selected wallet name
  • icon: selected wallet icon
  • api: Cardano API object with following properties:
    • getNetworkId
    • getBalance
    • getUtxos
    • getUsedAddresses
    • getUnusedAddresses
    • getRewardAddresses
    • getChangeAddress
    • signData
    • signTx
    • submitTx
  • serializer: cardano-serialization-lib

If an error occurs the element will emit an event CardanoConnectWalletError which contains the following:

  • code: error code
  • info: error info
  • name: selected wallet name
  • icon: selected wallet icon

Read more: https://github.com/cardano-foundation/CIPs/tree/master/CIP-0030

If json is set to true, the component will emit CardanoConnectWalletList with is a json list of supported wallets. The structure looks like (array):

  • display: (string) Wallet display name, ex: Eternl
  • id: (string) Wallet display name, ex: eternl (internal use only)
  • installed: (boolean) if true, it was found as a property of the Cardano object in the browser
  • icon: (string) base64 image string to show the wallet icon/logo

On user select, fire CardanoConnectWalletSelected with the entire selected wallet object to the component and it will return the needed wallet information

Listen for success

document.getElementsByTagName('cardano-connect')[0].addEventListener(
  'CardanoConnectWallet',
  (evt) => {
    const { detail } = evt;
    console.log(detail);
  },
  false
);

Listen for error

document.getElementsByTagName('cardano-connect')[0].addEventListener(
  'CardanoConnectWalletError',
  (evt) => {
    const { detail } = evt;
    console.log(detail);
  },
  false
);

Listen for JSON wallet list event and fire selected wallet event

document.getElementsByTagName('cardano-connect')[0].addEventListener(
  'CardanoConnectWalletList', // event name
  (evt) => {
    const { detail } = evt;
    const { wallets } = detail; // wallet list
    wallets.forEach((wallet) => { // iterate over collection and display as you like
      const btn = document.createElement('button');
      btn.innerText = wallet.display;
      if (!wallet.installed) {
        btn.setAttribute('disabled', 'disabled');
      }
      btn.onclick = (e) => {
        const evt = new CustomEvent(
          'CardanoConnectWalletSelected',
          { detail: { wallet } }
        );
        jsonButton.dispatchEvent(evt); // dispatch event with selected wallet
      };
      document.getElementById('walletButtons').appendChild(btn);
    });
  },
  {
    once: true
  }
);