Here I want to introduce the Proof of Concept for the “Empowering Machines with Wallets”, the 2nd IOTA Development Contest on “Hackster.io”. The main idea is to buy services paying with IOTA tokens. I took a smart-plug as example. This device can be turned on and turned off using some APIs through WiFi using a library written fore nodeJS. Basically I developed a server running on a Raspberry Pi that can be contacted using REST API that will provide the service (turn on the smart-plug) after receiving a POST request with attached an IOTA transaction hash. Once the server verify that the transaction exists and it is verified, the lamp is turned on for a specific amount of seconds depending on the predefined cost of electricity (for this sample I provide 1 second of the lamp for 1 IOTA). To simplify the interaction with the server, I developed a Telegram Bot that will take care of all the requests from a user. User will ask to the bot for the service, he will pay some IOTA token using the trinity mobile application (or whatever other IOTA wallet supporting IOTA) and then will use the bot to forward the transaction hash in order to demonstrate his payment. In this way the service can be simply accessed using any device (iOS, Android and Windows Phone mobile devices and PC of any OS) without installing/developing any other new application, just Telegram, a widespread messaging application (https://telegram.org/) and IOTA trinity wallet, application available for various platforms and OS (https://trinity.iota.org/).
General description of the PoC.
Basically, the idea of this PoC is to provide a service and pay for it using IOTA tokens. User wants to use a service and after understanding how much it costs (in IOTA) he pay for it to a specific IOTA wallet (created from the device he is asking for the service). The device offering a service has some logic on server side in order to provide the service to the user after he verify that the user pay and the transaction has been verified. This is only a PoC and has some limitations but this is just to provide a general idea of my project. Of course this can be improved.
Detailed description of the entire process.
Here it is described the complete process with technical details of all the components and action performed:
- A user, who wants to turn on the lamp attached to the smart-plug, contacts the Telegram bot. He starts the bot and then sends a message with the command with his request (e.g. “turn on the the lamp for 10 seconds”).
- The Telegram Bot perform a GET HTTP request to the server in order to get the IOTA address to be sent to the user. The user will use this address to perform the payment.
- The server use the IOTA Typescript library to generate a new address from the SEED of the smart-plug wallet and reply to the IOTA Bot.
- The Telegram Bot, once received the address from the server, replies to the user with the IOTA amount needed to provide the requested service. Supposing 1 seconds of electricity costs 1 IOTA, the bot will reply to the user the total amount of IOTA to be paid and the address X to which to send the payment (e.g. “send me 10 IOTA for 10 seconds to the address X”).
- The user will send the requested IOTA to the address X using the wallet he wants. Supposing he is using his mobile phone he use the trinity wallet application to send IOTA to the address. Both Telegram and trinity wallets applications are available for many devices and OS, so the user can contact the Bot from any device he wants. (e. g. “the user pay 10 IOTA to the address X”).
- The user sends another command to the bot in order to provide his transactions hash, as a receipt, of the just done transaction.
- The telegram Bot forward the transaction hash to the server.
- The server use the IOTA typescript library to check if the transaction is valid and verified.
- The server contacts the Bot in order to sent back an answer to the user to let him know that the transaction is valid and it is waiting for the validation.
- The Bot reply to the user (e.g. “payment received, service will be provided once the transaction will be verified”).
- The server, when the transaction has been verified, sends the command to the smart-plug in order to turn on the lamp. The server stats also a timer in order to provide the service for the paid amount of time.
- Once the smart-plug receive the command it turns on the lamp that is attached to.
- Once the timer expires, the server sends a command to the smart-plug to turn off the lamp.
- The smart-plug turned off, so the lamp turn off.