Supply Chain on Blockchain
Track and trace, provenance, logistics, and supply chain transparency.
Overview
Blockchain provides transparent, immutable supply chain records.
Supply Chain Contract
contract SupplyChain {
struct Product {
string name;
address manufacturer;
address currentOwner;
uint256 timestamp;
string location;
}
mapping(uint256 => Product) public products;
mapping(uint256 => Product[]) public history;
function createProduct(uint256 id, string calldata name) public {
products[id] = Product(
name,
msg.sender,
msg.sender,
block.timestamp,
""
);
}
function transfer(uint256 id, address to, string calldata location) public {
require(products[id].currentOwner == msg.sender);
history[id].push(products[id]);
products[id].currentOwner = to;
products[id].timestamp = block.timestamp;
products[id].location = location;
}
}
Provenance Tracking
class ProvenanceTracker:
def __init__(self):
self.product_id = None
self.origin = None
self.journey = []
def add_checkpoint(self, location, handler, timestamp):
self.journey.append({
"location": location,
"handler": handler,
"timestamp": timestamp,
"verified": True
})
def get_full_journey(self):
return self.journey
Use Cases
| Industry | Application |
|---|---|
| Food | Farm to table tracking |
| Pharma | Drug authenticity |
| Luxury | Anti-counterfeiting |
| Logistics | Shipment tracking |
Benefits
- Transparency — All participants see data
- Immutability — Cannot alter records
- Efficiency — Automated verification
- Trust — Verified provenance
Practice
Build a supply chain tracking system for food products.