Socket
Book a DemoInstallSign in
Socket

bitcoin-qr

Package Overview
Dependencies
Maintainers
1
Versions
17
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

bitcoin-qr

A zero-dependency, zero-framework QR code web component for Bitcoin on-chain, Lightning, and unified BIP-21 payments.

1.5.0
latest
Source
npmnpm
Version published
Maintainers
1
Created
Source

<bitcoin-qr />

MIT License Latest Version npm

A zero-dependency, zero-framework QR code web component for Bitcoin on-chain, Lightning, and unified BIP-21 payments.

PRs and suggestions welcome!

Table of Contents

Features

  • URI support for Lightning, on-chain, BIP-21
  • Poll for payment
  • Customizable styles
  • WebLN support
  • Embed or overlay images

Background

When developing a Bitcoin payment flow, there are multiple ways a user can expect to be able to pay. They might want to pay an on-chain address or Lightning invoice, they may be scanning a QR Code from their phone, copy/pasting from a wallet, or using a WebLN browser extension. Creating an intuitive interface that also captures all the possible ways a user can pay is one of the fundamental UX challenges of developing an application that can receive payments in Bitcoin.

This flexibility opens up many exciting use cases, but often comes at the cost of being able to easily develop a smooth experience for the user. The greater the developer's cognitive load, the more difficult it is to create intuitive UX.

This project aims to provide everything needed to allow standard Bitcoin & Lightning Network payments out of the box. It handles creating the proper URIs from just an address or invoice, and favors creating unified URIs whenever possible. Styles are highly customizable and images can be embedded. It also includes polling functionality -- a callback can be passed as a property of the element to periodically check for payment.

See the Roadmap

Installation

CDN

<script type="module" src="https://unpkg.com/bitcoin-qr@1.4.1/dist/bitcoin-qr/bitcoin-qr.esm.js"></script>

NPM

yarn add bitcoin-qr

Usage

To get the first image above:

HTML:

<!doctype html>
<html lang="en">
  <head>
    <script type="module" src="https://unpkg.com/bitcoin-qr@1.4.1/dist/bitcoin-qr/bitcoin-qr.esm.js"></script>
  </head>
  <body>
    <bitcoin-qr
      id="qr"
      width="300"
      height="300"
      bitcoin="BC1QYLH3U67J673H6Y6ALV70M0PL2YZ53TZHVXGG7U"
      parameters="amount=0.00001&label=sbddesign%3A%20For%20lunch%20Tuesday&message=For%20lunch%20Tuesday"
      image="https://voltage.imgix.net/Team.png?fm=webp&w=160"
      type="svg"
      corners-square-color="#b23c05"
      corners-dot-color="#e24a04"
      corners-square-type="extra-rounded"
      dots-type="classy-rounded"
      dots-color="#ff5000"
    />
  </body>
</html>

Sveltekit:

<script lang="ts">
  import { defineCustomElements } from 'bitcoin-qr/loader';

  defineCustomElements();
</script>

<bitcoin-qr
  id="qr"
  width="300"
  height="300"
  bitcoin="BC1QYLH3U67J673H6Y6ALV70M0PL2YZ53TZHVXGG7U"
  parameters="amount=0.00001&label=sbddesign%3A%20For%20lunch%20Tuesday&message=For%20lunch%20Tuesday"
  image="https://voltage.imgix.net/Team.png?fm=webp&w=160"
  is-polling="true"
  poll-interval="1000"
  type="svg"
  corners-square-color="#b23c05"
  corners-dot-color="#e24a04"
  corners-square-type="extra-rounded"
  dots-type="classy-rounded"
  dots-color="#ff5000"
/>

More Examples

API Reference

Base attributes:

AttributeTypeDescriptionDefaultExample
unifiedstringOptional. A BIP-21 URIbitcoin:BC1QYLH3U67J673H6Y6ALV70M0PL2YZ53TZHVXGG7U?amount=0.00001&label=sbddesign%3A%20For%20lunch%20Tuesday&message=For%20lunch%20Tuesday&lightning=LNBC10U1P3PJ257PP5YZTKWJCZ5FTL5LAXKAV23ZMZEKAW37ZK6KMV80PK4XAEV5QHTZ7QDPDWD3XGER9WD5KWM36YPRX7U3QD36KUCMGYP282ETNV3SHJCQZPGXQYZ5VQSP5USYC4LK9CHSFP53KVCNVQ456GANH60D89REYKDNGSMTJ6YW3NHVQ9QYYSSQJCEWM5CJWZ4A6RFJX77C490YCED6PEMK0UPKXHY89CMM7SCT66K8GNEANWYKZGDRWRFJE69H9U5U0W57RRCSYSAS7GADWMZXC8C6T0SPJAZUP6
bitcoinstringOptional. A bitcoin addressBC1QYLH3U67J673H6Y6ALV70M0PL2YZ53TZHVXGG7U
lightningstringOptional. A Lightning invoice (BOLT-11) or offer (BOLT-12)LNBC10U1P3PJ257PP5YZTKWJCZ5FTL5LAXKAV23ZMZEKAW37ZK6KMV80PK4XAEV5QHTZ7QDPDWD3XGER9WD5KWM36YPRX7U3QD36KUCMGYP282ETNV3SHJCQZPGXQYZ5VQSP5USYC4LK9CHSFP53KVCNVQ456GANH60D89REYKDNGSMTJ6YW3NHVQ9QYYSSQJCEWM5CJWZ4A6RFJX77C490YCED6PEMK0UPKXHY89CMM7SCT66K8GNEANWYKZGDRWRFJE69H9U5U0W57RRCSYSAS7GADWMZXC8C6T0SPJAZUP6
parametersstringOptional. A query string. Must be parseable by URLSearchParams?amount=0.00001&label=sbddesign%3A%20For%20lunch%20Tuesday&message=For%20lunch%20Tuesday
is-pollingbooleanOptional. A boolean value indicating whether the component should continue pollingfalse
poll-intervalnumberOptional. The frequency at which to poll in milliseconds5000
debugbooleanOptional. Enable debug modefalse
image-embeddedbooleanOptional. Specify if the image should be embedded within the QR code or overlayed on top. The larger the image overlay, the higher the qr-error-correction-level neededfalse

At least one of unified, bitcoin, or lightning must be defined in order for the QR Code to render. All Bitcoin addresses and Lightning invoices will be prepended with bitcoin: and lightning: URIs, respectively. If both bitcoin and lightning are defined, a unified string of the format bitcoin:<ADDRESS>?lightning=<INVOICE> will be passed to the QR Code. If unified is defined, bitcoin and lightning are ignored. Whatever is passed to parameters will be appended to the unified string, whether it was provided via the unified attribute or created from the bitcoin & lightning params.

NOTE: There is currently no validation for the unified, bitcoin, lightning, or parameters fields. This is currently on the roadmap. Validate what you're passing in!

| click-behavior | click-callback | Optional. Set the behavior when clicked. The possible options are: copy, click-callback, or none. If click-callback is set, a function attribute clickCallback is expected which will fire on click. If this attribute is not set, the clicking the QR code will result in mobile deep link behavior. | false |

Callback

<bitcoin-qr /> can also be given a callback property which it will poll at a given poll-interval

<script>
    async function checkPayment() {
        ...
    }

    const qr = document.getElementById('my-bitcoin-qr')
    qr.callback = checkPayment
</script>

Styles and Other Options

This component is built on top of qr-code-styling, refer to their documentation for more details on their API, <bitcoin-qr /> surfaces the majority of it:

AttributeTypeDescription
widthnumberOptional. Width of the QR code.
heightnumberOptional. Height of the QR code.
typestringOptional. Type of QR code to draw. Options: 'canvas', 'svg'.
marginnumberOptional. Margin around the QR code.
imagestringOptional. URL of the image to overlay on the QR code.
shapestringOptional. Shape of the QR code. Options: 'square', 'circle'.
qr-type-numbernumberOptional. Type number of the QR code.
qr-modestringOptional. Mode of the QR code. Options: 'Numeric', 'Alphanumeric', 'Byte', 'Kanji'.
qr-error-correction-levelstringOptional. Error correction level of the QR code. Options: 'L', 'M', 'Q', 'H'.
image-hide-background-dotsbooleanOptional. Whether to hide background dots behind the image.
image-sizenumberOptional. Size of the image overlay on the QR code.
image-cross-originstringOptional. Cross-origin setting for the image overlay.
image-marginnumberOptional. Margin around the image overlay.
dots-typestringOptional. Type of dots. Options: 'square', 'dots', 'rounded', 'classy', 'classy-rounded', 'extra-rounded'.
dots-colorstringOptional. Color of the dots.
dots-rotationnumberOptional. Rotation angle for dots.
corners-square-typestringOptional. Type of corners for square. Options: 'square', 'extra-rounded', 'dot'.
corners-square-colorstringOptional. Color of corners for square.
corners-dot-typestringOptional. Type of corners for dot. Options: 'square', 'dot'.
corners-dot-colorstringOptional. Color of corners for dot.
background-roundnumberOptional. Rounding value for the background.
background-colorstringOptional. Color of the background.

Currently, only Gradient styling options are not included.

Roadmap

  • Address, invoice, BIP-21, and parameter validation
  • Add tests
  • Optional copy (as opposed to URI)
  • Add remaining qr-code-styling properties (gradients)
  • Add aria labels for accessibility
  • Add share button

Run Locally

yarn # install dependencies
yarn dev # opens at localhost:3333

License

MIT

FAQs

Package last updated on 18 Aug 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.