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

n20-connect

v1.1.1

Published

N20 connect for unisat, notemarket and chainbow

Downloads

23

Readme

N20 Connect

N20 Connect is a library that allows you to easily integrate N20 compatible Bitcoin wallets (Unisat, ChainBow and NOTEMarketWallet) into your web application. With this library, you can enable your users to manage their Bitcoin addresses, send and receive transactions, and interact with Bitcoin wallets directly from your web app.

Features

  • Connect to popular N20 compatible (Unisat, ChainBow and NOTEMarketWallet)
  • Manage Bitcoin addresses and check balances
  • Send and receive Bitcoin transactions
  • Sign messages and PSBTs
  • Push transactions and PSBTs to the network
  • Switch between different connectors and networks
  • Customizable UI theme (light and dark)
  • Typescript support
  • Support for React components
  • Support for pure JavaScript usage (compatible with Vue, vanilla JS, etc.)

Installation

You can install the package via npm, yarn, pnpm or bun:

npm

npm install n20-connect

Yarn

yarn add n20-connect

pnpm

pnpm add n20-connect

bun

bun add n20-connect

Requirements

For React:

  • react (>=16.8.0)
  • react-dom (>=16.8.0)

The library also uses the zustand state management library for React hooks.

Usage

React

Import the WalletConnectReact component and wrap your application with it:

import React from 'react';
import { WalletConnectReact } from 'n20-connect/dist/react';
import "n20-connect/dist/style/index.css";

const App = () => {
  const config = {
    network: 'BTClivenet', // or 'testnet'
    defaultConnectorId: 'chainbow', // or 'chainbow'
  };

  return (
    <WalletConnectReact
      config={config}
      onConnectSuccess={(btcWallet) => {
        // Handle successful connection
      }}
      theme="dark"
      onConnectError={(error) => {
        // Handle connection error
      }}
      onDisconnectSuccess={() => {
        // Handle successful disconnection
      }}
      onDisconnectError={(error) => {
        // Handle disconnection error
      }}
    >
      {/* Your app components */}
    </WalletConnectReact>
  );
};

export default App;

You can also use the useReactWalletStore hook to access the wallet store and perform various actions:

import React from 'react';
import { useReactWalletStore } from 'n20-connect/dist/react';

const MyComponent = () => {
  const walletStore = useReactWalletStore();

  const connect = () => {
    walletStore.connect();
  };

  const disconnect = () => {
    walletStore.disconnect();
  };

  const sendBitcoin = async () => {
    const toAddress = '...';
    const amount = 1000;
    const txid = await walletStore.btcWallet?.sendToAddress(toAddress, amount);
    console.log('Transaction ID:', txid);
  };

  return (
    <div>
      <button onClick={connect}>Connect</button>
      <button onClick={disconnect}>Disconnect</button>
      <button onClick={sendBitcoin}>Send Bitcoin</button>
    </div>
  );
};

export default MyComponent;

Pure JavaScript

You can use the BtcWalletConnect class directly in your JavaScript code:

import BtcWalletConnect from 'n20-connect';

const config = {
  network: 'BTClivenet', // or 'testnet'
  defaultConnectorId: 'chainbow', // or 'chainbow'
};

const btcWallet = new BtcWalletConnect(config);

// Connect to the wallet
btcWallet.connect()
  .then(() => {
    // Handle successful connection
  })
  .catch((error) => {
    // Handle connection error
  });

// Send Bitcoin
const toAddress = '...';
const amount = 1000;
btcWallet.sendToAddress(toAddress, amount)
  .then((txid) => {
    console.log('Transaction ID:', txid);
  })
  .catch((error) => {
    // Handle error
  });

// Disconnect from the wallet
btcWallet.disconnect()
  .then(() => {
    // Handle successful disconnection
  })
  .catch((error) => {
    // Handle disconnection error
  });

This pure JavaScript usage makes it compatible with Vue, vanilla JavaScript, and other frameworks or libraries.

For more detailed information and examples, please refer to the Doc.

TODO

  • Support NOTE Protocol directly

License

N20 Connect is licensed under the MIT License.

Support and Donation

If you find this project helpful and you would like to support its continued development, feel free to make a donation through one of the following methods. Your support is a tremendous encouragement for us!

You can also donate N20 Token using the following cryptocurrency addresses:

  • BTC: bc1pxdh2tzxdt5kvcpsppg0e3vh3z7jzhksqwcuyg084uwj0n8ktgv2s4s2kh6