Secure storage and sharing of medical records:
Copy from daeta_sdk import DaetaClient , EncryptionMethod
client = DaetaClient ( 'YOUR_API_KEY' )
client . set_encryption_method (EncryptionMethod.AES_256_GCM)
def store_medical_record ( patient_id , record_file ):
encrypted_file = client . encrypt_file (record_file)
file_id = client . upload_file (encrypted_file, 'medical-records' )
client . set_file_metadata (file_id, { 'patient_id' : patient_id})
return file_id
def retrieve_medical_record ( patient_id ):
files = client . list_files ( 'medical-records' , metadata = { 'patient_id' : patient_id})
if files :
return client . download_file (files[ 0 ][ 'id' ])
return None
# Usage
patient_record = store_medical_record ( 'P12345' , 'patient_data.pdf' )
retrieved_record = retrieve_medical_record ( 'P12345' )
Immutable record-keeping for supply chain events:
Copy from daeta_sdk import DaetaClient
import json
client = DaetaClient ( 'YOUR_API_KEY' )
def log_supply_chain_event ( event_data ):
event_json = json . dumps (event_data)
file_id = client . upload_file (event_json. encode (), 'supply-chain-logs' )
return file_id
def verify_supply_chain ( product_id ):
files = client . list_files ( 'supply-chain-logs' )
events = []
for file in files :
content = client . download_file (file[ 'id' ])
event = json . loads (content. decode ())
if event [ 'product_id' ] == product_id :
events . append (event)
return events
# Usage
event = {
'timestamp' : '2024-07-15T10:30:00Z' ,
'product_id' : 'PROD-123' ,
'event_type' : 'SHIPMENT' ,
'location' : 'Warehouse A' ,
'details' : 'Product shipped to distributor'
}
log_supply_chain_event (event)
product_history = verify_supply_chain ( 'PROD-123' )
Decentralized Finance (DeFi)
Using DÆTA for storing off-chain data in DeFi applications:
Copy pragma solidity ^0.8.0;
import "@daeta/contracts/DaetaStorage.sol" ;
contract DeFiDataStore {
DaetaStorage private daetaStorage;
constructor ( address daetaStorageAddress) {
daetaStorage = DaetaStorage (daetaStorageAddress);
}
function storeTransactionData ( bytes32 txHash , string memory data) public {
bytes32 fileId = daetaStorage. store (data , "defi-transactions" );
emit TransactionDataStored (txHash , fileId);
}
function retrieveTransactionData ( bytes32 fileId) public view returns ( string memory ) {
return daetaStorage. retrieve (fileId);
}
event TransactionDataStored ( bytes32 indexed txHash, bytes32 fileId);
}
Usage in a DeFi application:
Copy const DeFiDataStore = artifacts .require ( "DeFiDataStore" );
const daetaStorage = await DaetaStorage .deployed ();
const defiDataStore = await DeFiDataStore .new ( daetaStorage .address);
// Store transaction data
const txHash = web3 . utils .sha3 ( "0x123..." );
const transactionData = JSON .stringify ({
amount : "100 DAI" ,
sender : "0xabc..." ,
recipient : "0xdef..." ,
timestamp : Date .now ()
});
await defiDataStore .storeTransactionData (txHash , transactionData);
// Retrieve transaction data
const storedData = await defiDataStore .retrieveTransactionData (fileId);
console .log ( "Retrieved data:" , JSON .parse (storedData));
These integrations and use cases demonstrate the versatility and potential of DÆTA in various industries and technological ecosystems. By leveraging DÆTA's decentralized storage capabilities, developers and businesses can create more secure, efficient and innovative solutions across different sectors.