Main Content

A Blockchain-Powered Smart-Lock

Securely open/close your front door with a smart contract

Story
Ever wondered why many consider blockchain to be a game-changer in the IoT space? This example describes how to build a very simple smart-lock powered by a Blockchain smart contract to make some considerations around this topic.

The hardware
We will use a very basic solenoid-based electric lock, that requires a dc 12V input to switch in the “open” state, while a mechanical spring will push it in “closed” state when not powered. A Raspberry Pi Zero is more than enough to run the small script that monitors the blockchain and it’s small enough to fit into an hypothetical SmartLock case of a decent size. Finally the 12V power supply to power the lock and a relay board to switch it on and off complete the hardware specs for this simple project.

The blockchain
We will use the IoTeX Blockchain for the smart contract infrastructure: it has some nice characteristics and features that are very desired in an IoT project, let’s see some of them:

It’s extremely fast, with an amazing 5-second transaction confirmation time it’s perfect for devices automation
In features instant finality of transactions: once a transaction is confirmed in a block, the confirmation is 100% final (i.e. no need to wait for more blocks to increase the confidence of the confirmation against possible blockchain forks), which is totally required if we are operating on real-world devices (if you are doing home-sharing, you don’t want to open your front door based on a transaction that you will later discover it was not included in the blockchain, right?)
It provides smart contracts: well, IoT is all about automation of devices, and orchestration of “things” in real world scenarios that will possibly also involve deposits and payments, all based on some more or less complex logic, so this is a pretty obvious requirement! Good that we ca use Solidity, too.
It’s extremely secure: IoTeX has proven itself to be one of the most secure networks in the blockchain space. Ever since the bootstrap of the first MainNet Alpha release in April 2018 the network has never experienced any downtime, or any relevant issue. To date, the network is running smoothly on MainNet v1.1.1, it’s backed by over 60 worldwide block producers, and is actively developed with many innovations tailor fit for the IoT (both software and hardware!).
Benefits of Smart Contracts
Why would we use a smart contract for our smart-lock? Well, we want to remotely operate our SmartLock, so one option we have is to open our network to external incoming connections and talk directly to our SmartLock: this option poses huge security concerns that are not easy to tackle without professional knowledge and a solid security policy (read “money”), especially if we are going to scale. A more reasonable alternative is to use an intermediate server in the cloud to hold the status of the lock that we will actually modify, while it is monitored by the SmartLock to execute the request. This option sounds much better as the security is managed by the cloud service provider, but it poses another types of concerns: their security is probably much stronger than what we can do, but they are also the target of 99% of all serious hackings, so the risk is still high. Additionally, our business (the service availability and the data) are in the hands of a third party, in the best scenario it could have downtime’s, in the worst one it could sell our data, or close our account for whatever reason. And it has a cost of course.

What about the blockchain? You may think that for such a simple application there could be not much benefits in using a smart contract, yet even though the code that we will use is as simple as one line of code: State = not State; to toggle the Lock, solely because it’s executed ina blockchain contract it changes everythin. Le’s what it provides us:

CloudService: We can use the blockchain as a cloud server to remotely access our home device: so no need to open our home network to the outside world.

Security: Only the owner of the blockchain account (i.e. the wallet) that deployed the smart contract is the one allowed to execute it and to operate the smart lock, which means that our system is as secure as a blockchain account, and no successful attempts of cracking a blockchain wallet have been reported to date — that’s pretty important if you are driving the lock of your front door, isn’t it?!

Uptime: Relying on a blockchain we achieve a theoretical 100% uptime: even comparing to the best professional cloud service, a well designed blockchain counts on a worldwide decentralized network of numerous independent servers, and can be considered immune to hardware failures and almost immune to attacks.

Censorship-free/tamper-proof: Because our blockchain is permission-less and decentralized, there is no service provider (or hacker!) here that can decide to close your account, stop your service, or somehow tamper with your code altering the behavior.”

Link to article