February 7, 2023

How to convert your IoT app to a Web3 dApp on peaq

The IoT market is projected to hit $2,270 billion by 2028 from a volume of more than $480 billion in 2022, according to some of the latest research. While a lot of the growth comes from industry, which is reinventing itself for the digital era, the consumer sector will grow too. We do, after all, live in a day and age when there’s an app for anything, from food deliveries to e-scooter sharing, and these apps leverage connected devices to enable such services. 

The problem is with the “app” part, though — it’s missing one very crucial word before it. You see, most of today’s IoT applications leverage centralized architecture, the so-called Web2 or ‘Big Tech’ stack. As with single-use plastic straws, the default way of doing things is not ideal. Centralized databases are prone to leaks and hacks (hi, Uber!), denying both private and B2B users their privacy, and grant the app builder the power to alter the app data on the go should they choose so. There’s also the lack of transparency around pricing and reward models (hey there, Instacart!), and many other ills right from Web2’s darker underbelly.  

In 2023, savvy entrepreneurs looking to gain an edge in the IoT sector can and should do things differently: ditch the Web2 stack and bring your creations to Web3, the blockchain-powered future of the internet, where privacy and user empowerment reign supreme and users have full ownership and authority over their data and identities. In this blog, you’ll get an overview of how to do so, whether you already have your app up and running or only getting started.  

Wait a sec, why Web3?

Before diving into the “how”, it would only be reasonable to go a bit deeper into the “why”. And the good news here is that switching to the Web3 stack will not just grant your users a better experience, but also opens up new opportunities and revenue streams.

On the user side, dApps are significantly more privacy-minded. Web3 doesn’t like centralized databases, which make for hacker honeypots, and scraps traditional access credentials in favor of user-owned decentralized identities. Furthermore, embracing Web3 ideals enables projects to grant users ownership not just over the data, but over the service itself, implementing token-based democratic governance mechanisms.

Thankfully, none of these benefits come with any real drawbacks on the UX side. It’s true that Web3 is largely notorious for its UX struggles, but with some effort and creative thinking, a dApp can be as frictionless and easy to use as a regular app. Take design cues from Web2 apps and make user convenience one of your priorities, and we’ll sure the result will be worth it. It’s a challenge, a chance to innovate, an opportunity to stand out. 

Going all-out Web3 also brings your project a wide array of benefits and quality-of-life improvements. First of all, you’re also benefiting from the lack of a centralized database, because you don’t have to host it and spend sleepless nights pondering over its security, management, and updates. 

Taking this a step further, hosting overall won’t sit too high up on your costs list. Web3 dApps run on smart contracts, executable code stored across thousands of nodes making up a blockchain network. This code handles business logic and is what the user interacts with when using the dApp. In other words, it’s your backend, and its hosting, transparency, scalability, and management aren’t your headache — your blockchain network of choice handles all that.

Furthermore, stepping into the blockchain space opens up a wide variety of new monetization models. Besides putting your governance or utility token up on public markets and leveraging DeFi, you can opt to utilize NFTs as additional means of fundraising or even use such platforms as Fundrs to seek extra funds across the entire Web3 community.

Last but not least, going Web3 can be a benefit when looking to enter new markets, especially when it comes to the developing world and communities lacking access to traditional finance. Blockchain is by definition borderless, and all it takes to dive in is having a phone and Internet access. Granted, that in itself can be a threshold too high in some cases, but it’s still often the more accessible option compared to opening a bank account.  

It’s worth noting that Web3 alternatives to IoT or sharing economy apps will in many cases turn out cheaper for the user and more lucrative for the service providers (like taxi drivers) by cutting out the Big Tech middlemen. Meaning if you get the user experience right, you’ve got some SERIOUS wind in your sails.

Bringing your app on-chain

Now that we’re done with the “why”, we can go to the “how”. And there’s some good news there. The first question before any project diving into the future of the Internet is what blockchain to choose. And the good news is that there’s an entire blog post about why you should build on peaq. Go ahead, read it here, we’re not going anywhere without you.

Now, in the most general terms, converting a Web2 app into a Web3 dApp is a process that includes the following steps:

  • Implement your business logic as smart contracts. We already touched upon what smart contracts are, and unless your dApp isn’t leveraging them, it’s not really decentralized. In more specific terms, what you need is to write, test, and deploy the code that handles the logic of user and machine interactions. If you are decentralizing food deliveries, you need a smart contract that is capable of taking in a user’s location and food preferences and returning a list of restaurants that they can order from. This contract, or additional supporting ones, depending on your choice of architecture for your decentralized backend, must also be able of alerting the restaurant of the order, processing the payment, pinging a user with a courier role (or a delivery drone, why not?), and rewarding them too once the food is delivered. If you already have an app, or at least a prototype, this will be the bulk of the work at hand. This doesn’t just mean converting your backend to Solidity or ink! From Javascript or whatever framework you were using, it’s about re-thinking your business logic in a way that works with the Web3 architecture. It’s hard work, but it’s worth the payoff, and you can make the job easier by leveraging various in-built functionalities of public blockchains the same way you would use a library or a framework when building a traditional app.  
  • Decentralize your data storage. Besides the core business logic, your dApp also needs a database. How would the smart contract know what restaurants are out there to quell the user’s hunger? And having a user’s order history would probably help too, as well as, potentially, the list of users registered as couriers (or delivery robots, let’s not forget about those). A traditional centralized database is not the Web3 way of doing such things. Instead, there are a variety of methods to choose from. One thing you could do is leverage decentralized storage networks such as the Interplanetary File System, where files are securely stored on a network of nodes. WIth peaq, you can easily make use of this method by leveraging our integration with the IPFS via Crust Network. Alternatively, depending on your specific needs, you can store the data locally, uploading its hashes on-chain for validation and verification purposes, or store it on-chain in an encrypted form. In both cases, various cryptography-based methods such as zero-knowledge proofs, which enable one party to validate the veracity of the data without reading it, or homomorphic encryption, which enables computation on encrypted data, will help you handle the data in a privacy-first way. 

All of the above goes for any Web3 project, whether it’s building from scratch or converting from Web2. Machine-oriented decentralized applications have their specifics, enough so to warrant a quick chat about those as well.

Challenges of device-powered dApps

As we already noted, the algorithm we just went over goes for converting pretty much any application to Web3, but dApps leveraging connected devices have their own quirks. We’ve touched upon some of these before, but just to avoid giving you the impression that you’re in for an utter cakewalk, let’s dive into them a bit more.

First of all the penultimate challenge before you is managing complex device interactions through little more than embedded software and smart contracts. Again, let’s take the drone deliveries. How does the drone get from point A, the restaurant, to point B, the delivery address? Assuming there’s a human pilot involved, things are easy enough. But what if you want the process to be automated? 

In this case, you must either somehow manage the flying machine via smart contracts or have the drone run autonomously in the first place. The former is highly complicated, and the latter means you’ll have to code the interactions between the smart contract and the drone’s embedded AI, which is likely third-party. This involves a lot of interplay between different interfaces, data formats, standards, and protocols, which is a handful to manage. And if you want the dApp to work with a variety of models from different manufacturers, the problem grows exponentially. 

Another challenge to tackle is connectivity. Since dApps run on smart contracts, which live on-chain, your device needs to be constantly connected to the Web to properly function. Should it end up in an area with low connectivity, it’s already in for a struggle, given the latency needs defined by the real-time nature of such services. In other words, if you have a smart contract running your drone, lag would mean it’s giving it inputs based on outdated data, which can result in an accident. 

An area with no coverage is obviously even more problematic. So if you’re placing your bet on autonomous machines, make sure to account for such scenarios — which is what you’d have to do anyways with a centralized backbone as well.

Time to build!

Does all of the above sound complicated? It is. Impossible, though? Not at all, and, on top of that, it’s absolutely worth it — not just for the sake of more competition, which is always a good thing, but also for our very own future. We’re moving into a reality where machines produce more and more value, but this value only lands with the select few, while the majority are struggling to make a living. A decentralized Economy of Things fixes that through shared ownership and its radical inclusion, and machine-powered dApps are its crucial building blocks. So crucial, in fact, that we’ll walk the extra mile with you to help your project blossom.

Firstly, here is the handy documentation — dive in yourself or pass it on to your developer team to see how your project could leverage peaq. Second, make sure to check out the Ecosystem Grant Program by the peaq Foundation, which supports prospective builders with funds, investor intros, and technological know-how. All of this is always handy for projects at any stage, and securing a grant relieves a lot of the pressure on the team which comes with the rush for funding and having to adapt to a new tech stack. The exposure to the ecosystem comes in handy too — head here to check out some of the companies and organizations involved with peaq in different ways. And if you need some inspiration, check out our Use Cases page, there’s a lot of cool ideas there from the peaq community. 

Build the Economy of Things.

There are open positions at EOT LABS, from engineering to communications. Start the new year with a new job and build the Economy of Things with us.

Are you interested in building a dApp for vehicles, robots, devices and other machines? Get inspired, get funded, and start building today.

Want to stay in the loop? Join the conversation on our channels.


All blogposts