Blockchain technology has numerous applications beyond cryptocurrency, offering a secure, transparent, and decentralized way to conduct various transactions and operations. Here are some common use cases for blockchain:

1. Supply Chain Management

Blockchain can be used to track and verify the origin, quality, and movement of goods throughout the supply chain.

Example: Tracking Coffee Beans


pragma solidity ^0.8.0;

contract CoffeeSupplyChain {
struct CoffeeBean {
uint id;
string origin;
string quality;
uint quantity;
address[] owners;
}

mapping(uint => CoffeeBean) public coffeeBeans;
uint public coffeeBeanCount;

function addCoffeeBean(string memory origin, string memory quality, uint quantity) public {
coffeeBeanCount++;
coffeeBeans[coffeeBeanCount] = CoffeeBean(coffeeBeanCount, origin, quality, quantity, [msg.sender]);
}

function transferOwnership(uint coffeeBeanId, address newOwner) public {
CoffeeBean storage coffeeBean = coffeeBeans[coffeeBeanId];
require(coffeeBean.owners[coffeeBean.owners.length - 1] == msg.sender, "Only the current owner can transfer ownership.");
coffeeBean.owners.push(newOwner);
}

function getCoffeeBean(uint coffeeBeanId) public view returns (string memory origin, string memory quality, uint quantity, address[] memory owners) {
CoffeeBean memory coffeeBean = coffeeBeans[coffeeBeanId];
return (coffeeBean.origin, coffeeBean.quality, coffeeBean.quantity, coffeeBean.owners);
}
}

2. Identity Verification

Blockchain-based identity verification systems enable individuals to control their personal data and securely share it with third parties.

Example: Self-Sovereign Identity


pragma solidity ^0.8.0;

contract SelfSovereignIdentity {
struct Identity {
uint id;
string name;
string email;
string phoneNumber;
address owner;
}

mapping(uint => Identity) public identities;
uint public identityCount;

function createIdentity(string memory name, string memory email, string memory phoneNumber) public {
identityCount++;
identities[identityCount] = Identity(identityCount, name, email, phoneNumber, msg.sender);
}

function updateIdentity(uint identityId, string memory name, string memory email, string memory phoneNumber) public {
Identity storage identity = identities[identityId];
require(identity.owner == msg.sender, "Only the owner can update their identity.");
identity.name = name;
identity.email = email;
identity.phoneNumber = phoneNumber;
}

function getIdentity(uint identityId) public view returns (string memory name, string memory email, string memory phoneNumber) {
Identity memory identity = identities[identityId];
return (identity.name, identity.email, identity.phoneNumber);
}
}

3. Healthcare

Blockchain can be used to securely store and manage electronic health records (EHRs), track prescription medication, and enable secure sharing of medical research data.

Example: Electronic Health Records


pragma solidity ^0.8.0;

contract ElectronicHealthRecords {
struct Patient {
uint id;
string name;
string dateOfBirth;
string medicalHistory;
address owner;
}

mapping(uint => Patient) public patients;
uint public patientCount;

function createPatient(string memory name, string memory dateOfBirth, string memory medicalHistory) public {
patientCount++;
patients[patientCount] = Patient(patientCount, name, dateOfBirth, medicalHistory, msg.sender);
}

function updatePatient(uint patientId, string memory medicalHistory) public {
Patient storage patient = patients[patientId];
require(patient.owner == msg.sender, "Only the patient can update their medical history.");
patient.medicalHistory = medicalHistory;
}

function getPatient(uint patientId) public view returns (string memory name, string memory dateOfBirth, string memory medicalHistory) {
Patient memory patient = patients[patientId];
return (patient.name, patient.dateOfBirth, patient.medicalHistory);
}
}

4. Financial Services

Blockchain technology can streamline financial transactions, reduce fraud, and enhance transparency in banking and finance.

Example: Decentralized Finance (DeFi)


pragma solidity ^0.8.0;

contract SimpleBank {
mapping(address => uint) public balances;

function deposit() public payable {
balances[msg.sender] += msg.value;
}

function withdraw(uint amount) public {
require(balances[msg.sender] >= amount, "Insufficient balance.");
balances[msg.sender] -= amount;
payable(msg.sender).transfer(amount);
}

function getBalance() public view returns (uint) {
return balances[msg.sender];
}
}

5. Voting Systems

Blockchain can provide a secure and transparent way to conduct elections, ensuring that votes are counted accurately and preventing fraud.

Example: Voting Contract


pragma solidity ^0.8.0;

contract Voting {
struct Candidate {
uint id;
string name;
uint voteCount;
}

mapping(uint => Candidate) public candidates;
mapping(address => bool) public voters;
uint public candidatesCount;

constructor() {
addCandidate("Alice");
addCandidate("Bob");
}

function addCandidate(string memory name) private {
candidatesCount++;
candidates[candidatesCount] = Candidate(candidatesCount, name, 0);
}

function vote(uint candidateId) public {
require(!voters[msg.sender], "You have already voted.");
require(candidateId > 0 && candidateId <= candidatesCount, "Invalid candidate ID.");

voters[msg.sender] = true;
candidates[candidateId].voteCount++;
}

function getCandidate(uint candidateId) public view returns (string memory name, uint voteCount) {
Candidate memory candidate = candidates[candidateId];
return (candidate.name, candidate.voteCount);
}
}

Conclusion

Blockchain technology has the potential to revolutionize various industries by providing secure, transparent, and efficient solutions. From supply chain management to financial services, the applications of blockchain are vast and continue to grow as the technology evolves.