A brief exploration of a potentially very large use case of Ethereum, including the full technical implementation. Posting as I work on it.
There are two technologies that I think are going to be defining of our time. One is deep learning and the other is blockchain. I have spent a couple of years deep diving into deep learning. Despite its magic (its the first technology that has “fallen” on humanity´s lap, without us fully understanding how it works), it is hard to create value with it without being part of a larger organization, because you need a lot of data. This year I am discovering blockchain technologies and I am marvelled by the possibilities it brings about — with it, we really are back to the disrupt something from your garage vibe. I discuss this in more detail here.
Project Description: Stack and Functionality
I am architecting a supply chain tracking system, that runs on the Ethereum network (in this case a test network). The system will track the evolution of coffee through the supply chain, as different actors along the chain (farmers, distributors, retailers and consumers) perform actions that alter the state of the coffee. The ways such as system could deliver value are endless, all stemming from giving the chain added transparency and accountability.
The project has 2 large components:
- Smart Contracts (backend): written on Solidity and to be deployed on the Ethereum network.
- Web Interface (front end): some HTML and JS to enable clients to interact with the backend.
Once the contracts are deployed, the frontend enables clients to interact with it.
The supply chain is essentially a DApp (decentralized app). It is decentralized because the Ethereum network runs on multiple decentralized nodes vs one centralized node. The stack is as follows:
I am using the Truffle framework, because it makes everything really easy. As with any kind of app, there is no need to reinvent the wheel. On the front end, the UX is some simple HTML. The JS is listening for events on the front end (mostly clicks). The JS also contains several abstractions that enable it to interact with the deployed smart contracts. It connects with the client´s MetaMask, injects Web3 and loads the contracts´ instances.
- MetaMask: gives clients access to their Ethereum funds
- Web3: enables transactions to be read/written onto the blockchain
- Infura: provides the actual connection to the blockchain
The above is confusing until you see it working. It´s magic.
Regarding the contracts, I am using 3 of them. accessControl defines what users with different roles in the supply chain can do. base defines the logic we need to operate the supply chain and core defines who contract ownership management. Each inherits from the other. base inherits from accessControl and core inherits from base. Ultimately, core is the contract that we deploy to the network. Truffle (Ganache) offers a dev environment we can push the contracts to, in order to test them.
We have 4 different actuators on the supply chain:
[farmers, distributors, retailers, consumers]
that are performing actions on one commodity:
The actions that each actuator can perform are:
- Farmers: [harvestItem(), processItem(), packItem(), sellItem()]
- Distributors: [buyItem(), shipItem(), receiveItem()]