1
votes

As a project I am attempting to make an application which allows a food supply chain to be stored using the ethereum blockchain. In doing this I will be storing an asset from farm to consumer. The end consumer will ultimately be able to retrieve the information about their specific product from the blockchain, for example which farm it came from. I cannot get my head around whether a seperate smart contract is required for each asset, or whether one smart contract can be used to store information about several different assets.

Any help is much appreciated, thanks.

3

3 Answers

1
votes

Either way is fine . I would personally go with the multiple smartcontract way .If you are using a single smartcontract , you can have a datastructure to map the ID of the item to its current position in the supply chain . You can have a simple mapping from an integer to a struct for this . This approach gets complicated if you want to track all previous locations of a particular item .

The best approach would be maintain separate smart contract for each item.In each contract you can have a mapping from timestamp/string to a struct to store details of the item .

0
votes

This really depends on how you code your smart contract. If you want one contract to be able to handle multiple items, you can assign some sort of ID, maybe a plain integer, to each item and then you can create a data structure that, for each ID, has info about the supply chain attached.

You can then add functionality to add more tracked IDs, so you expand the number of items later on

0
votes

Just think of public Solidity functions you're going to write and ask yourself: am I going to have different functions for different types of assets? If your answer is "yes" - you'll probably need separate smart contracts. Otherwise, stick with a single one and make sure it handles different asset types internally.

Keep in mind though, that once a smart contract is deployed and mined, it's impossible to change. You can only deploy a new one, and then migrate your clients to the new Eth address.