Architect a Blockchain Supply Chain Solution Part B Project FAQ — Udacity Blockchain


  • You can use the starter code and complete the things that need to be done. It is not necessary that you start a project from scratch.
  • Supplychain should inherit from the Roles and Ownable
SupplyChain is Ownable, FarmerRole, ConsumerRole, RetailerRole, DistributorRole

I want to submit Udaicty Coffee Supply Chain template , and do not use my template , Can i ?

Yes, you can submit Udacity Coffee Supply Chain, even if you submitted different UMLs in part A.

BUT, you need to create UMLs for the Udacity Coffee Supply Chain, because the UMLs are examples that are not completely in sync with the code. We did that intentionally so that students need to adapt the UMLs and practice UML.

Do I need to implement the coffee supplychain provided in the boilerplate or can I create my own supplychain?

You can modify the boilerplate to implement a system for another supplychain. I do want to give these recommendations:

  • What I recommend is that you use a supplychain that is similar to the coffee one. For example: Gold, Wood, Cotton, Diamonds, Paper. Those are good examples of traditional supplychains that use software for product traceability

In this project we should download the boiletplate and implement all the functions in the contracts? is there other thing that we need to do to complete this project ?

If you are also doing a Coffee SupplyChain solution, I see reviewers looking for the correct inheritance pattern. It is expected that you inherit the access control contracts and the Ownable contract in the base contract (i.e. SupplyChain is Ownable, FarmerRole, DistributorRole, etc…) . Your truffle tests and dApp should work with that pattern. I think that is the only point that is not clearly stated in the project description but is expected in the reviews.

Answer from mentor Chris F

If you are working in the Coffee supplychain you need to do this:

  • Make sure that you added all the roles and implemented the roles that were not complete, based on the code of a role that is implemented in the boilerplate
  • Use the roles in the supplychain contract
  • Complete the functions in the supplychain contract that are not finished
  • Add the functions that are missing according to your UMLs
  • Tests all of the functions in the supplychain contract
  • Make sure that the Dapp works

If I use my own idea instead of coffee bean, must I use the same file structure for files and contract names for roles or can they change ?

  • You can change the names for the roles and assign the names related to your supplychain
  • You can add your own file structure, but I recommend that you follow the structure proposed: the roles are created in separate files, a file for the supplychain and a file for each type of access management handler (like Ownable).
  • The important thing is that the mentor can easily run your project, can easily understand it and that the mentor can easily review each point in the rubric. Your project could be awesome, but if the reviewer can’t understand it and does not know how to run it, that is a problem
  1. I’m trying to run the tests of the started code but the first test does not pass. I get the following error: 1) Contract: SupplyChain Testing smart contract function harvestItem() that allows a farmer to harvest coffee: AssertionError: Error: Invalid item UPC: expected { Object (s, e, …) } to equal 1 at (test/TestSupplychain.js:66:16) at process._tickCallback (internal/process/next_tick.js:68:7)

It seems like your question is similar to this answered one in Knowledge

The short answer is that some functions within the contract are yet to be implemented, including the FetchOneBuffer. That test is falling because you need to implement the FetchOneBuffer function and other functions

Credits to Alan Arevalo, an awesome BDND student!

2. During lessons it was suggested to have a structure of contracts using inheritance like:

contract AccessControl
contract Base is AccessControl
contract Core is Base

But from the project template code we are not using inheritance, why? What did I miss?

  • It is a suggested way to use inheritance, you can change some part of it. For example, The SupplyChain contract could be the top contract and you inherit the Core like: Base is Core
  • You need to implement the inheritance.
  • One typical inheritance pattern that students follow in this project is:
SupplyChain is Ownable, ConsumerRole, RetailerRole, DistributorRole
  • But it all depends on the supply chain that you are modeling, in the Access Control contracts that you want to implement (ConsumerRole, RetailerRole, ,…), in the Ownership and management (Core) contracts that you want to implement (Ownable, Pausable, Secondary, ,…)

3. I needed clarification around methods 1. fetchItemBufferOne and fetchItemBufferTwo. What is the difference expected out of these two functions. Which actors in coffe block-chain will have access to these functions.

  • The purpose of these functions is to return the information of the item or product in the supplychain. You can’t return more than 9 output arguments in a function and that is the reason why there are 2 functions and not just 1
  • fetchItemBufferOne and fetchItemBufferTwo should be public to everyone, no role restrictions

4. What is the purpose of the Ownable.sol file? I don’t see why is it necessary for transferring the ownership of an item (coffee) from one address to an other one.

The purpose of Ownable.sol is to manage the ownership of the contract and for access control.

Ownable.sol is not for transferring the ownership of an item (coffee) from one address to an other one. But to transfer the ownership of the contract. In some contracts the owner has some special administrative functions that only can be executed by the owner and that is the reason that the modifier onlyOwnerexists.

Understanding how to implement well access control is very important in the real world and this link is very useful

These are some interesting topics that you should explore to continue learning more about access control:

  • Secondary: create a “secondary” contract that allows a “primary” contract to manage it.
  • renounceOwnership: to remove the owner altogether, useful for decentralizing control of your contract
  • role based access control
  • single-concern Ownable

5. Can someone explain how to use the roles from within the SupplyChain contract?

Hi Alex! The access control contracts restrict certain roles from accessing your base contract functions. For example, you don’t want consumer accounts marking items as shipped. Only distributors can. You can do that with the `onlyDistributor` modifier in `DistributorRole.sol` by appending it in `shipItem()`. You can make use of it in the base contract by inheriting it (e.g. SupplyChain is DistributorRole).

Credits to Chris F, an awesome BDND Mentor!

6. I’m in the last stage of the project. I’m having troubles to understand the interaction with the frontend. If I understand correctly, the js/app.js boilerplate file contains the interface between the frontend index.html file and the smart contract functionality. Unfortunately, I don't really understand what is happening in this file. I don't see any imports and if I click the buttons on the webapp nothing happens or gets logged in the console. I'm suppose to modify this file at all?

  • First, make sure that you’re serving the files via a web server. lite-server is already included in the boilerplate and you just need to run it via npm run devthen point your browser to localhost:3000
  • You’ll need to modify the front end if you chose a different supply chain solution (i.e. not coffee bean) and your activities don’t match the boilerplate (i.e. no harvestItem(), packItem(), etc..).
  • To put it simply, you could say that the html sets up buttons and assigns processIDs to it. The app.js then monitors button clicks and executes the corresponding methods based on the process ID assigned. You can see this in the switch statement in app.js.
  • You could say that the front end is initialized in the initSupplyChain method when it grabs the ABI and sets up the interaction with the deployed contract. Thus, make sure that you already migrated the contract and you have the correct network chosen in Metamask.
  • Please also check the port in this line in initWeb3: App.web3Provider = new Web3.providers.HttpProvider('http://localhost:8545');Change to 7545 if you're using ganache-gui

Credits to Chris F, an awesome BDND Mentor!

8. Hello. I am writing about one aspect of Supplychain.sol which is mapping (uint => string[]) itemsHistory; //maps the UPC/item to an array of TxHash & tracks its journey through the supply chain — to be sent from DApp. There is no clear indication of the purpose of this on how is to be used

You can disregard itemsHistory. I’ve already reported it to the project team and still waiting for official advice. However, looking at the materials provided to us in evaluating submissions, there is also no mention nor use of this mapping. Previous work also dont check for this. Thus, I think it can be ignored until we get clarification on its use.

Credits to Chris F, an awesome BDND Mentor!

The itemsHistory mapping is not required.

The purpose of this mapping is to store an array of the ids of the transactions of each item to have a trace of the evolution of the item in the supplychain.

Yes, If we populate it from the DApp, that would cost gas, and it would open a new MetaMask popup only for that purpose. That is the expected way for it to work because as the transaction is not mined you can’t find here the tx.hash.

Correct you don’t have the TxHash get the transaction is created.

You need to add the TxHash after the transaction is added.

Implement the process to add the TxHash after the transaction is added, in the Front End, listening to the event that signals the creation of the transaction or waiting until the transaction completes.

Credits to Alvaro Andres Pinzon Cortes, an awesome BDND Mentor!

9. I’m still a bit confused about the Roles. What is the intent of verifyCaller() in the boilerplate code? In my implementation I use i.e. the onlyFarmer() modifier for the harvest method, and similar Role modifiers for the others. Is there a method of SupplyChain where I need to call verifyCaller(), or can I remove it?

Hi @AnonA ! verifyCaller is used to make sure that the expected caller is the one calling the function. For example, if Bob is the originalFarmer of the coffee, then his address should only be the one to execute SellItem() for that particular item. If you just check using onlyFarmer() then another farmer (e.g. Bruce) can also execute this function for Bob’s item and depending on the implementation, he might be the one getting the payment instead of Bob.

So in this case, msg.sender should be equal to the originFarmerID (Bob’s address) and you can do that through verifyCaller(). Hope this helps!

Credits to Chris F, an awesome BDND Mentor!

10. Why we need to check role before adding? Why the function addConsumer need the onlyConsumermodifer? the modifier check the sender is Consumer Role, right? We add he to Consumer because he is not a Consumer....right? But why we should check the sender is not a Consumer Role before adding it as Consumer? Or we should check the sender don't have any role before adding it?

That is an arbitrary rule set by the boilerplate. I guess it doesnt make much sense for consumers. But I would say it’s okay for farmers.

It like a group of farmers saying that only fellow farmers can add a member into their league.

A consumer account should not be able to add farmer accounts into the farmers list.

As you may have noticed, this can be implemented another way and new rules can be set. For this project, I recommend that you follow the convention placed by the boilerplate. After passing the requirement, you can modify the rules for access control when you customize the project for your portfolio.

Credits to Chris F, an awesome BDND Mentor!

11. What are SKU and UPC? How are their use in the industry?

  • SKU: First off, an SKU (stock keeping unit) is strictly for internal use. Since an SKU is unique to a company, a product would have different SKUs if sold by different companies. Each product type has an SKU, in other words all 32GB Gold iPhones share the same SKU in a retailer.
  • UPC: A UPC (universal product code) is affixed to a product wherever it is sold in the retail market place. A product will have the same UPC, no matter its current owner. Each product type has an UPC, in other words all 32GB Gold iPhones share the same UPC across the supplychain.

Please try to read this articles to study in more depth this topic:

12. How is the smart contract invoked when there are multiple distinct party involved ? Lets say and example of coffee harvest . The stake holders are distributors , farmer , and a consumer . Now how will the contracts interact and how will contract identify someone as a farmer or consumer or a distributor ?

In this project, the person that creates the contract, has all the roles. Is done with the purpose to make it easier to test the application and also with the purpose to allow the creator of the contract to act as the administrator of the app and to give him the power to authorize someone to have a certain role.

It is also assumed that an individual with a certain role can authorize another individual to have that role, so we give that power to the current stakeholders in the system.

14. The supply chain code (boiler plate) has a “itemsHistory” mapping. If we populate it from the DApp, that would cost gas, and it would open a new MetaMask popup only for that purpose. How do you expect us to do it? Or we should better ignore that mapping?

  • The itemsHistory mapping is not required
  • The purpose of this mapping is to store an array of the ids of the transactions of each item to have a trace of the evolution of the item in the supplychain
  • Yes, If we populate it from the DApp, that would cost gas, and it would open a new MetaMask popup only for that purpose. That is the expected way for it to work because as the transaction is not mined you can’t find here the tx.hash

Answer from mentor Alvaro Andres Pinzon

I also encourage you to implement showing the tx hash in the screen after executing the activity functions. Similar to the screenshot below. Some reviewers will be looking for it:

Answer from mentor Chris F

18. How to use IPFS in the project?

I want to recommend this great tutorial from IPFS How to Easily Host a Website on IPFS. It is a step by step guide to easily host Angular, ReactJS, or VueJS apps on IPFS using Cloudflare and Pinata. You can host the Dapp in IPFS

Alternatively, to host the Dapp I want to recommend Fleek. Fleek makes it easy to build websites and apps on the new open web: permissionless, trustless, censorship resistant, and free of centralized gatekeepers.

Answer from mentor Alvaro Pinzon

— — —

Previously, you can use the node package ipfs-api to interact with an IPFS daemon. It has been deprecated recently and renamed to ipfs-http-client. Unfortunately, I haven’t tried with that update yet. In the previous version, you’ll need to use the ipfs.add() method to upload an image via IPFS.

Answer from mentor Chris F

It depends on why do you need IPFS

I propose that you can store the image of the product in IPFS. Or what file do you want to store?

Answer from mentor Alvaro Pinzon

21. i have one conflict i have an owner variable declared in supplychain.sol, but it is also in Ownable.sol

Because you are using the Ownable contract you should delete the owner variables and the onlyOwner from the SupplyChain contract, to use what is provided by Ownable and avoid redundancies

22. I’m afraid to doing more complicate then should be. I’m doing about Beer and I separate the Raw Materials and the beer process. So I’m doing 2 Supply chains. I’m starting to think that this is wrong.

I suggest that you should not try to work in 2 separate supplychains, just work in 1.

Try not to overcomplicate the supplychain or maybe we will not have enough time to finish the project.

Try to do this, just model the part of the supplychain of the beer:

  1. The beer is packed in the bottle
  2. The packed beer is inspected
  3. It is stored in the warehouse
  4. It is shipped to the retailer A
  5. It is bought by the consumer B

In a real world supplychain app, companies divide the product tracking process in many different stages. There is an specific tracking of the barley, until it gets processed to beer. Then they start a new supplychain tracking since the beer is bottled and they can do a tracking of that beer or the six pack. They treat barley and beer as 2 different supplychains




Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Logstash hourly rotate file output

Using Chart JS in react

Intro to JavaScript

6 Cool APIs for Your Next JavaScript Project

Perseverance is Powerful

Testing with FakeAsync in Angular

Free React course for beginners to support Ukraine

Realtime chat app with laravel 5.4 and vuejs 2

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Alvaro Andres Pinzon Cortes

Alvaro Andres Pinzon Cortes

More from Medium

Sliding Window Challenge Process for Congestion Detection

Blockchains in IoT based on Smart Healthcare Systems

Defining the web3 stack

Switchboard Deep Dive