Lately I’ve been hearing a lot of hype around web3- cryptocurrencies, NFTs, DAOs, DeFi, GameFi and all of these cool jargons giving me a lot of FOMO (Fear of missing out), so I decided that I’m gonna try some of them for myself and see what’s it all about.
I tried a few things like buying some cryptos on an exchange, made a couple of web3 projects and joined a gazillion of discord channels doing the morning ritual of gm(good morning!) and responding to WAGMI(we all gonna make it!) but this one specific project called Monero caught my attention and I wanted to share it with the community here.
Before proceeding I want to put out that this is in no way an endorsement of the project or whole blockchain/web3 ecosystem in general, nor it’s a financial, get rich by mining cryptocurrency advice. This is in fact a fun project which you can build along to learn more about web3 and being a developer advocate, I’m also gonna use this project to share about the concept of :
Using a separate docker images for build-time and run-time within the same Dockerfile, we will see why it’s important and how to achieve that later in this post
Nevertheless, this project is kind of a fun to build, it allows you to mine cryptocurrency called XMR of Monero blockchain, profitable or not you can no doubt brag about mining cryptocurrency at your home to your friends, so let’s get started 😉
You can skip the inner details and jump straight to the build part down in the post if you like.
BackgroundWithout going too much into the detail, for someone new into the web3 ecosystem - A blockchain is a distributed ledger which keeps records of every transaction happening over it. Just like how a bank keeps the record of who sent money to whom, the amount as well as the date and time, similarly in case of blockchain this immutable information is maintained within distributed blocks connected by a network.
This validation of all the transactions on a blockchain is done by certain users who lend their compute power in the form of miners or validator nodes. There are also some programs called smart contracts which can run automatically on blockchain when certain conditions are met but that is out of scope for this blog so will not go into more details of smart contracts.
When you think of Bitcoin or Ethereum miners you might imagine a big server room consisting of massive GPUs or ASICs machines dedicatedly solving complex cryptographic problems sent to them by blockchain and once they solve it they earn rewards in the form of cryptocurrencies The process of successful submission to earn the rewards follows certain consensus mechanism which can vary depending on the type of blockchain
For example: Bitcoin blockchain works on a consensus mechanism known as Proof of Work (PoW), while Solana works on Proof of Stake (PoS) and Proof of History(PoH). You can read all about types of consensus mechanism here
If you’re feeling disheartened seeing the cost of these mining computers crushing your dream to have a mining rig of yourself, don’t be because the project we’re talking today called Monero allows or in fact encourages mining on CPUs, so even a small single board computer like Raspberry Pi 4 can become a miner to help validate the transactions and get the rewards in form of XMRs, the cryptocurrency of monero blockchain.
The philosophy behind this is since the cost and entry barrier to mine is pretty high, the miners are usually owned by few persons or organizations which may not be good for blockchain’s decentralization (no ownership and trustlesness by design), so monero optimizes to allow more and more people to contribute making their blockchain more decentralized. Monero also works on Proof of Work but instead of your small device solving a really complex cryptography puzzle it can join a mining pool with other devices to lend the compute power and together they can solve it fast and depending on how much your device contributed to the solution it’ll be rewarded suitably for that.
Is it profitable? Maybe not, given the device needs to be powered on and running but it surely is fun and maybe you can really earn if you add a lot of devices in your mining pool with good resources, say Rpi with 8 GB RAM; nevertheless it’s not financial advice so please do your due diligence :)
You can read all about Monero project, how much it pays for mining, costs associated, etc all on official website: here
BuildHardware Needed- A single board computer like raspberry pi 4 (more ram the better).
The following SBCs were tested by my friend Lambros and this was the hashrate result:
Raspberry Pi 3 - 20 H/s
Raspberry Pi 4, 1 GB RAM - 45 H/s
Raspberry Pi 4, 4 GB RAM - 99 H/s
Nvidia Jetson Nano 2GB (without GPU enabled) - 62 H/s
Hash rate(H/s) is the number of hashes a device can solve per second. I’ve not enabled CUDA(GPU backend) for Nvidia Jetson since monero encourages mining on CPU though if you want to give it a shot I’d love to see how it performs.
Other things you'll need are
- SD card
- Power supply
- Connectivity to Internet via LAN or WiFi
monero wallet (this is where you’ll get the rewards) download from https://www.getmonero.org/downloads/Information of mining pools : as mentioned earlier we will be joining a mining pool, the address of active mining pools can be found by a simple google query, it’s better to use one near you ex: google search monero mining pools in Los Angeles. Each mining pool has their own threshold after which they start paying out to the wallets.
- monero wallet (this is where you’ll get the rewards) download from https://www.getmonero.org/downloads/Information of mining pools : as mentioned earlier we will be joining a mining pool, the address of active mining pools can be found by a simple google query, it’s better to use one near you ex: google search monero mining pools in Los Angeles. Each mining pool has their own threshold after which they start paying out to the wallets.
balenaCloud account to manage miners
- balenaCloud account to manage miners
balenaEtcher to flash the SD card
- balenaEtcher to flash the SD card
Visit the project page on balenaHub and click 'fork this fleet'
Select the DeviceAdd OS type: Production vs Development
- Add OS type: Production vs Development
(optionally) add in your home WiFi credentials, download and flash the OS to SD card using etcher
- (optionally) add in your home WiFi credentials, download and flash the OS to SD card using etcher
If you are already a balena user it might be better for you to use this way. You can clone the project from this github repo and use the balena CLI commandbalena push <fleet_name>
to push the application to your devices in the fleet created on dashboard. This is the best option if you want to tinker with the project and have full control. The Getting Started Guide covers this option. After you've created the application and pushed the code using the CLI, follow the steps below.
When the device boots for the first time, it connects to the balenaCloud dashboard, after which you’ll be able to see it listed online. In the meanwhile we need to Install Monero wallet on our computer where we will be getting the mining rewards
Software SetupDownload the Monero wallet from https://www.getmonero.org/downloads/GUI or CLI as per your preference. I recommend using a GUI wallet and create a new wallet using Simple Mode.
Once the wallet is created you’ll have a unique wallet address copy that to clipboard and head over to:
balena cloud > your device > Device Variables
tab and add the following
This will restart the container and your miner will be registered to the mining pool and start getting the jobs. All the rewards will be sent to your monero wallet after your device meets the threshold of the miner pool.
Now as I mentioned above this may not be profitable at all but it's definitely fun and let’s look at some totally unrelated things that we're gonna learn here.
Container LearningsHere is the project’s Dockerfile.template. If you take a closer look at it, you’ll see there are two different base images being used. One of them is a build image and other one is the run image
Why we do that is simply because we don't want our run image to be bloated with extra packages which were needed to build a source code. So we conduct the build in a separate image and copy the artifacts or binaries in the run image using
This way our main image is minimal and less bloated. All of the balena base images are available as build and run. The build image has additional packages such as gcc, build-essential which are needed to build from source whereas the run image is minimal. You can read more about it here.
So this was the container lesson from this blog. Now I hope you do use this project to dip into the world where IoT edge computing meets web3 and as always if you have any suggestions, feedbacks or questions, please write on balenaForums or any social media channel. I'll be back with another interesting project and lesson soon 🍻
Attribution
===
Comments