DEV Community

Lance Ellis
Lance Ellis

Posted on

Browser Mining for Charity

Abstract

For Longhorn Hack for Humanity 2022, I came across an article on crypto mining in the browser. It was often regarded as an alterative to ads, but much more intrusive given that they were often hidden and obnoxiously slowed down your computer. Since then, browser mining is often blocked by adblockers making it basically non-existence though it still occasionally happens. It was a niche platform for mining anyways; you could really only mine coins that were efficient on CPUs. However, given the theme of the hackathon was for "humanity," I saw there was some potential in a crypto miner that users consented to use to mine for charity. It was to be non-invasive, controllable, and easy to use such users felt safe using it. Thus, Tab for Charity was born.

Design is Crucial

This is first and foremost a web app meant to look good. It was important that users felt safe using the app as if the app looked sketchy is would naturally seem like a scam. The design process for the app did not take long though. Inspired from Coinbase and donation page for Ukraine for crypto, I sketched out a simple hero which inspired the design of the other pages.

Finding a Browser Miner

This was not easy. Most are rather sketchy, and I was not capable of building my own crypto miner for the web. I did eventually find Minero.cc. They took a small cut apparently, can never know actually how much they took, and had a decent API. The only issue was implementing this into a Next.js app which was the framework the project was using since the script was 3rd party vanilla JS and WASM. After some fidgeting I used the experimental Script from Next with the onLoad attribute with some state referring to the miner.

Back-end Pain

This was a learning experience. I used Mongoose, next-connect, @hapi/iron, and passport.js to implement the back-end for sign-in with Google OAuth2 and a MongoDB database. Sounds simple enough, but I painfully learnt that passport.js did not end the response after the redirect from Google OAuth leading to many hours of frustration that the session was not being saved. It eventually worked and was straight forward to implement the database afterwards.

End Product

I did not finish this project in-time for the hackathon. Which was sad because I think this was a very solid concept, but I struggled too much to implement the back-end and front-end with the miner. I eventually finished this project in my freetime which you can see here.

Top comments (0)