#11 - The Summer of Bitcoin Experience
What is WebLN and how to get started building with it, chat with SOB 2022 intern Dhruv Baliyan and best bitcoin jobs for freshers!
Hello Summer of Bitcoiner!
Thought of the Week
Summer of Bitcoin 2022 intern Sanjay Singh Rajpoot breaks down what WebLN is and how to build apps that enable lightning transactions on the web using WebLN.
What is WebLN?
WebLN is a library and set of specifications for lightning apps and client providers to facilitate communication between apps and users’ lightning nodes in a secure way. It provides a programmatic, permissioned interface for letting applications ask users to send payments, generates invoices to receive payments, and much more.
Integrating lightning with the web
Lightning Network is just another software layer, and we want to integrate it with the web, adding Lightning to web will go a long way in enabling bitcoin payments natively on the internet. This is precisely the idea behind WebLN, which is a simple JavaScript tool to build Lightning-enabled browser extensions using makePayment and sendInvoice (again, the two core functions for any kind of money: sending and receiving).
WebLN offers a few advantages. First, JavaScript is nearly universal and almost thirty years old. Second WebLN delivers a better interface for the users, starting with the fact that you don’t need to use a second device. It feels native, not like a workaround. You also have access to all browser events, so a key press, a mouse click, a scroll position, etc. can all trigger a payment.
Installation
First Way: Install with Package Manager (Preferred)
Install the webln
library using your package manager of choice:
npm:
npm install --save webln
yarn:
yarn add webln
And import it into your project wherever you need it:
import { requestProvider } from 'webln';
Second Way: Include Script (Alternative)
Alternatively, you can include a script on your page that will load the library. Be sure to keep the integrity check to prevent malicious Javascript from loading.
<script
src="https://unpkg.com/webln@0.2.0/dist/webln.min.js"
integrity="sha384-mTReBqbhPO7ljQeIoFaD1NYS2KiYMwFJhUNpdwLj+VIuhhjvHQlZ1XpwzAvd93nQ"
crossorigin="anonymous"
></script>
Most of WebLN’s methods will prompt the user in some way, often times to make payments or have them provide the information they may feel is quite private. Before running requestProvider
or other methods, make sure the user knows what your app does, and why they should allow your calls to run. Popping up as soon as they load a page will cause users to reject WebLN requests, or worse yet, bounce from your page.
requestProvider
To begin interacting with a user’s Lightning node, you’ll first need to request a WebLNProvider
from them. WebLNProvider
is a class that various clients implement and attach to your web session. Calling requestProvider
will retrieve the provider for you, and prompt the client for permission to use it. Once you get the provider, you're free to call all of the other API methods.
WebLN getInfo function
Ask the user for some information about their node. The request may be rejected by the user depending on the provider implementation.
function getInfo(): Promise<GetInfoResponse>;
Response
interface GetInfoResponse = {
node: {
alias: string;
pubkey: string;
color?: string;
};
}
webln.makeInvoice
This is used to create an Invoice for the user by the app. This will return a BOLT-11 invoice. There are many ways to request an invoice:
By specifying an explicit
amount
, the user's provider should enforce that the user generate an invoice with a specific amountWhen an explicit
amount
is not set, the user can return an invoice that has no amount specified, allowing the payment maker to send any amountBy specifying a
minimumAmount
and / ormaximumAmount
, the user's provider should enforce that the user generate an invoice with an amount field constrained by that amount
Amounts are denominated in satoshis. For large amounts, it’s recommended you use a big number library such as bn.js as Javascript only supports 32 bit integers.
Parameters
function makeInvoice(args: RequestInvoiceArgs): Promise<RequestInvoiceResponse>;
interface RequestInvoiceArgs {
amount?: string | number;
defaultAmount?: string | number;
minimumAmount?: string | number;
maximumAmount?: string | number;
defaultMemo?: string;
}
Response
interface RequestInvoiceResponse {
paymentRequest: string;
}
What if there is an error?
To handle this test case both apps and providers can make use of WebLN’s pre-defined errors. They can be found in webln/lib/errors
and should be used when throwing and handling errors to best inform the user of what's going on:
And the provider should throw the correct error when possible, just add this code to your project and if there is any error that will be displayed directly on your browser:
Resources
Have fun building with lightning on the web using WebLN!
Are you starting out in bitcoin today and want to learn how to build apps on the bitcoin blockchain?
Build On L2 (BOL2) is a community-led effort by contributors and companies building on Core Lightning and the Liquid Network. It's a space to connect with bitcoin builders, product managers, designers and developers through events and mentorship programs and learn from experts building the future of bitcoin.
Completely free and accessible, each layer-2 protocol has a respective community platform that will host activities including:
Localized hackathons
Virtual networking events
Project bounties and other incentive programs
International builder tournaments
Career development programs
Mentorship and coaching
AMAs with leading developers
Visit buildonl2.com to join the community and learn how to build killer apps on bitcoin.
Interview with Dhruv Baliyan
We spoke with Dhruv Baliyan, a 22-year-old university student of J.S.S Academy of Technical Education, India and a Summer of Bitcoin 2022 intern who contributed to Bitcoin Dev Kit. We discuss why bitcoin is important, his Summer of Bitcoin project, and advice on getting started with bitcoin.
Listen to the full conversation on Spotify here.
You can also watch a video of the conversation here.
Read the full transcript:
ADI SHANKARA: Hey Dhruv, welcome to the Summer of Bitcoin Experience!
DHRUV BALIYAN: Thanks Adi for having me here!
SHANKARA: Tell us a bit about yourself.
BALIYAN: I'm Dhruv Baliyan. I'm a final year computer science undergraduate from India. I have different experience in different tech stack like Android, backend and now bitcoin. I interned at Summer of Bitcoin 2022. And so here I am sharing my experience.
SHANKARA: Awesome. So Dhruv we would love to know how you got into bitcoin, like when was the first time you heard about it? And what was your first impression?
BALIYAN: I remember the first time I heard about the term bitcoin, and it was when I was in my high school, and I think it was something related to investing and stuff. At that time, I had no idea what bitcoin was, other than it was some digital currency. So I just thought, it's just an investment asset for people to make money. So I didn't pay much attention at first.
SHANKARA: I see. So between then and now, what changed, what convinced you to pay attention?
BALIYAN: I joined college, started studying computer science and I usually watch videos from a YouTube channel named 3Blue1Brown. And one day I got recommended a video from the channel and the title was, ‘but how does bitcoin actually work?’, and as I was studying computer science, that got me interested, so I watched the video and that helped me understand how bitcoin works on some level. So that got me basically interested in bitcoin.
SHANKARA: Alright, and then you heard about Summer of Bitcoin, you applied to it. Tell us what that was like?
BALIYAN: So a student from my college, interned at Summer of Bitcoin, a year prior to me, so that's where I heard it from. I wanted to start contributing to open source and as I was interested in bitcoin, so therefore, I thought about applying here and that's what I did.
SHANKARA: Okay, so before we jump into your Summer of Bitcoin experience - you heard about bitcoin first time in your high school, then of course, you came across that famous video which I would recommend everyone to watch, it's a really good explainer on the basics of how bitcoin works by 3Blue1Brown. So then you applied to Summer of Bitcoin. You obviously spent the summer last year in 2022 working on a project which we'll talk about in a moment, but tell us, now that you know everything about bitcoin, you have already contributed to parts of it. Why do you think bitcoin is important? Why should we pay attention?
BALIYAN: For me, the most important thing about bitcoin is that there are no restrictions. You can make payments anywhere across the globe with minimal fee. You don't need to have trust in anyone as it is decentralized. So like in some countries, the government has set really low cash withdrawal limits, but that is not the case with bitcoin. There is no central authority who makes decisions for us. And the other thing is unlike fiat currency, in bitcoin there is a limited supply and it is backed by energy while the fiat currency can be printed and is not backed by anything and not handling that the right way can cause inflation, and bitcoin solves all that and the adoption is increasing, and it's a great money.
SHANKARA: Beautiful, that's a beautiful answer. Cool, so let's switch gears to Summer of Bitcoin. Tell us about the organization that you selected, what it does and why did you apply to that organization?
BALIYAN: So before applying to Summer of Bitcoin, I only knew about android development. So that's why I initially wanted to contribute with a project named Padawan wallet that is an android application. So I made a few contributions there. But the thing that interested me more was the library that the Padawan wallet was using to communicate with the blockchain. And it was the BDK library. And that's why I decided to contribute to BDK instead and learn whatever was required to do so. BDK, which is short for bitcoin dev kit, is a lightweight library that is written in rust. And the project that I contributed to was the BDK FFI. What it does is basically it generates bindings for the rust code that is in the BDK library, so that the same code can be used to create libraries in different languages for different platforms. And right now it supports the language Kotlin, Swift and Python.
SHANKARA: Nice. Do you recall any challenges, during the project while helping with BDK FFI, would you like to share some of that experience?
BALIYAN: It was my first time working on a project with Rust. And I had never worked with this before. And it took some time for me to understand why the library is designed the way it is, and what are the best practices while using Rust. There are some limitations using Rust in this project as this project uses unify.rs. This tool is used to generate bindings. So we had to program in a way to get around those limitations. During the internship, the requirements for the API also changed a bit. The API I was supposed to build was to create child keys from the parent key. The plan changed a bit because the requirement was added that we had to add descriptor templates. So we had to implement the API in a different way that checks the new requirements. So there was like, all these problems that came during the development and we had a thorough way around it with the help of mentors.
SHANKARA: Great. Tell us more about the experience working with the mentors, who was your mentor and how did that go with him?
BALIYAN: I had two mentors actually. Steve and Sudarshan - they were really helpful during the internship. They have a great experience in Rust and have great knowledge about bitcoin. They also helped me understand some concepts about them. I had set up a meeting with Steve where he made me understand how SegWit works. I had a problem understanding that so we used to have a call on a weekly basis where we discussed the progress on the pull request, and what are the challenges that people are facing. And you know, and even after the internship, I have been in touch with those people.
SHANKARA: Great, so tell us more about that. Like how are things going after the internship? Are you still working on any bitcoin projects?
BALIYAN: So after the internship ended, I made few contributions to the BDK FFI, but I want to now contribute to the core logic of the library. So that's why I'm revisiting some bitcoin topics, having solid understanding. And the other thing that I'm doing in bitcoin right now is I have started a blog series that is named learn bitcoin with examples. I have not published it anywhere yet. It's still on my GitHub. These blogs will help people understand bitcoin with some exercises. There are many resources to learn bitcoin from, but this is the way I would have liked to understand bitcoin when I started. So maybe these blogs can help people who are like me, want to play with the CLI and want to practice what they learn at the same time - using the exercises.
SHANKARA: Wow, that sounds really exciting. Looking forward to that. Hopefully it comes out soon!
BALIYAN: I'm kind of planning on writing a blog per week. It's going on track as of now.
SHANKARA: Alright. Awesome. So on the same lines maybe you want to share some advice on how to understand bitcoin and how to go about it, especially if you're a beginner.
BALIYAN: Summer of Bitcoin’s YouTube channel actually has a playlist - where Kalle Rosenbaum explained bitcoin from the base up, like a really thorough explanation. It was really great! So people can start from there or if you are into reading books, you can start from Mastering Bitcoin, it is available on GitHub - that covers all the basic topics that you require to understand bitcoin basically.
SHANKARA: Yep, Kalle Rosenbaum is the author of Grokking Bitcoin. So in 2021, we had a lecture series where he came in, he essentially gave a series of video lectures on the basics of bitcoin which was based on the book that he authored, which is called Grokking Bitcoin and Mastering Bitcoin is a great book as well. All those links are up - you can find them either by googling or you can also check out our guide at summerofbitcoin.org. You'll find the links to both those resources on the site.
Dhruv, any specific advice on just open-source development? Since you know it's not just bitcoin, but it's also open source. And, there are many good practices that one could learn as you're contributing to open-source projects.
BALIYAN: So programming in public is scary at first, like the thought that your code will be reviewed by a bunch of people online, you will get stuck at a problem that is for sure. So what you should do is before asking questions, you should do a little research of your own. You cannot depend on someone else to solve every problem that you have. Try the best you can to solve something and then ask in a way that explains what the problem is, and what are all the things that you have tried to solve that. This way people will know that you have actually tried and would be more willing to help you. And also try joining the meetings that the project maintainers have to get in sync with what is going on with that open-source project and try not to disturb someone for no reason like little things that you can do on your own. And the other thing after you submit a pull request, like adding a feature or solving an issue, you should be expecting some questions and suggestions on the code that you wrote by the people who review them or the project maintainers. They will also suggest some changes according to the best practices and they can also point out some potential bugs. This is how you learn basically - do not overthink just try the best you can.
SHANKARA: Awesome. And finally, Dhruv, do you have any tips that you want to give out to aspiring applicants of Summer of Bitcoin and maybe some advice on how to succeed if they're selected for the internship?
BALIYAN: According to me, you should first shortlist the organizations that you're interested in. These are available on the Summer of Bitcoin site. And do not be afraid of the tech stack that is used to build those products. Just focus on the organization that you find interesting, and then study the codebase by setting it in your local machine. If you're having trouble setting up the project, just ask in discord. If you find some bug then create an issue on GitHub, start solving issues on that repository, help with reviewing the PRs, get in touch with potential mentors. These all things can improve the chances of you getting selected as an intern. And the next part that comes is the proposal writing. Select the idea that is released by the organization that you find interesting and study about all the topics that are required to build that feature. So now that you already know about how the project works, and how the code is structured, you can just write a proposal on how you will be implementing that feature. Also you can get your proposal reviewed by mentors even before the proposal submission deadline, but that's why you should get in touch with them early on. And they will provide you with some feedback on how you can improve your proposal and do all that and I think you will have a high chance of getting selected.
SHANKARA: Awesome. Dhruv, thank you so much for sharing about your experience and also giving advice to aspiring applicants with bitcoin and open source. It was great to have you.
BALIYAN: Thanks Adi!
JOBS IN BITCOIN
If you are a fresher straight out of college, here are a few exciting job postings we recommend:
Engineering:
NOSTR Dev | Zion | Austin, TX, USA, Remote | Apply
Mobile developer (IOS and Android) | Easepay | Nigeria, Remote | Apply
iOS Engineer | lipa | Bern, Switzerland, Remote | Apply
Android Engineer | lipa | Bern, Switzerland, Remote | Apply
Software Engineer & Remnant | plebeian.market | Remote | Apply
Bitcoin Developer | Ordx | Remote | Apply
Software Engineer, iOS (Native) | Blockstream | Europe OR Canada, Remote | Apply
NodeJS Engineer | Synonym | Remote | Apply
Lead Mobile Engineer | Galoy | Remote | Apply
Software Engineer | Mash | Remote | Apply
Wordpress Wizard | DCA Signals | Remote | Apply