A fully decentralized approach
This tutorial demonstrates a fully decentralized approach to managing the lifecycle of device identity and ownership in DePINs using ioID. This method aligns perfectly with the principles of a true Web3 project, enabling device owners to independently initiate and complete the registration process without relying on centralized cloud services.
The document offers a practical, hands-on guide featuring an ESP32 board, with instructions that can be easily adapted to a variety of other โmachines,โ including Linux-based boards, smartphones, and desktop computers.
1. Initial DePIN Project Setup
Ensure you have completed the steps in the prerequisites section to fund an IoTeX developer account.
2. Device NFT Contract
Ensure you deployed an ERC721 NFT contract to "tokenize" your devices
See how to deploy an NFT Token on IoTeX using Hardhat: Deploy an NFT Token
and note the deployed contract address.
For a quicker option, you can deploy a standard NFT contract using its bytecode with the following ioctl command:
Check the transaction link to find the address of the contract just deployed.
We will refer to this contract as the "Device NFT" from now on. Let's also export the contract address for convenience:
Register your project on IoTeX
Take note of your Project ID
and set it as an environment variable:
Bind the Device NFT to your Project ID
Integrate ioID SDK in your device
In this step, we will use the popular ESP32 board as our DePIN device and create a simple firmware that enables the device to be registered on-chain by the device owner. This demonstrates the integration of ioID-SDK with minimal setup, making it a practical and efficient way to securely connect your DePIN devices to your Dapp on the IoTeX blockchain.
Below is a flowchart illustrating the basic flow common to most use cases. The process ensures proper device registration at boot and, during normal operation, the device utilizes its DID key to sign messages securely.
Prerequisite
Before proceeding, ensure you have an ESP32 toolchain correctly configured on your system. This is essential for building the code and deploying it to your ESP32 board. A VS Code extension is also available.
Get the ioID-SDK example
Clone ioID-SDK and enter the ESP32 examples folder:
Clone the tutorial:
Build the demo
Testing the Firmware
In this demo, the firmware is designed to accept HTTPS connections from a client and respond to a request to sign an ioID registration message that the client will utilize to call the ioID registration contract (ref. ioID Registry Contract).
In other scenarios, the device might communicate via Bluetooth or simply request the ownerโs address to perform on-chain registration directly.
To test the device:
1. Find the Deviceโs IP Address:
Check the terminal output to find the IP address assigned to the device.
2. Open a Browser:
Use a Chrome-based browser and navigate to the following URL:
Replace YOUR_DEVICE_IP with the actual IP address of the device.
3. Handle Security Warning:
Accept the browserโs security warning. (The demo firmware does not provide a valid HTTPS certificate; however, in a production environment, you should use a valid certificate.)
4. Verify the Response:
The firmware should return some DID (Decentralized Identifier) information in response to the request:
The device is now ready to be registered. While any DePIN project can provide their own client to perform the actual registration, here are some tools that work with the current communication protocol implemented in this demo:
The IoTeX Hub Portal: https://hub.iotex.io/my-devices - Please notice that this is being developed at this moment.
An example command line tool community-developed using NodeJS: https://github.com/simonerom/ioid-registration-js
A closer look at the code
Last updated