# A Blockchain and IoT-Enabled Framework for Ethical and Secure Coffee Supply Chains
## 3 Methodology
### Roles and Interaction  
As illustrated in Figures 4 and 5, our proposed system models the coffee supply chain through a role-based smart contract structure in which every participant is responsible for specific stages of the product life cycle. These roles include coffee farmers, cooperatives, transporters, warehouses, retailers, and end consumers. Our system also incorporates IoT devices, mobile interfaces, and blockchain-backed ledger functionality to ensure data integrity and traceability across all interactions. Each participant is uniquely identified through their Ethereum address and registered using the _registerUsers()_ function within the smart contract. Their interactions are structured to reflect real-world workflows and are validated on-chain to ensure accuracy, ownership consistency, and accountability. The process begins at the coffee farm, where beans are harvested and physically tagged with RFID identifiers. While no hardware was used in the simulation, this phase was modeled in the dataset by assigning each batch a unique ID. The farmer, acting as the batch owner, registers both the user and the beans via the _registerUsers()_ and _registerBeans()_ functions. These records establish the origin of the beans and create a persistent reference for traceability. After being tagged, the beans are transported to the next stage of the supply chain. Simulated IoT devices are modeled to send weight data, such as when a cooperative or weighing center receives a batch. The _sale0_ function is used to record this handoff, log the new batch weight, and update ownership. In future deployments, IoT-enabled scales could trigger this update automatically through middleware such as mobile applications or APIs [52]. Figure 3: Blockchain ledger structure illustrating the on-chain storage of user identities, coffee batch metadata, and sales transactions. These components are managed through smart contract mappings and arrays to ensure traceability, ownership transparency, and immutable record-keeping. Environmental data collection is also part of the system's design, as shown in the diagram above. During transportation and storage, simulated temperature and humidity  
Figure 4: This diagram shows how farmers interact with the blockchain via a mobile app linked to a backend server. The server verifies identity, signs transactions with the farmer’s blockchain ID, and triggers a smart contract to record data on the decentralized ledger. A confirmation is then returned to the app, ensuring secure, authenticated, and verifiable transactions. Figure 5: RFID data initiate bean registration through a mobile app at the farm level. As the batch progresses, simulated IoT devices capture weight and environmental data submitted on-chain through smart contracts. Ownership, location, and retail validations are logged, enabling consumers to query batch provenance, with all steps aligned to supply chain roles and automated through blockchain. readings are recorded in the dataset and associated with the batch. Although the smart contract does not currently include environmental parameters, these values could be submitted through extensions to the _sale0_ function or through additional condition-checking modules in future iterations. This step is critical for quality assurance, as it enables traceability not just of ownership but also of product handling conditions. Mobile validation is included near the retail endpoint. Retailers use simulated mobile devices to finalize the transaction, acting as the final receivers before product delivery. This is again represented by a _sale0_ transaction, capturing the transfer from the transporter or warehouse to the retail outlet. The final update to the ledger marks the retail acceptance of the product and completes the traceability cycle. Finally, consumers do not contribute data to the blockchain, but benefit from its transparency.