This Lightning Weather App is a cutting-edge demonstration of the L402 API's capabilities, showcasing how the Lightning Network can power applications. This project stands as a testament to an evolving digital economy where products can thrive without traditional advertising or data harvesting models. By leveraging the L402 APIs, this app offers a glimpse into a future where user experience and privacy are paramount.
The core purpose of this project is to illustrate the potential of the Lightning Network's L402 APIs in creating native applications that prioritize user privacy and a seamless user experience. Our Lightning Weather App is a prime example of a product that operates independently of advertising revenue or invasive data collection practices. It serves as a blueprint for developers looking to build innovative, user-centric applications on the Lightning Network.
This app leverages the power of L402 APIs through a variety of technologies:
-
L402: L402, developed by Lightning Labs, is a protocol that enables the monetization of APIs through the Lightning Network. It was developed by Lightning Labs, a pioneer in the development of the Lightning Network, is committed to creating scalable, fast, low-cost, and privacy-preserving public blockchains. Read more about L402 here.
-
Sulu: Monetizing APIs with L402 can be complicated. Sulu is a platform that enables API providers to seamlessly implement API monetization for their endpoints. They also provide SDKs and technology to consume and operate with these APIs.
-
Alby: Alby brings Bitcoin to the web with easy-to-use browser extensions, facilitating seamless transactions and interactions within the Lightning Network. By integrating Alby, our app demonstrates a simple yet powerful way for users to interact with Lightning Network services directly from their browsers.
-
WebLN: WebLN is a standard for web-based Lightning Network applications that enables client-side Lightning payments and identity management. Our use of WebLN in the Lightning Weather App exemplifies how developers can create more interactive and user-friendly experiences with the Lightning Network.
The Lightning Weather App is more than just a weather forecast tool. It's a harbinger for a new era of application development. It paves the way for products that are free from the constraints of conventional monetization strategies, empowering developers to create with the user's best interests in mind.
We encourage developers, enthusiasts, and visionaries to explore the Lightning Weather App, delve into its code, and consider how the Lightning Network can be the foundation of your next project. If you're inspired by the possibilities of Lightning-native applications, join us in this journey to redefine what's possible in the realm of app development.
Note: The sections beyond this point contain technical details on setting up and running the application, provided by the project maintainers.
This is a Next.js project bootstrapped with create-next-app
.
First, run the development server:
npm run dev
Open http://localhost:3000 with your browser to see the result.
Important: You will need a WebLN compatible wallet to operate this demo and pay for usage. We recommend using Alby.
To consume L402 endpoints using Alby, you can use the fetchWithL402
function from the @getalby/lightning-tools
package. This function allows you to make requests to L402 endpoints and handle the payment process seamlessly.
Here is an example of how you can use it:
import { fetchWithL402 } from "@getalby/lightning-tools";
const fetchWeather = async (city: string) => {
try {
const formatted_city = city.replace(/\s/g, '');
const response = await fetchWithL402(`https://weatherman.ln.sulu.sh/current?city=${formatted_city}`,
{},
{headerKey: "L402"})
const { current } = await response.json();
// Process the response data...
} catch (err) {
// Handle error...
}
};
In this example, fetchWithL402
is used to fetch weather data from an L402 endpoint. The city name is passed as a parameter in the URL. The function returns a promise that resolves with the response of the request.
To learn more about Next.js, take a look at the following resources:
- Next.js Documentation - learn about Next.js features and API.
- Learn Next.js - an interactive Next.js tutorial.
Please note that this is a demo application. We are not responsible for any funds lost while using this demo. Always ensure you are using small amounts for testing and understand the risks involved with digital currency transactions.