This project includes web components for connecting to Lightning wallets and enabling WebLN. Websites only need to implement a single interface to connect with multiple wallets (WebLN), and users can connect from both desktop and mobile devices. These components work with pure HTML and all Javascript libraries or frameworks, such as React, Angular, Vue, Solid.js, etc.
🆕 Bitcoin Connect also supports a nice invoice payment UI that gives a multitude of options to a user to pay an invoice. Accept payments with a single line of code.
🚧WARNING🚧: this package is currently in Alpha. It's got awesome features, but is using new features of protocols such as WebLN and NWC which have not been finalized, and there may be breaking changes or bugs.
npm install @getalby/bitcoin-connect-react or yarn add @getalby/bitcoin-connect-react
npm install @getalby/bitcoin-connect or yarn add @getalby/bitcoin-connect
You can use Bitcoin Connect without any build tools:
NOTE: LNC connector is not supported!
<script src="https://cdn.jsdelivr.net/npm/@getalby/bitcoin-connect@2.4.2/dist/index.browser.js"></script>import {Button, Modal, launchModal, closeModal} from '@getalby/bitcoin-connect-react';
// render a button
<Button onConnect={() => alert('Connected!')} />
// include the modal on the page (will not be rendered unless launchModal is called)
<Modal onConnect={() => alert('Connected!')} />
// open modal programmatically
<button onClick={launchModal}>
Programmatically launch modal
</button>
// open modal programmatically to pay an invoice
<button onClick={() => launchModal({invoice: "lnbc...."})}>
Programmatically launch modal
</button>
// close modal programmatically
closeModal();Make sure to only render the components client side. This can be done either by creating a wrapper component with 'use client' directive (NextJS app directory) or by using next/dynamic.
Use another popular framework? please let us know or feel free to create a PR for a wrapper. See the React package for an example implementation.
Bitcoin Connect exposes the following web components for allowing users to connect their desired Lightning wallet:
<bc-button/>- launches the Bitcoin Connect Modal on click<bc-modal/>- render the modal on its own.- Optional Arguments:
open- make the modal appear
- Optional Arguments:
<bc-connector-list/>- render the list of connectors on their own<bc-send-payment/>- render a payment request UI- Arguments:
invoice- BOLT11 invoice
- Arguments:
- more components coming soon
app-name(React:appName) - Name of the app requesting access to wallet. Currently used for NWC connections (Alby and Mutiny)filters- EXPERIMENTAL: Filter the type of connectors you want to show. Example: "nwc" (only show NWC connectors). Multiple filters can be separated by a comma e.g.nwc,second_filter.
Bitcoin Connect exposes the following events:
bc:connectedwindow event which fires when a wallet is connected and window.webln is ready to usebc:connectingwindow event which fires when a user is connecting to their walletbc:disconnectedwindow event which fires when user has disconnected from their walletbc:modalopenedwindow event which fires when Bitcoin Connect modal is openedbc:modalclosedwindow event which fires when Bitcoin Connect modal is closed
<bc-modal/> needs to be rendered somewhere on the page. The modal can then be launched with:
window.bitcoinConnect.launchModal();launchModal can also take an optional options object:
launchModal({
invoice: 'lnbc...', // bolt11 invoice
});window.bitcoinConnect.closeModal();
window.bitcoinConnect.disconnect();
window.bitcoinConnect.isConnected();
More methods coming soon. Is something missing that you'd need? let us know!
These variables must be set at the root or on a container element wrapping any bitcoin connect components.
html {
--bc-color-brand: #196ce7;
}Optional CSS variables for further customization:
html {
--bc-color-brand-dark: #3994ff; /* use a different brand color in dark mode */
--bc-brand-mix: 100%; /* how much to mix the brand color with default foreground color */
}💡 using near-white or black brand colors? either set a lower
bc-brand-mixor make sure to use an off-white forbc-color-brandand off-black forbc-color-brand-darkto avoid conflicts with the modal background color.
Bitcoin Connect uses prefers-color-scheme to automatically detect light/dark mode.
In case your site uses a manual theme switcher, you can force a theme by following these steps:
see an example here
- set
globalThis.bcDarkMode = "class"before any bitcoin connect components are rendered "dark"must be added as a classname to the document to enable dark mode (e.g.<html class="dark">ordocument.documentElement.classList.add('dark')) otherwise light mode will be forced.
See Pure HTML
See React
Open demos
Run yarn install && (cd dev/vite && yarn install)
Run yarn dev
Open dev
yarn build
yarn dev:build
yarn dev:build:browser
yarn test
We are happy to help, please contact us or create an issue.
- Twitter: @getAlby
- Telegram group
- support at getalby.com
- bitcoin.design Discord community (find us on the #alby channel)
- Read the Alby developer guide to better understand how Alby packages and APIs can be used to power your app.
Bitcoin Connect provides multiple options to the user to connect to a lightning wallet, each compatible with WebLN. Any already-existing providers of WebLN (such as an installed WebLN extension like Alby) are detected and offered, as well as options to create a new WebLN provider through protocols such as NWC. No matter which option you choose, window.webln will become available for the website to use to interact with your lightning wallet. Similar to the Alby extension, new options (called Connectors) can be easily added as they all follow a common, simple interface. As long as there is a way to connect to a lightning wallet through Javascript, a connector can be created for it in Bitcoin Connect. We welcome any and all contributions for new connectors!
Yes! that's the main benefit.
Yes. It will use the desktop extension as the default connector if it exists.
That depends. The connection to your lightning node / wallet needs to be asynchronous so that you can use Bitcoin Connect natively on mobile websites or PWAs.
It will only work for the connectors that are shown in the modal. Some of these connectors (e.g. the Alby Browser Extension) allow to connect multiple wallets themselves. Feel free to contribute to add a new connector.
Yes. Your connection is saved to localStorage
You should have a certain level of trust on the website you decide to connect your wallet with, and that they ensure there is no malicious third-party scripts which would intend to read the wallet connection configuration, either from memory or storage. Connectors with budget controls or confirmation dialogs (Alby extension or NWC) are recommend so you have full control over your connection.
- add the "Connect Wallet" button
- wait for a connection event (using window.addEventListener) and then request to pay the invoice with window.webln
Bitcoin Connect cannot detect payments made externally. It's up to your app to detect the payment and then programmatically close the modal using the exposed closeModal function.
- NWC connectors do not work on iOS in non-secure contexts because window.crypto.subtle is unavailable. If testing on your phone, please run an https server or use an https tunnel.
This project is powered by Lit.
See Get started on the Lit site for more information.
