Storing DePIN Data on Irys
DePIN networks need a reliable data layer they can trust.
Imagine a network of nodes signing and reporting data onchain and a smart contract that reads this data to mint rewards. This setup only works if the DePIN protocol can easily verify that miners are storing the data they claim to store and that the data hasn’t been tampered with after being uploaded. Additionally, DePIN networks need to chronologically order data so they can process it in the order it was posted.
Irys makes this possible with permanent onchain data storage and upload receipts with millisecond-accurate timestamps. Protocols can verify data is stored by miners, ensure it remains unaltered, and sequence it.
Data on Irys can be accessed by protocols on any blockchain.
Example
This guide includes example code showing how to store DePIN messages on Irys, how to tag and query those messages, and how to order them chronologically.
Data messages for DePIN networks vary, but the core principles of secure storage, retrieval, and verification remain consistent across different use cases.
Device Data
Example data for a weather sensor.
{
"device_id": "foo_device_001",
"timestamp": "2024-08-29T12:34:56Z",
"data": {
"temperature": 22.5,
"humidity": 60,
"battery_level": 85,
"location": {
"latitude": 37.7749,
"longitude": -122.4194
}
},
"signature": "a4f8a2e8e7c4d2a7c3e1f9b6d8e2f1a0c5b7e6a3c4d1f7b8e2a6c1d3e7f8b9c2"
}
You can upload your DePIN data to Irys using the Irys CLI:
irys upload depin_data.json \
-n testnet \
-t ethereum \
-w 6dd5e....54a120201cb6a \
--tags Content-Type application/json \
Or through the Irys SDK:
Use a token-specific version of getIrysUploader()
to connect to an Irys Bundler before uploading. Choose one from here.
const uploadDePINData = async () => {
const irys = await getIrysUploader();
const fileToUpload = "./depin_data.json";
const tags = [{ name: "Content-Type", value: "application/json" }];
try {
const response = await irys.uploadFile(fileToUpload, { tags: tags });
console.log(`File uploaded ==> https://gateway.irys.xyz/${response.id}`);
} catch (e) {
console.log("Error uploading file ", e);
}
};
Using Tags
Irys supports adding metadata tags to each upload, allowing you to categorize data and make it easily searchable. For DePIN networks, tags like device-id
, data-type
, location
, and application-id
can be attached to each upload. This makes it simple to filter data by criteria important to your network.
Example Tags
Here’s how you might tag a data upload:
device-id
: "foo_device_001"data-type
: "temperature"location
: "San Francisco, CA"application-id
: "DePIN Network Alpha"
const uploadDePINData = async () => {
const irys = await getIrysUploader();
const fileToUpload = "./depin_data.json";
const tags = [{ name: "Content-Type", value: "application/json" },
{ name: "device-id", value: "foo_device_001" },
{ name: "data-type", value: "temperature" },
{ name: "location", value: "San Francisco, CA" },
{ name: "application-id", value: "DePIN Network Alpha" }];
try {
const response = await irys.uploadFile(fileToUpload, { tags: tags });
console.log(`File uploaded ==> https://gateway.irys.xyz/${response.id}`);
} catch (e) {
console.log("Error uploading file ", e);
}
};
Querying
To query data stored on Irys, you can use GraphQL to search for specific tags and order the results by timestamp:
query getDeviceTemperatureData {
transactions(tags: [
{ name: "device-id", values: ["foo_device_001"] },
{ name: "data-type", values: ["temperature"] },
{ name: "location", values: ["San Francisco, CA"] },
{ name: "application-id", values: ["DePIN Network Alpha"] }
], order: ASC) {
edges {
node {
id
tags {
name
value
}
timestamp
}
}
}
}
This query retrieves all temperature
data from foo_device_001
located in San Francisco
, and orders the results by the upload timestamp.
By using tags and timestamps, you can ensure your DePIN network maintains accurate data sequencing and retrieval across any blockchain.