Example: On-Demand Data Retrieval Implementation
Step-by-Step Implementation
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
contract DataRetrieval {
address owner;
mapping(address => bool) authorizedUsers;
event DataRequested(address indexed requester, string cid);
constructor() {
owner = msg.sender;
}
modifier onlyOwner() {
require(msg.sender == owner, "Not authorized");
_;
}
modifier onlyAuthorized() {
require(authorizedUsers[msg.sender], "Not authorized");
_;
}
function authorizeUser(address user) public onlyOwner {
authorizedUsers[user] = true;
}
function deauthorizeUser(address user) public onlyOwner {
authorizedUsers[user] = false;
}
function requestData(string memory cid) public onlyAuthorized returns (string memory) {
emit DataRequested(msg.sender, cid);
return cid; // The cid is the Content Identifier used by IPFS or other decentralized storage
}
}Benefits of On-Demand Data Retrieval
Challenges and Considerations
Last updated